4.4.2. Publishing Messages to a Topic Exchange
The publisher application publishes messages to an exchange, with no knowledge of how that exchange is bound to queues or which consumers receive the messages. To publish messages using a topic exchange, specify the name of the exchange and the routing key. Routing keys for a topic exchange are typically multi-part, with the components separated by a period. The publisher publishes five messages with each of the four routing keys. Here's the code that publishes the messages for one of these routing keys, usa.news:
final = "That's all, folks!"
# usa.news
for i in range(5):
message = Content("message " + str(i))
message["routing_key"] = "usa.news"
session.message_transfer(destination="amq.topic", content=message)
message = Content(final)
message["routing_key"] = "usa.news"
session.message_transfer(destination="amq.topic", content=message)
# Now we repeat for "usa.weather", "europe.news", "europe.weather"