Creating Topics in the PubSub+ JCSMP API

When using the PubSub+ JCSMP API, which is object-oriented, a client must create a topic instance to encapsulate a topic name that can be used as a destination to publish messages to. Topic instances can also be used by consumers to indicate through subscriptions what messages they are interested in receiving.

Clients can create:

  • Non-temporary Topics at the factory level.
  • Temporary Topics at the Session level. The scope and lifetime of a temporary Topic is that of the Session it is created in.

For information on the supported Topic syntax rules, refer to Topic Support & Syntax.

Topics

To create a non-temporary topic, call the JCSMPFactory.createTopic(...) method listed below on a connected session and pass in a topic name:

Temporary Topics

To create a temporary topic, call the JCSMPSession.createTemporaryTopic() method on a connected session. A temporary topic’s physical name is automatically generated by the API.

A temporary topic can only be created on a connected Session.

When using JCSMP, a connection automatically occurs when the first operation is performed on the session. Therefore, it is recommended that another operation, for example, adding a subscription, is performed before attempting to create a temporary topic, as this establishes the necessary connection.

Related Samples

For an example of how to create Topics and temporary Topics, refer to the SimpleFlowToTopic sample on the Solace Developer Hub.