Creating Topics

When using the PubSub+ Java RTO API, PubSub+ JavaScript API, PubSub+ Node.js API, or PubSub+ .NET API (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 PubSub+ C API (not object-oriented) where a topic is simply a string (char*).

When using the PubSub+ JavaScript API and PubSub+ Node.js API, 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 PubSub+ 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.

To Create Topics

PubSub+ Messaging API Use

PubSub+ Java RTO API

  • Solclient.Allocator.NewTopic(...)

PubSub+ C API

  • No function, a topic is a char* (string).

PubSub+ .NET API

  • ContextFactory.createTopic(...)

  • Helper.Destination.TopicFromEncodedName(...)

PubSub+ JavaScript API and PubSub+ Node.js API

  • solace.SolClientFactory.createTopicDestination(...)

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.

To Create Temporary Topics

PubSub+ Messaging API Use

PubSub+ Java RTO API

SessionHandle.createTemporaryTopic()

PubSub+ C API

solClient_session_createTemporaryTopicName()

PubSub+ .NET API

ISession.createTemporaryTopic()

PubSub+ JavaScript API and PubSub+ Node.js API

Not applicable

Related Samples

For an example of how to create topics and temporary topics, refer to the SimpleFlowToTopic samples for the PubSub+ Java RTO API and PubSub+ .NET API.