publisher

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: 5 Imported by: 0

Documentation

Overview

Package publisher makes handling RabbitMQ's publishing tasks easier.

Index

Constants

View Source
const ENOEXCHANGE = "no exchange declared correctly"

ENOEXCHANGE is returned when no server.Exchange is properly declared. The default is not enough, it needs a name.

View Source
const ENOSERVER = "incorrect or no server passed. Use Rabbit() to pass one"

ENOSERVER is returned when the server.Server passed is incorrect, nil or there was no server.Server passed. Check the method Server() under the Option type.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Publisher) error

func Exchange

func Exchange(e exchange.Exchange) Option

Exchange adds a server.Exchange definition to a Publisher.

func Immediate

func Immediate() Option

Set the immediate option in the Publish action. Defaults to false, the only logic use of Immediate() method is to set it true.

func Mandatory

func Mandatory() Option

Set the mandatory option in the Publish action. Defaults to false, the only logic use of Mandatory() method is to set it true.

func PublishingTemplate

func PublishingTemplate(tpl amqp.Publishing) Option

PublishingTemplate adds a template of the amqp.Publishing structure to the Publisher. If this is not set the only default value in the Publishing template is ContentType as "text/plain".

func RoutingKey

func RoutingKey(k string) Option

RoutingKey adds a Routing Key value during the publishing action of the Publisher.

func Server

func Server(r *server.Server) Option

Server adds a server.Server representation to a Publisher.

type Publisher

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

A Publisher represents a RabbitMQ publisher of messages against an specific queue. It implements logic to have always a connection available before trying to send a message and reconnect as possible.

func New

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

New returns a Publisher or an error if is not in a working state. A Server argument is required, if it's missing it will return a server.ENOCONN and if it's incorrect it will return a ENOSERVER. If no Exchange is passed it will return a ENOEXCHANGE.

func (*Publisher) Close

func (p *Publisher) Close() error

Close will call the method Close against the *amqp.Channel.

func (*Publisher) RoutingKey

func (p *Publisher) RoutingKey() string

RoutingKey returns the routing key to which is publishing against the exchange.

func (*Publisher) Send

func (p *Publisher) Send(body []byte) error

Send returns an error if something goes wrong while publishing. If it's awaiting for a reconnection then it will block until either a reconnection succeeds or a close notification is sent, in which case it will return the closing error and it won't try to send the message. On subsequent calls it will return a ENOSERVER becase server.Server.Loop() in that case will be false.

Jump to

Keyboard shortcuts

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