Comment on page
Fundamentally, NATS is about publishing and listening for messages. Both of these depend heavily on Subjects.
What is a Subject? At its simplest, a subject is just a string of characters that form a name which the publisher and subscriber can use to find each other. It helps scope messages into streams or topics.
For compatibility across clients, we recommend using ASCII characters (this may change in future).
9(names are case sensitive, and cannot contain whitespace). Special characters: The period
.(which is used to separate the tokens in the subject) and
>are used as wildcards). Reserved subject names: By convention subject names starting with a
$are reserved for system use (e.g. subject names starting with
.character is used to create a subject hierarchy. For example, a world clock application might define the following to logically group related subjects:
NATS provides two wildcards that can take the place of one or more elements in a dot-separated subject. Subscribers can use these wildcards to listen to multiple subjects with a single subscription but Publishers will always use a fully specified subject, without the wildcard.
The first wildcard is
*which will match a single token. For example, if an application wanted to listen for eastern time zones, they could subscribe to
time.*.east, which would match
The second wildcard is
>which will match one or more tokens, and can only appear at the end of the subject. For example,
time.us.*would only match
time.us.eastsince it can't match more than one token.
Subject to your security configuration, wildcards can be used for monitoring by creating something sometimes called a wire tap. In the simplest case you can create a subscriber for
>. This application will receive all messages -- again, subject to security settings -- sent on your NATS cluster.
*can appear multiple times in the same subject. Both types can be used as well. For example,
It is recommended to keep the maximum number of tokens in your subjects to a reasonable value of 16 tokens max.