5.4. Writing Publish/Subscribe Applications in C++

5.4. Writing Publish/Subscribe Applications in C++

This section describes two programs that implement Publish/Subscribe messaging using a topic exchange.

Note

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.