Documentation ¶
Overview ¶
Package mq wrap the github.com/streadway/amqp library to be able to mock it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Delivery ¶
Delivery interface provide a wrapper for the message and acknowledgment system of AMQP. It will allows the read the body of the message and either aknowledge it or non acknowledge it.
type MQ ¶
type MQ struct { Conn *amqp.Connection Channel *amqp.Channel }
MQ struct is compliant to the MessageQueue interface.
func NewMQ ¶
NewMQ open a connection to AMQP server, open a channel of communication and then return a MQ struct holding the connection and the channel.
func (MQ) Consume ¶
Consume will start listening to the message queue using the provided queue name. It will call the Receiver function every time a message arrives.
func (MQ) DeclareQueue ¶
DeclareQueue declare a queue an set QoS
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is the wrapper for the Delivery struct of the github.com/streadway/amqp library. Its purpose is to met the be compliant with the Delivery interface in this package (mq) and help making the rest of the project testable.
func (Message) Ack ¶
Ack delivers an acknowledgment that the message has been receive and treated. The multiple argument is true when the all the previous messages can be acknowledged as well.
type MessageQueue ¶
type MessageQueue interface { DeclareQueue(string) error Publish(string, []byte) error // Consume should block until the underlying connection to is closed // or the Receiver function send a bool to the channel it's passed Consume(string, Receiver) error }
MessageQueue interface help masking the complexity of the amqp library and reduce them to the needs of this project. The interface helps testing and only provide with the ability to declare a queue, publish on a queue and consume the elements coming on a queue.
type Receiver ¶
Receiver is a function type that will be called every time a message arrives on the message queue. It will be provided with a Delivery. The Receiver can then use the Body of the Delivery to make the necessary computations and either acknowledge or non acknowledge the message for it to be requeued or not. The boolean channel can make the message queue stop consuming the queue. If so, it will be needed to call Consume again, because the function will return.