Understanding Topics

To understand how messages flow from publishers to subscribers you need to understand the role played by topics in the publish-subscribe model.

What Are Topics?

In an event-driven architecture (EDA), topics are a means of classifying the information contained in the event message. Events are published to a topic and endpoints can subscribe to one or more topics to attract events from publishers. In practice, topics are simply strings composed of one or more levels added to a message header.

Basic syntax

Topics have the format a/b/c/.../n, where 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/cats and animals/domestic/dogs to organize the content you're sending out. You can learn about the full syntactical rules, construction, and encoding in SMF Topics.

Topic Subscriptions

A topic subscription is a string used to attract published events. Topic subscriptions can contain wildcards to match with multiple topics. The * and > characters can be used as wildcards in topic subscriptions.

  • *
  • When * appears by itself at a level within a topic subscription it indicates a wildcard match at that level. For example, animals/*/cats matches the topics animals/domestic/cats and animals/wild/cats.

  • >
  • The > character is used at the last level of a subscription to indicate a “one or more” wildcard match for any topics. For example, animals/domestic/> doesn't match the topic animals/domestic, but it does match animals/domestic/cats, animals/domestic/dogs, and animals/domestic/dogs/beagles/long-eared.

To learn more about wildcard rules and their use in topic subscriptions, see Wildcard Characters in SMF Topic Subscriptions.

Topic Destinations

When an event message is published, it is sent to an endpoint that subscribes to the topic. Because the topic is used to specify where the message is received, topics can be thought of as "topic destinations". In other words, the message's destination is a topic rather than something like an IP address, which is a common expectation. Throughout the documentation, publishing is often referred to as "publishing to a topic".

How Event Brokers use Topics

If we think of topics as destinations, then the event broker can be thought of as the post office that directs events from the publisher to the subscribers' post boxes. Depending on how your EDA and event broker are configured event brokers use topics to send events to a few types of subscribers:

  • Endpoints—Endpoints are objects created on the event broker to persist messages. There are two types of endpoints: queue endpoints (usually just called queues), and topic endpoints.
    • Queues—A queue is both a destination that clients can publish messages to and an endpoint that clients can consume messages from. Queues that have been configured with topic subscriptions will receive messages with matching topics. A queue is typically used in a point-to-point (PTP) messaging environment. Queues can provide exclusive access to one consumer or access to multiple consumers where each is serviced in a round‑robin fashion.
    • Topic Endpoints—A topic endpoint attracts messages published to a topic for which the topic endpoint has a matching subscription. Any topic endpoints whose topic subscriptions match the topics on the incoming messages will receive those messages.
  • Clients—A client is a consuming application that connects to an event broker. Any of the event broker's clients that have been configured with topic subscriptions will receive messages with matching topics. Access control lists can govern which topics clients can subscribe to.

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.

More About Solace Topics

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 wildcard characters. He also provides some examples for different types of use cases.

All About Solace Topics!

How and when clients receive event messages and the how event brokers interact with publishers and clients depends on the type of messaging used. Learn more under Message Delivery Modes.