Topics
Last updated
Last updated
Copyright 2013-2024 60East Technologies, Inc.
A topic is a string that is used to declare a subject of interest for purposes of routing messages between publishers and subscribers. Topic-based Publish and Subscribe (e.g., Pub/Sub) is the simplest form of Pub/Sub filtering. All messages are published with a topic designation to the AMPS engine, and subscribers will receive messages for topics to which they have subscribed.
For example, in the diagram above there are two publishers: Publisher 1 and Publisher 2 which publish to the topics LN_ORDERS
and NY_ORDERS
, respectively. Messages published to AMPS are filtered and routed to the subscribers of a respective topic. For example, Subscriber 1, which is subscribed to all messages for the LN_ORDERS
topic will receive everything published by Publisher 1. Subscriber 2, which is subscribed to the regular expression topic ".*_ORDERS"
will receive all orders published by Publisher 1 and 2.
Regular expression matching makes it easy to create topic paths in AMPS. Some messaging systems require a specific delimiter for paths. AMPS allows you the flexibility to use any delimiter. However, 60East recommends using characters that do not have significance in regular expressions, such as forward slashes. For example, rather than using northamerica.orders
as a path, use northamerica/orders
.
AMPS does not restrict the characters that can be present in a topic name. However, notice that topic names that contain regular expression characters (such as .
or *
) will be interpreted as regular expressions by default, which may cause unexpected behavior.
Topics that begin with /AMPS
are reserved. The AMPS server publishes messages to topics that begin with /AMPS
as described in the Event Topics section. Some versions of the AMPS client libraries may internally publish to /AMPS/devnull
. Your applications should not publish to topics that begin with /AMPS
, as publishes to those topics may fail.
Each topic has an associated message type. Each client connection to AMPS also has an associated message type. A given client connection can only publish to topics with the same message type, and can only receive messages from topics with the same message type.
AMPS does not require explicit configuration of a topic for publishers to send messages to the topic and subscribers to receive messages from the topic. However, if there is no configuration for the topic, AMPS does not persist messages to the topic, so no features that depend on having a persisted message state (for example; replay, aggregation, State of the World, and so on) are available for that topic. The message will be delivered to subscriptions that are active when the message is published, but the message will not be persisted or retained. These "ad hoc" topics are useful for low-latency delivery of messages that are only useful at the time that they are published.
With AMPS, a subscriber can use a regular expression to simultaneously subscribe to multiple topics that match the given pattern. This feature can be used to effectively subscribe to topics without knowing the topic names in advance.
Notice that a message cannot be published to a topic pattern. The topic for a given message is unambiguously specified using a literal string. From the publisher’s point of view, it is publishing a message to a topic. A publisher does not publish to a topic pattern.
When a subscription is sent to AMPS, the topic for the subscription is interpreted as a regular expression if the topic includes special regular expression characters. Otherwise, the topic must be an exact match.
Some examples of regular expressions to match a set of topics are included in the table below:
Topic | Behavior |
| Matches only "trade". |
| Matches "client", "clients", "client001", etc. |
| Matches "NYSEtrades", "ICEtrade", etc. |
| Matches "trade/info", "trade-info", "every/trade/info", etc. |
For more information regarding the regular expression syntax supported within AMPS, please see the Regular Expressions section for details.
AMPS can be configured to disallow regular expression topic matching for subscriptions. See the AMPS Configuration Guide for details.