Chapter 5. Message Delivery and Acceptance

5.1. The Lifecycle of a Message

5.1.1. Message Delivery Overview

The following diagram illustrates the message delivery lifecycle.
The lifecycle of a message.

Figure 5.1. Fanout Exchange

A message producer generates a message. A message is an object with content, a subject, and headers. At the minimum, a message producer will produce a message with message content.
The message producer may send the message to the broker and let the routing be taken care of by the properties of the message or by the address of the sender object used to send the message (1).
Or the message producer may set the message.subject, which acts as the routing key (2), and then send the message to the broker (3).
Consumers subscribed to exchanges (which uses a temporary, private queue in the background) receive messages when they are connected (4).
Messages are buffered in queues that are subscribed to exchanges (5). Consumers can subscribe to queues and receive messages that were buffered while the consumer was disconnected (6). These queues can also be used to share responsibility for messages between consumers.

5.1.2. Message Generation

The Message object is used to generate a message.
Python
import sys
from qpid.messaging import *     
...        
msg = Message('This is the message content')
msg.content = 'Message content can be assigned like this'
msg.properties['header-key'] = 'value'

tx = ssn.sender('amq.topic')

# msg.subject set by sender for routing purposes
tx.send(msg)

msg.subject = 'Messaging Routing Key can also be manually set'
# beware that this will interfere with sender-object-based routing

5.1.5. Message Distribution on the Broker

When the broker receives a message, it examines the message and the routing information associated with it to determine how to deliver it.
The bindings on the exchanges that receive the message are examined, and when there is a match between the message and a binding, the message is delivered to any queue with that binding.