{"modulePath":"github.com/src-d/go-queue","version":"v1.0.6","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package queue\n\n## Variables\n\n```go\nvar (\n\t// ErrAlreadyClosed is the error returned when trying to close an already closed\n\t// connection.\n\tErrAlreadyClosed = errors.NewKind(\"already closed\")\n\t// ErrEmptyJob is the error returned when an empty job is published.\n\tErrEmptyJob = errors.NewKind(\"invalid empty job\")\n\t// ErrTxNotSupported is the error returned when the transaction receives a\n\t// callback does not know how to handle.\n\tErrTxNotSupported = errors.NewKind(\"transactions not supported\")\n)\n```\n\n```go\nvar (\n\t// ErrUnsupportedProtocol is the error returned when a Broker does not know\n\t// how to connect to a given URI.\n\tErrUnsupportedProtocol = errors.NewKind(\"unsupported protocol: %s\")\n\t// ErrMalformedURI is the error returned when a Broker does not know\n\t// how to parse a given URI.\n\tErrMalformedURI = errors.NewKind(\"malformed connection URI: %s\")\n)\n```\n\n```go\nvar ErrCantAck = errors.NewKind(\"can't acknowledge this message, it does not come from a queue\")\n```\nErrCantAck is the error returned when the Job does not come from a queue\n\n## Functions\n\n```go\nfunc Register(name string, b BrokerBuilder)\n```\nRegister 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\\`.\n\n## Types\n\n```go\ntype Acknowledger interface {\n\t// Ack is called when the Job has finished.\n\tAck() error\n\t// Reject is called if the job has errored. The parameter indicates\n\t// whether the job should be put back in the queue or not.\n\tReject(requeue bool) error\n}\n```\nAcknowledger 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.\n\n```go\ntype Broker interface {\n\t// Queue returns a Queue from the Broker with the given name.\n\tQueue(string) (Queue, error)\n\t// Close closes the connection of the Broker.\n\tClose() error\n}\n```\nBroker represents a message broker.\n\n```go\nfunc NewBroker(uri string) (Broker, error)\n```\nNewBroker creates a new Broker based on the given URI. In order to register different implementations the package should be imported, example:\n\n\timport _ \"gopkg.in/src-d/go-queue.v1/amqp\"\n\n```go\ntype BrokerBuilder func(uri string) (Broker, error)\n```\nBrokerBuilder instantiates a new Broker based on the given uri.\n\n```go\ntype Job struct {\n\t// ID of the job.\n\tID string\n\t// Priority is the priority level.\n\tPriority Priority\n\t// Timestamp is the time of creation.\n\tTimestamp time.Time\n\t// Retries is the number of times this job can be processed before being rejected.\n\tRetries int32\n\t// ErrorType is the kind of error that made the job fail.\n\tErrorType string\n\t// ContentType of the job\n\tContentType string\n\t// Raw content of the Job\n\tRaw []byte\n\t// Acknowledger is the acknowledgement management system for the job.\n\tAcknowledger Acknowledger\n}\n```\nJob contains the information for a job to be published to a queue.\n\n```go\nfunc NewJob() (*Job, error)\n```\nNewJob creates a new Job with default values, a new unique ID and current timestamp.\n\n```go\nfunc (j *Job) Ack() error\n```\nAck is called when the job is finished.\n\n```go\nfunc (j *Job) Decode(payload interface{}) error\n```\nDecode decodes the payload from the wire format.\n\n```go\nfunc (j *Job) Encode(payload interface{}) error\n```\nEncode encodes the payload to the wire format used.\n\n```go\nfunc (j *Job) Reject(requeue bool) error\n```\nReject is called when the job errors. The parameter is true if and only if the job should be put back in the queue.\n\n```go\nfunc (j *Job) SetPriority(priority Priority)\n```\nSetPriority sets job priority\n\n```go\nfunc (j *Job) Size() int\n```\nSize returns the size of the message.\n\n```go\ntype JobIter interface {\n\t// Next returns the next Job in the iterator. It should block until\n\t// a new job becomes available or while too many undelivered jobs have\n\t// been already returned (see the argument to Queue.Consume). Returns\n\t// ErrAlreadyClosed if the iterator is closed.\n\tNext() (*Job, error)\n\tio.Closer\n}\n```\nJobIter represents an iterator over a set of Jobs.\n\n```go\ntype Priority uint8\n```\nPriority represents a priority level.\n\n```go\nconst (\n\t// PriorityUrgent represents an urgent priority level.\n\tPriorityUrgent Priority = 8\n\t// PriorityNormal represents a normal priority level.\n\tPriorityNormal Priority = 4\n\t// PriorityLow represents a low priority level.\n\tPriorityLow Priority = 0\n)\n```\n\n```go\ntype Queue interface {\n\t// Publish publishes the given Job to the queue.\n\tPublish(*Job) error\n\t// PublishDelayed publishes the given Job to the queue with a given delay.\n\tPublishDelayed(*Job, time.Duration) error\n\t// Transaction executes the passed TxCallback inside a transaction.\n\tTransaction(TxCallback) error\n\t// Consume returns a JobIter for the queue.  It receives the maximum\n\t// number of unacknowledged jobs the iterator will allow at any given\n\t// time (see the Acknowledger interface).\n\tConsume(advertisedWindow int) (JobIter, error)\n\t// RepublishBuried republishes to the main queue those jobs complying\n\t// one of the conditions, leaving the rest of them in the buried queue.\n\tRepublishBuried(conditions ...RepublishConditionFunc) error\n}\n```\nQueue represents a message queue.\n\n```go\ntype RepublishConditionFunc func(job *Job) bool\n```\nRepublishConditionFunc is a function used to filter jobs to republish.\n\n```go\ntype RepublishConditions []RepublishConditionFunc\n```\nRepublishConditions alias of a list RepublishConditionFunc\n\n```go\nfunc (c RepublishConditions) Comply(job *Job) bool\n```\nComply checks if the Job matches any of the defined conditions.\n\n```go\ntype TxCallback func(q Queue) error\n```\nTxCallback is a function to be called in a transaction.\n\n","path":"github.com/src-d/go-queue","name":"queue","synopsis":"","isRedistributable":true}
