Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyClosed is the error returned when trying to close an already closed // connection. ErrAlreadyClosed = errors.NewKind("already closed") // ErrEmptyJob is the error returned when an empty job is published. ErrEmptyJob = errors.NewKind("invalid empty job") // ErrTxNotSupported is the error returned when the transaction receives a // callback does not know how to handle. ErrTxNotSupported = errors.NewKind("transactions not supported") )
var ( // ErrUnsupportedProtocol is the error returned when a Broker does not know // how to connect to a given URI. ErrUnsupportedProtocol = errors.NewKind("unsupported protocol: %s") // ErrMalformedURI is the error returned when a Broker does not know // how to parse a given URI. ErrMalformedURI = errors.NewKind("malformed connection URI: %s") )
var ErrCantAck = errors.NewKind("can't acknowledge this message, it does not come from a queue")
ErrCantAck is the error returned when the Job does not come from a queue
Functions ¶
func Register ¶
func Register(name string, b BrokerBuilder)
Register registers a new BrokerBuilder to be used by NewBroker, this function should be used in an init function in the implementation packages such as `amqp` and `memory`.
Types ¶
type Acknowledger ¶
type Acknowledger interface { // Ack is called when the Job has finished. Ack() error // Reject is called if the job has errored. The parameter indicates // whether the job should be put back in the queue or not. Reject(requeue bool) error }
Acknowledger represents the object in charge of acknowledgement management for a job. When a job is acknowledged using any of the functions in this interface, it will be considered delivered by the queue.
type Broker ¶
type Broker interface { // Queue returns a Queue from the Broker with the given name. Queue(string) (Queue, error) // Close closes the connection of the Broker. Close() error }
Broker represents a message broker.
type BrokerBuilder ¶
BrokerBuilder instantiates a new Broker based on the given uri.
type Job ¶
type Job struct { // ID of the job. ID string // Priority is the priority level. Priority Priority // Timestamp is the time of creation. Timestamp time.Time // Retries is the number of times this job can be processed before being rejected. Retries int32 // ErrorType is the kind of error that made the job fail. ErrorType string // ContentType of the job ContentType string // Raw content of the Job Raw []byte // Acknowledger is the acknowledgement management system for the job. Acknowledger Acknowledger }
Job contains the information for a job to be published to a queue.
func (*Job) Reject ¶
Reject is called when the job errors. The parameter is true if and only if the job should be put back in the queue.
func (*Job) SetPriority ¶
SetPriority sets job priority
type JobIter ¶
type JobIter interface { // Next returns the next Job in the iterator. It should block until // a new job becomes available or while too many undelivered jobs have // been already returned (see the argument to Queue.Consume). Returns // ErrAlreadyClosed if the iterator is closed. Next() (*Job, error) io.Closer }
JobIter represents an iterator over a set of Jobs.
type Queue ¶
type Queue interface { // Publish publishes the given Job to the queue. Publish(*Job) error // PublishDelayed publishes the given Job to the queue with a given delay. PublishDelayed(*Job, time.Duration) error // Transaction executes the passed TxCallback inside a transaction. Transaction(TxCallback) error // Consume returns a JobIter for the queue. It receives the maximum // number of unacknowledged jobs the iterator will allow at any given // time (see the Acknowledger interface). Consume(advertisedWindow int) (JobIter, error) // RepublishBuried republishes to the main queue those jobs complying // one of the conditions, leaving the rest of them in the buried queue. RepublishBuried(conditions ...RepublishConditionFunc) error }
Queue represents a message queue.
type RepublishConditionFunc ¶
RepublishConditionFunc is a function used to filter jobs to republish.
type RepublishConditions ¶
type RepublishConditions []RepublishConditionFunc
RepublishConditions alias of a list RepublishConditionFunc
func (RepublishConditions) Comply ¶
func (c RepublishConditions) Comply(job *Job) bool
Comply checks if the Job matches any of the defined conditions.
type TxCallback ¶
TxCallback is a function to be called in a transaction.