pubsub

package module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: MIT Imports: 6 Imported by: 0

README

pubsub

Wrapper of streadway/amqp that provides reconnection logic.

DRAFT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotConnected          = errors.New("not connected to a server")
	ErrAlreadyClosed         = errors.New("already closed: not connected to the server")
	ErrShutdown              = errors.New("session is shutting down")
	ErrNotSetDefaultQueue    = errors.New("default queue is not set")
	ErrNotSetDefaultExchange = errors.New("default exchange or key is not set")
)

Functions

This section is empty.

Types

type Bind

type Bind struct {
	QueueName    string
	ExchangeName string
	Key          string

	IsUsageDefault bool
}

type Consumer

type Consumer struct {
	Name      string
	QueueName string
	AutoAck   bool
	Exclusive bool

	Handler EventHandler
	// contains filtered or unexported fields
}

type Delivery added in v0.10.0

type Delivery struct {
	Exchange   string
	RoutingKey string

	Body []byte
}

type EventHandler

type EventHandler func(Delivery) error

type Exchange

type Exchange struct {
	Name       string
	Kind       string
	Durable    bool
	AutoDelete bool
	Internal   bool

	IsUsageDefault bool
}

type Option

type Option func(*Session) error

func WithDeclare

func WithDeclare(ex Exchange, q Queue, b Bind) Option

type Queue

type Queue struct {
	Name       string
	Durable    bool
	AutoDelete bool
	Exclusive  bool

	IsUsageDefault bool
}

type Session

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

func New

func New(addr string, opts ...Option) *Session

New creates a new Session instance, and automatically attempts to connect to the server.

func (*Session) AddConsumer added in v0.7.0

func (session *Session) AddConsumer(c *Consumer) error

func (*Session) ChannelClose

func (session *Session) ChannelClose() error

func (*Session) Close

func (session *Session) Close() error

Close will cleanly shutdown the channel and connection.

func (*Session) ExchangeDeclare added in v0.9.0

func (session *Session) ExchangeDeclare(ex Exchange) error

func (*Session) Publish added in v0.7.0

func (session *Session) Publish(message []byte) error

Push will push data onto the queue, and wait for a confirm. If no confirms are received until within the resendTimeout, it continuously re-sends messages until a confirm is received. This will block until the server sends a confirm. Errors are only returned if the push action itself fails, see UnsafePush.

func (*Session) PublishTo added in v0.7.0

func (session *Session) PublishTo(exchange, key string, message []byte) error

func (*Session) QueueBind added in v0.9.0

func (session *Session) QueueBind(b Bind) error

func (*Session) QueueDeclare

func (session *Session) QueueDeclare(q Queue) error

func (*Session) Stream

func (session *Session) Stream(c *Consumer) (<-chan amqp.Delivery, error)

Stream will continuously put queue items on the channel. It is required to call delivery.Ack when it has been successfully processed, or delivery.Nack when it fails. Ignoring this will cause data to build up on the server.

func (*Session) Subscribe

func (session *Session) Subscribe(handler func(Delivery) error) error

func (*Session) SubscribeTo added in v0.7.0

func (session *Session) SubscribeTo(queue string, handler func(Delivery) error) error

func (*Session) UnsafePublish added in v0.7.0

func (session *Session) UnsafePublish(message []byte, exchange, key string) error

UnsafePush will push to the queue without checking for confirmation. It returns an error if it fails to connect. No guarantees are provided for whether the server will recieve the message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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