Chapter 1. Initial Concepts
In AMQP, a connection represents a network connection, and a session represents the interface between a client and a broker. A session uses a connection for communication. Sessions may be synchronous or asynchronous.
The following diagram shows how the MRG Messaging broker is used by producer-consumer applications. Message producers write to exchanges, exchanges route messages to queues, and message consumers read from queues.
A message producer creates a message, fills it with content, gives the message a routing key, and sends it to an exchange (for one kind of exchange, the fanout exchange, a routing key is optional). The routing key is simply a string that the exchange can use to determine to which queues the message should be delivered. The way the routing key is used depends on the exchange type, and is discussed later in this chapter. Before delivering a message, the message producer can also set various message properties in the message; for instance, one property determines whether the message is durable. A MRG Messaging broker does not lose durable messages. Even if the broker suffers a hardware failure, all durable messages are delivered when the broker is restarted. Another property can be used to specify message priority; the broker gives higher priority messages precedence.
An exchange accepts messages from message producers and routes them to message queues if the message meets the criteria expressed in a binding. A binding defines the relationship between an exchange and a message queue, specifying which messages should be routed to a given queue. For instance, a binding might state that all messages with a given routing key should be sent to a particular queue. If a queue is not bound to an exchange, it does not receive any messages from that exchange.
A message queue holds messages and delivers them to the message consumers that subscribe to the queue. A message consumer can create, subscribe to, share, use, or destroy message queues (as long as they have permission to do so). A message queue may be durable, which means that the queue is never lost; even if the MRG Messaging Broker were to suffer a hardware failure, the queue would be restored when the broker is restarted. A message queue may be exclusive, which means only one client can consume messages from it. A message queue may also be auto-delete, which means that the queue will disappear from the server when the last client unsubscribes from the queue.
A message producer can use transactions to ensure that a group of messages are all received. In a transaction, messages and acknowledgments are batched together, and all messages in the transaction succeed or fail as a unit.
The simplest exchange type is a Fanout exchange, which sends each message to every queue bound to the exchange.