5.4. Writing Publish/Subscribe Applications in C++
This section describes two programs that implement Publish/Subscribe messaging using a topic exchange.
topic_publisher.cpp sends messages to the amq.topic exchange, using the multipart routing keys usa.news, usa.weather, europe.news, and europe.weather.
topic_listener.cpp creates private queues for news, weather, usa, and europe, binding them to the amq.topic exchange using bindings that match the corresponding parts of the multipart routing keys.
The topic_listener program reads only messages published after it begins running. Run topic_publisher after starting topic_listener to send messages to the subscriber.
In this example, the publisher creates messages for topics like news, weather, and sports that happen in regions like Europe, Asia, or the United States. A given consumer may be interested in all weather messages, regardless of region, or it may be interested in news and weather for the United States, but uninterested in items for other regions. In this example, each consumer sets up its own private queues, which receive precisely the messages that particular consumer is interested in.