Creating Topics
When using the JCSM, Java RTO, and Javascript, Node.js, 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.
In the C (not object-oriented) where a topic is simply a string (char*
).
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 |
|
.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) |
|
Java RTO |
|
C |
|
.NET |
|
JavaScript and Node.js |
Not applicable |
Related Samples
For an example of how to create topics and temporary topics, refer to the SimpleFlowToTopic
samples for the JCSMP, Java RTO, and .NET APIs.