Creating Topics

When using the Java 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.

To Create Topics

Language

Call

Java

  • JCSMPFactory.createTopic(...)

  • DestinationUtils.topicFromNetworkName(...)

Java RTO

  • Solclient.Allocator.NewTopic(...)

C

Not applicable

.NET

  • ContextFactory.createTopic(...)

  • Helper.Destination.TopicFromEncodedName(...)

JavaScript and Node.js

  • solace.SolClientFactory.createTopicDestination(...)

Temporary Topics

To create a temporary Topic, call one of the listed methods lon 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 the Java API, 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.

To Create Temporary Topics

Language

Call

Java

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 Java, Java RTO, and .NET APIs.