mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
Update subjects.md
This commit is contained in:
parent
049617b61d
commit
81e5aa9ff7
@ -2,19 +2,7 @@
|
||||
|
||||
Fundamentally NATS is about publishing and listening for messages. Both of these depend heavily on _Subjects_ which scope messages into streams or topics. At its simplest, a subject is just a string of characters that form a name the publisher and subscriber can use to find each other.
|
||||
|
||||
<div class="graphviz"><code data-viz="dot">
|
||||
digraph g {
|
||||
rankdir=LR
|
||||
publisher [shape=box, style="rounded", label="PUB time.us"];
|
||||
subject [shape=circle, fixedsize="true", width="1.0", height="1.0", label="nats-server"];
|
||||
sub1 [shape=box, style="rounded", label="SUB time.us"];
|
||||
sub2 [shape=box, style="rounded", label="SUB time.us"];
|
||||
|
||||
publisher -> subject [label="msg"];
|
||||
subject -> sub1 [label="msg"];
|
||||
subject -> sub2 [label="msg"];
|
||||
}
|
||||
</code></div>
|
||||

|
||||
|
||||
The NATS server reserves a few characters as special, and the specification says that only "alpha-numeric" characters plus the "." should be used in subject names. Subjects are case-sensitive and cannot contain whitespace. For safety across clients, ASCII characters should be used, although this is subject to change in the future.
|
||||
|
||||
@ -38,39 +26,13 @@ NATS provides two _wildcards_ that can take the place of one or more elements in
|
||||
|
||||
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 `time.us.east` and `time.eu.east`.
|
||||
|
||||
<div class="graphviz"><code data-viz="dot">
|
||||
digraph g {
|
||||
rankdir=LR
|
||||
publisher [shape=box, style="rounded", label="PUB time.us.east"];
|
||||
subject [shape=circle, fixedsize="true", width="1.0", height="1.0", label="nats-server"];
|
||||
sub1 [shape=box, style="rounded", label="SUB time.*.east"];
|
||||
sub2 [shape=box, style="rounded", label="SUB time.us.east"];
|
||||
|
||||
publisher -> subject [label="msg"];
|
||||
subject -> sub1 [label="msg"];
|
||||
subject -> sub2 [label="msg"];
|
||||
}
|
||||
</code></div>
|
||||

|
||||
|
||||
### Matching Multiple Tokens
|
||||
|
||||
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.>` will match `time.us.east` and `time.us.east.atlanta`, while `time.us.*` would only match `time.us.east` since it can't match more than one token.
|
||||
|
||||
<div class="graphviz"><code data-viz="dot">
|
||||
digraph g {
|
||||
rankdir=LR
|
||||
publisher [shape=box, style="rounded", label="PUB time.us.east.atlanta"];
|
||||
subject [shape=circle, fixedsize="true", width="1.0", height="1.0", label="nats-server"];
|
||||
sub1 [shape=box, style="rounded", label="SUB time.us.east.atlanta"];
|
||||
sub2 [shape=box, style="rounded", label="SUB time.us.*"];
|
||||
sub3 [shape=box, style="rounded", label="SUB time.us.>"];
|
||||
|
||||
publisher -> subject [label="msg"];
|
||||
subject -> sub2 [style="invis"];
|
||||
subject -> sub1 [label="msg"];
|
||||
subject -> sub3 [label="msg"];
|
||||
}
|
||||
</code></div>
|
||||

|
||||
|
||||
### Monitoring and Wire Taps
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user