Temporary Topics
In the chat example we explored in Chapter 2, we assumed that JMS clients would communicate with each other using established topics on which messages are asynchronously produced and consumed. In this section, we will explore ways to augment this basic mechanism by looking at temporary topics, which is a mechanism for JMS clients to create topics dynamically.
A temporary topic is a topic that is dynamically created by the
JMS provider, using the createTemporaryTopic method of the TopicSession object. A temporary topic is
associated with the connection that belongs to the TopicSession that created it. It is only
active for the duration of the connection and it is guaranteed to be
unique across all connections. Since it is temporary, it can’t be
durable—it lasts only as long as its associated client connection is
active. In all other respects, it is just like a “regular”
topic.
Since a temporary topic is unique across all client connections
(it is obtained dynamically through a method call on a client’s session
object), it is unavailable to other JMS clients unless the topic
identity is transferred using the JMSReplyTo header. While any client may
publish messages on another client’s temporary topic, only the sessions
that are associated with the JMS client connection that created the
temporary topic may subscribe to it. JMS clients can also, of course,
publish messages to their own temporary topics.
A temporary topic allows a consumer to respond directly to a producer. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access