queue

package
v1.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMaxTimeNoRead = errors.New("no messages available in the queue for more than the max time")

ErrMaxTimeNoRead is returned by a queue reader when there were no messages available in the queue for more than the configured amount of time.

Functions

This section is empty.

Types

type Message

type Message struct {
	// Body contains the body of the message to be processed.
	Body string
	// TimesRead contains the number of times this concrete message has been
	// read so far.
	TimesRead int
}

Message defines the information a queue reader passes to a processor about a message.

type MessageProcessor

type MessageProcessor interface {
	FreeTokens() chan any
	ProcessMessage(msg Message, token any) <-chan bool
}

MessageProcessor defines the methods needed by a queue reader implementation to process the messages it reads.

FreeTokens returns a channel that can be used to get a token to call ProcessMessage.

ProcessMessage processes the message given a token that must be obtained from FreeTokens. ProcessMessage is in charge of returning the token once the message has been processed. When the message has been processed the returned channel will indicate if the message must be deleted from the queue or not.

func Discard added in v1.1.3

func Discard() MessageProcessor

Discard returns a MessageProcessor that discards all the received messages.

type Reader

type Reader interface {
	StartReading(ctx context.Context) <-chan error
	LastMessageReceived() *time.Time
}

Reader defines the methods that all the queue reader implementations must fulfill.

StartReading starts reading messages from the queue. The caller can use the returned channel to track when the reader stops reading from the queue and all the messages have been processed.

LastMessageReceived returns the time when the last message was read. If no messages have been read it returns nil.

type Writer

type Writer interface {
	Write(body string) error
}

Writer defines the functions that a queue writer must implement.

Directories

Path Synopsis
Package chanqueue provides a local queue based on channels.
Package chanqueue provides a local queue based on channels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL