4.2.3. Publishing Messages to a Direct Exchange

direct_producer.py publishes a series of messages to the amq.direct exchange. It uses a simple loop to create ten messages, then signals that no more messages are expected by publishing a message with the content That's all, folks!. The routing key is specified in the delivery properties for the message. Here is the main body for this program.
# Create some messages and put them on the broker.
props = session.delivery_properties(routing_key="routing_key")

for i in range(10):
     session.message_transfer(destination="amq.direct", message=Message(props,"message " + str(i)))

session.message_transfer(destination="amq.direct", message=Message(props,"That's all, folks!"))
Note that the last message sent is That's all, folks!. The consumer looks for this text to determine when all messages have been received.