consumer

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package consumer consolidates all the functions and methods for queue consumers. It implements a reconnection method as well.

Usage

 con, err := consumer.New(
	 consume.Server(server),
	 consumer.Exchange(exchange),
	 consume.Queue(queue),
 )
 for server.Loop() {
	 select {
	 case msg := <-con.Subscribe():
		 // do things with the message
	 }
 }

Index

Constants

View Source
const ENOEXCHANGE = "no exchange declared"
View Source
const ENOQUEUE = "no queue declared, can't consume without queues"
View Source
const ENOSERVER = "no valid server in rabbit"

ENOSERVER is returned when there's no valid server.Server definition. It may mean an error on the connection or the initialization.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer struct {
	// contains filtered or unexported fields
}

A Consumer represents a RabbitMQ consumer of messages against a set of queues. It implements logic to have always a connection available where to receive messages from.

func New

func New(opts ...Option) (*Consumer, error)

New returns a Consumer or an error if it's not in a working state. A Server argument is required, if it's missing it will return a rabbit.ENOCONN and if it's an incorrect value it will return a ENOSERVER.

func (*Consumer) Close

func (c *Consumer) Close()

func (*Consumer) RoutingKeys

func (c *Consumer) RoutingKeys() []string

RoutingKeys returns a slice of all the routing keys being used against the queue in this consumer.

func (*Consumer) Subscribe

func (c *Consumer) Subscribe() <-chan amqp.Delivery

type Option

type Option func(*Consumer) error

func Args

func Args(a amqp.Table) Option

Args changes the args to consume call.

func AutoAck

func AutoAck() Option

AutoAck makes the consumer auto-acknowledge messages as soon as they are received.

func Exchange

func Exchange(e exchange.Exchange) Option

Exchange adds a rabbit.Exchange definition to Consumer.

func Exclusive

func Exclusive() Option

Exclusive marks as true the exclusive value on the Consume method from AMQP.

func Internal

func Internal() Option

Internal changes the boolean internal value to true.

func NoWait

func NoWait() Option

NoWait changes the boolean nowait value to true.

func Qos

func Qos(q int) Option

Qos sets the prefetch value for the consuming of queues.

func Queue

func Queue(q queue.Queue) Option

Queue adds a rabbit.Queue to a slice of rabbit.Queue's in the consumer.

func Server

func Server(r *server.Server) Option

Server adds a Server definition to the Consumer as a server value.

func Tag

func Tag(tag string) Option

Tag adds a consumer tag being sent as the consumer value.

Jump to

Keyboard shortcuts

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