Creating Topics
When using the JCSMP or .NET APIs, which are 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.
When using the JavaScript and Node.js APIs, a generic Destination instance is created and used instead of a Topic instance.
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.
When using the C API, a Topic is simply set as a destination message property (refer to Destination).
Topics
To create a Topic (non-temporary), call one of the methods listed below on a connected Session and pass in a topic name.
PubSub+ Messaging API | Use |
---|---|
JCSMP |
|
Java RTO |
|
C |
Not applicable |
.NET |
|
JavaScript and Node.js |
|
Temporary Topics
To create a temporary Topic, call one of the listed methods 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.
PubSub+ Messaging API | Use |
---|---|
JCSMP (legacy Solace Java API) |
JCSMPSession.createTemporaryTopic() |
Java RTO |
SessionHandle.createTemporaryTopic() |
C |
Not applicable |
.NET |
ISession.createTemporaryTopic() |
JavaScript and Node.js |
Not applicable |
Related Samples
For an example of how to create Topics and temporary Topics, refer to the SimpleFlowToTopic
sample for the JCSMP, Java RTO, and .NET APIs.