Special characters in topics

A topic can contain any character in the Unicode character set. However, the following three characters have a special meaning:
  • The topic level separator "/".
  • The multilevel wild card "#".
  • The single-level wild card "+".

The topic level separator is used to introduce structure into the topic, and can therefore be specified within the topic for that purpose.

The multilevel wild card and single-level wild card can be used for subscriptions, but they cannot be used within a topic by the publisher of a message.

The topic level separator

The topic level separator character "/" is used to provide a hierarchical structure to the topic space. It must be used by applications to separate levels within a topic tree. The use of the topic level separator is significant when the two wildcard characters are encountered in topics specified by subscribers.

Topic hierarchy is important in the administration of access control.

The multilevel wild card

The multilevel wildcard character "#" is used to match any number of levels within a topic. For example, using the example topic tree shown above, if you subscribe to "USA/Alaska/#", you receive messages on topics "USA/Alaska" and "USA/Alaska/Juneau".

The multilevel wild card can represent zero or more levels. Therefore, "USA/#" can also match the singular "USA", where # represents zero levels. The topic level separator is meaningless in this context, because there are no levels to separate.

The multilevel wild card can be specified only on its own or next to the topic level separator character. Therefore, "#" and "USA/#" are both valid, but "USA#" is not valid.