amqpw

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2018 License: MIT Imports: 10 Imported by: 0

README

AMQP worker adapter for Buffalo

This package implements the github.com/gobuffalo/buffalo/worker.Worker interface using the github.com/streadway/amqp package.

It allows AMQP-compatible message brokers, such as RabbitMQ, to process Buffalo's background tasks.

Setup

import "github.com/stanislas-m/amqp-work-adapter"
import "github.com/streadway/amqp"

// ...

conn, err := amqp.Dial("amqp://guest:guest@localhost:5672")
if err != nil {
    log.Fatal(err)
}

buffalo.New(buffalo.Options{
  // ...
  Worker: amqpw.New(amqpw.Options{
    Connection: conn,
    Name:           "myapp",
    MaxConcurrency: 25,
  }),
  // ...
})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConnection = errors.New("invalid connection")

ErrInvalidConnection is returned when the Connection opt is not defined.

Functions

This section is empty.

Types

type Adapter

type Adapter struct {
	Connection *amqp.Connection
	Channel    *amqp.Channel
	Logger     Logger
	// contains filtered or unexported fields
}

Adapter implements the buffalo.Worker interface.

func New

func New(opts Options) *Adapter

New creates a new AMQP adapter for Buffalo workers.

func (Adapter) Perform

func (q Adapter) Perform(job worker.Job) error

Perform enqueues a new job.

func (Adapter) PerformAt

func (q Adapter) PerformAt(job worker.Job, t time.Time) error

PerformAt performs a job at the given time.

func (Adapter) PerformIn

func (q Adapter) PerformIn(job worker.Job, t time.Duration) error

PerformIn performs a job delayed by the given duration.

func (*Adapter) Register

func (q *Adapter) Register(name string, h worker.Handler) error

Register consumes a task, using the declared worker.Handler

func (*Adapter) Start

func (q *Adapter) Start(ctx context.Context) error

Start connects to the broker.

func (*Adapter) Stop

func (q *Adapter) Stop() error

Stop closes the connection to the broker.

type Logger

type Logger interface {
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Errorf(string, ...interface{})
	Debug(...interface{})
	Info(...interface{})
	Error(...interface{})
}

Logger is used by the worker to write logs

type Options

type Options struct {
	// Connection is the AMQP connection to use.
	Connection *amqp.Connection
	// Logger is a logger interface to write the worker logs.
	Logger Logger
	// Name is used to identify the app as a consumer. Defaults to "buffalo".
	Name string
	// Exchange is used to customize the AMQP exchange name. Defaults to "".
	Exchange string
	// MaxConcurrency restricts the amount of workers in parallel.
	MaxConcurrency int
}

Options are used to configure the AMQP Buffalo worker adapter.

Jump to

Keyboard shortcuts

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