To understand how messages flow from publishers to subscribers you need to understand the role played by topics. In this section we'll discuss, in a high-level, API-neutral manner, the fundamentals of publishing and subscribing to topics.
Once you're comfortable with the basics, we'll give you some suggestions about where you should go next to get more detailed information to help you start messaging.
Topics are a means of classifying information, and in practice they're simply strings that are composed of one or more levels.
Topics have the format
a, b, c and so on to
n are identifiers in a hierarchical scheme you've devised that allows you to classify your information. For example, if you're publishing information on household pets you might create topics like
animals/domestic/dogs to organize the content you're sending out.
There's more to topic syntax than these basics. You can learn about the full syntactical rules, construction, and encoding in SMF Topics .
> characters are used as wildcards in topic subscriptions:
* appears by itself at a level within a subscription it indicates a wildcard match at that level. Continuing with our household pets example,
animals/domestic/* matches the topics
animals/domestic/dogs, but doesn't match
> character has a little different meaning. When it appears by itself at the last level of a subscription it provides a “one or more” wildcard match for any topics with an identical prefix to the subscription. Again, using our example,
animals/domestic/> doesn't match the topic
animals/domestic, but it does match
To learn much more about wildcard rules, and their use in topic subscriptions, take a look at Wildcard Characters in SMF Topic Subscriptions.
As we saw in the Anatomy of a Message section, a message is composed of 3 parts:
Say you're a publisher, and you need to send out a message containing some information on a particular subject to a group of subscribers. In the publisher's message, the subject is represented by a topic that's part of the message's header, and the information itself is carried in the message's body.
Topics as destinations
One thing that sometimes trips people up is that those message header topics are often referred to as 'topic destinations'. In other words, the message's destination is a topic, and the destination isn't something like an IP address, which is a common expectation. Throughout the Solace documentation this is commonly called "publishing to a topic".
Mixed topics in a message stream
When you're publishing messages to topics, the messages in the stream you're sending don't all need to be on the same topic. Using our household pets example, one message could be on the topic
animals/domestic/dogs, followed by three on
animals/domestic/cats, followed by another two on
animals/domestic/dogs, followed by one on
animals/domestic/parrots, and so on. A single publisher isn't limited to publishing to a single topic.
Since topics are destinations, where do the messages land when they arrive at the event broker? They can wind up at a few places depending on how you've got your broker configured:
- Topic Endpoints
Any topic endpoints whose topic subscriptions match the topics on the incoming messages will receive those messages.
You can find out more about how to administratively configure event broker topic endpoints in Configuring Topic Endpoints.
Likewise, queues that have been configured with topic subscriptions will receive messages with matching topics.
For instructions on assigning topic subscriptions to queues, take a look at Adding Topic Subscriptions to Queues.
And finally, any of the event broker's clients that have been configured with topic subscriptions will receive messages with matching topics.
Access Control Lists govern which topics clients can subscribe to (and publish to, but that's a discussion for when you want finer control over publishers).
You can find information on how to set them up at ACL Configuration.
Topics don't consume event broker resources
It's important to note that there are no topic resources to be created or configured on an event broker. Recall, topics are just strings. This, along with wildcarding, allows for relatively effortless scaling up of the topic name space.
Subscribing clients can be bound to destination topic endpoints or queues, or nothing at all. Subscribing clients receive their messages from whatever they're bound to, and if they aren't bound to anything, they can directly receive messages that match the topic subscriptions in their profile.
The dynamics of how and when those clients receive the messages, as well as the actions between the event broker and the publishers, and the event broker and the subscribing clients, depends on whether Direct or Guaranteed messaging is used.
For more information, see the following:
Solace Developer advocate Aaron Lee walks through how topics are implemented in Solace and how the Solace event broker filters and routes messages based on subscriptions and wildcards. He also provides some examples for different types of use cases.
In this section we've only touched on the most basic topic functions. For more information about publishing and receiving messages via Solace APIs, see the following: