broker

package
v0.0.0-...-0c4a537 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package broker exposes an abstracted and simplified implementation for interacting with a RabbitMQ node or cluster. At a very high level, a user will create/read a configuration which defines whether they intend to be a publisher or a subscriber The user will pass this configuration to the message broker which will handle the details of connecting to RabbitMQ and defining the queues and exchanges. After this, the user provides the necessary interfaces to the broker and it will handle the details of subscribing and reading messages or publishing messages as per the config. Known issues can be found on GitHub (https://github.com/KrylixZA/GoRabbitMqBroker/issues). This code is licensed under an MIT license. Authors: Simon Headley (KrylixZA).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMessagePublisher

func NewMessagePublisher(rmqConfig models.Config, logger logs.ILogger) *messageBroker

NewMessagePublisher initializes a message broker with a given publisher config.

This abstracts away the details of how the connection to RabbitMQ is made and how the exchanges are defined.
This will not initialize a subscriber. As a result, any attempts to subscribe to a queue after using this constructor will not succeed.

It is imperative that any users of this defer a call to Close() therafter. ILogger is some implementation of logs.ILogger.

By using an interface, the user of this endpoint can inject any implementation of ILogger.

func NewMessagePublisherSubscriber

func NewMessagePublisherSubscriber(rmqConfig models.Config, logger logs.ILogger) *messageBroker

NewMessagePublisherSubscriber initializes a messsage broker with a given config.

This abstracts away the details of how the connection to RabbitMQ is made and how the queues and exchanges are defined.
This constructor should only ever be used if a user of the service needs to consume messages from a queue and publish to an exchange.
	It won't always be the case, but this will typically be when a subscriber implements IMessageHandler and then publishes to an exchange from the HandleMessage function.

It is imperative that any users of this defer a call to Close() therafter. ILogger is some implementation of logs.ILogger.

By using an interface, the user of this endpoint can inject any implementation of ILogger.

func NewMessageSubscriber

func NewMessageSubscriber(rmqConfig models.Config, logger logs.ILogger) *messageBroker

NewMessageSubscriber initializes a message broker with a given subscriber config.

This abstracts away the details of how the connection to RabbitMQ is made and how the queues and exchanges are defined.
This will not initialize a publisher. As a result, any attempts to publish a message after using this constructor will not succeed.

It is imperative that any users of this defer a call to Close() therafter. ILogger is some implementation of logs.ILogger.

By using an interface, the user of this endpoint can inject any implementation of ILogger.

Types

type IMessageBroker

type IMessageBroker interface {
	Publish(routingKey string, distributedMessage models.IDistributedMessage) error
	Subscribe(handler processing.IMessageHandler, distributedMessage models.IDistributedMessage) error
	Close()
}

IMessageBroker exposes an interface through which users can interact with a RabbitMQ broker. Publish exposes functionality to publish an instance of the IDistributedMessageInterface to the configured exchange with the given routing key.

The routing key can be a direct routing key, or wildcard if the exchange is configured as a Topic based exchange.
The distributed message is an implementation of the IDistributedMessage interface.

Subscribe exposes functionality to consume messages from a RabbitMQ queue.

The handler is a delegate to an implementation of the IMessageHandler interface. This has a HandleMessage function which processes the consumed message.
The distributed message is an implementation of the IDistributedMessage interface.

Close provides a simple endpoint to close the channel and the connection from RabbitMQ.

This call should, typically, be deferred immediately after calling a constructor.

Jump to

Keyboard shortcuts

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