Categorygithub.com/src-d/go-queue
modulepackage
1.0.6
Repository: https://github.com/src-d/go-queue.git
Documentation: pkg.go.dev

# README

go-queue GoDoc Build Status Build status codecov.io Go Report Card

Queue is a generic interface to abstract the details of implementation of queue systems.

Similar to the package database/sql, this package implements a common interface to interact with different queue systems, in a unified way.

Currently, only AMQP queues and an in-memory queue are supported.

Installation

The recommended way to install go-queue is:

go get -u gopkg.in/src-d/go-queue.v1/...

Usage

This example shows how to publish and consume a Job from the in-memory implementation, very useful for unit tests.

The queue implementations to be supported by the NewBroker should be imported as shows the example.

import (
    ...
	"gopkg.in/src-d/go-queue.v1"
	_ "gopkg.in/src-d/go-queue.v1/memory"
)

...

b, _ := queue.NewBroker("memory://")
q, _ := b.Queue("test-queue")

j, _ := queue.NewJob()
if err := j.Encode("hello world!"); err != nil {
    log.Fatal(err)
}

if err := q.Publish(j); err != nil {
    log.Fatal(err)
}

iter, err := q.Consume(1)
if err != nil {
    log.Fatal(err)
}

consumedJob, _ := iter.Next()

var payload string
_ = consumedJob.Decode(&payload)

fmt.Println(payload)
// Output: hello world!

Configuration

AMQP

The list of available variables is:

  • AMQP_BACKOFF_MIN (default: 20ms): Minimum time to wait for retry the connection or queue channel assignment.
  • AMQP_BACKOFF_MAX (default: 30s): Maximum time to wait for retry the connection or queue channel assignment.
  • AMQP_BACKOFF_FACTOR (default: 2): Multiplying factor for each increment step on the retry.
  • AMQP_BURIED_QUEUE_SUFFIX (default: .buriedQueue): Suffix for the buried queue name.
  • AMQP_BURIED_EXCHANGE_SUFFIX (default: .buriedExchange): Suffix for the exchange name.
  • AMQP_BURIED_TIMEOUT (default: 500): Time in milliseconds to wait for new jobs from the buried queue.
  • AMQP_RETRIES_HEADER (default: x-retries): Message header to set the number of retries.
  • AMQP_ERROR_HEADER (default: x-error-type): Message header to set the error type.

License

Apache License Version 2.0, see LICENSE

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

NewBroker creates a new Broker based on the given URI.
NewJob creates a new Job with default values, a new unique ID and current timestamp.
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`.

# Constants

PriorityLow represents a low priority level.
PriorityNormal represents a normal priority level.
PriorityUrgent represents an urgent priority level.

# Variables

ErrAlreadyClosed is the error returned when trying to close an already closed connection.
ErrCantAck is the error returned when the Job does not come from a queue.
ErrEmptyJob is the error returned when an empty job is published.
ErrMalformedURI is the error returned when a Broker does not know how to parse a given URI.
ErrTxNotSupported is the error returned when the transaction receives a callback does not know how to handle.
ErrUnsupportedProtocol is the error returned when a Broker does not know how to connect to a given URI.

# Structs

Job contains the information for a job to be published to a queue.

# Interfaces

Acknowledger represents the object in charge of acknowledgement management for a job.
Broker represents a message broker.
JobIter represents an iterator over a set of Jobs.
Queue represents a message queue.

# Type aliases

BrokerBuilder instantiates a new Broker based on the given uri.
Priority represents a priority level.
RepublishConditionFunc is a function used to filter jobs to republish.
RepublishConditions alias of a list RepublishConditionFunc.
TxCallback is a function to be called in a transaction.