Documentation ¶
Index ¶
- func Initialize(configFile string, queues interface{}) error
- type Config
- type Event
- type MessageBrokerClientInterface
- type RabbitMq
- type RabbitMqClient
- func (cl *RabbitMqClient) Connect() error
- func (cl *RabbitMqClient) Consume(queueName string, workers uint, callback func(msg []byte, consumer string)) error
- func (cl *RabbitMqClient) CreateQueue(queueName string) error
- func (cl *RabbitMqClient) Disconnect() error
- func (cl *RabbitMqClient) Publish(event SerializableEventInterface, queueName string) error
- func (cl *RabbitMqClient) WatchWorkersStream()
- type SerializableEventInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Initialize ¶
Initialize : function takes care of two things : it parses the config of the amqb system, and creates the queues as binds them to the default exchange
Types ¶
type Config ¶
type Config struct {
RabbitMq RabbitMq
}
Config struct : describes the structure of the .yml file configuration
type Event ¶
Event : is the simplest form of event, provided as a quick way to
func (*Event) Deserialize ¶
Deserialize implements how an event of type Event is deserialize
type MessageBrokerClientInterface ¶
type MessageBrokerClientInterface interface { Connect() error Disconnect() error CreateQueue(queueName string) error Publish(event SerializableEventInterface, queueName string) error Consume(queueName string, workers uint, callback func(msg []byte, consumer string)) error WatchWorkersStream() }
MessageBrokerClientInterface : to create a message broker client, the client must implement this interface so that it can be used by other system components
func New ¶
func New() (MessageBrokerClientInterface, error)
New function creates a new client with a new connection (channel) to the message broker
type RabbitMq ¶
type RabbitMq struct { Connection struct { Host string `yaml:"host"` Port string `yaml:"port"` User string `yaml:"user"` Password string `yaml:"password"` } Logs struct { Logfile string `yaml:"logfile"` } }
RabbitMq struct : describes the rabbitmq configuration (connection, loggig settings)
type RabbitMqClient ¶
type RabbitMqClient struct {
// contains filtered or unexported fields
}
RabbitMqClient is the default Message Broker client that wraps streadway/amqp implementation of rabbitmq api streadway/amqp can be easily replaced with other implementations, all is need is a struct of type MessageBrokerClientInterface
func (*RabbitMqClient) Connect ¶
func (cl *RabbitMqClient) Connect() error
Connect connects the client to the amqp server
func (*RabbitMqClient) Consume ¶
func (cl *RabbitMqClient) Consume(queueName string, workers uint, callback func(msg []byte, consumer string)) error
Consume is used to consume events / messages from a specific queue. A callback function is required as a parameter, and it' called whn a new message has been received
func (*RabbitMqClient) CreateQueue ¶
func (cl *RabbitMqClient) CreateQueue(queueName string) error
CreateQueue is used to create a queue, by default all the queues created are durable, which means even if the message broker restarts, it will automatically recreate the queues upon recovery without data loss
func (*RabbitMqClient) Disconnect ¶
func (cl *RabbitMqClient) Disconnect() error
Disconnect closes the connection (channel) with the amqp server
func (*RabbitMqClient) Publish ¶
func (cl *RabbitMqClient) Publish(event SerializableEventInterface, queueName string) error
Publish : publishes an event of type SerializableEventInterface to a specific queue
func (*RabbitMqClient) WatchWorkersStream ¶
func (cl *RabbitMqClient) WatchWorkersStream()
WatchWorkersStream does a couple of things : it's a multiplexer of the logs of all the successfully consumed and handled events in the system, it also blocks the function calling it from exiting the consumers. Not calling this function would make it necessary for the developer to create consumers with a go routine [ go client.Consume(..)] and use the wait method from the builtin asynch package to manage concurrency in order to prevent the program from exiting.
type SerializableEventInterface ¶
type SerializableEventInterface interface { Serialize() ([]byte, error) Deserialize(jsonString []byte) error }
SerializableEventInterface : to create an event struct that can be published and consumed by the message broker the struct has to be of type SerializableEventInterface and should implement Serialize() and Deserialize() methods