Using Publish and Subscribe Messaging

As discussed at the beginning of this chapter, publish and subscribe messaging provides an alternative method of loosely coupled component interaction. In the following example, a message client sends a request for information on particular movies. As shown previously with the message queue example, the message is in an XML format, so parsing and processing the message is made simpler.

Creating a publish and subscribe client is similar to creating a message queue client. But instead of sending the message to a queue, we will publish it to a topic. The following code example demonstrates this process.

The JMSClientPS Class
 package examples.jms; import java.util.*; import javax.naming.*; import javax.jms.*; ...

Get J2EE™ and Beyond: Design, Develop, and Deploy World-Class Java™ Software now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.