6.6. Writing Publish/Subscribe Applications in Java JMS
This section describes two programs that implement Publish/Subscribe messaging:
Publisher.java sends messages to the hierarchical topics usa.news, usa.weather, europe.news, and europe.weather.
Listener.java listens for messages sent to the topics #.news, #.weather, europe.#, and usa.#.
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.