@@ -11,7 +11,6 @@ var context = require('rabbit.js').createContext();
1111context .on (' ready' , function () {
1212 var pub = context .socket (' PUB' ), sub = context .socket (' SUB' );
1313 sub .pipe (process .stdout );
14- sub .subscribe (' ' );
1514 sub .connect (' events' , function () {
1615 pub .connect (' events' , function () {
1716 pub .write (JSON .stringify ({welcome: ' rabbit.js' }), ' utf8' );
@@ -140,9 +139,9 @@ described below.
140139connected to <x > gets messages sent by a PUB socket connected to <x >;
141140a PUB socket sends every message to each of its connections. SUB
142141sockets are readable only, and PUB sockets are writable only. The
143- messages actually received are determined by the subscriptions of the
144- SUB socket and the topic used by the PUB socket -- see "Subscriptions"
145- below.
142+ messages actually received are determined by the parameters with which
143+ the SUB socket is connected, and the topic used by the PUB socket --
144+ see "Topics" below.
146145
147146** PUSH** / ** PULL** : a PUSH socket will send each message to a
148147single connection, using round-robin. A PULL socket will receive a
@@ -167,36 +166,37 @@ unacknowledged message, and must be called once only for each message.
167166A way to maintain ordering for REP and WORKER sockets is shown in the
168167[ "ordering" example] [ ordering-example ] .
169168
170- #### Subscriptions
169+ #### Topics and topic patterns
171170
172171** PUB** and ** SUB** sockets have an extra feature: the messages sent
173- by a PUB socket are routed to SUB sockets according to a topic given
174- by the PUB socket, and topic patterns given by the SUB socket.
172+ by a PUB socket are routed to SUB sockets according to a topic given
173+ by the PUB socket, and topic patterns given by the SUB socket.
175174
176175A PUB socket may set its ` 'topic' ` using `#setsockopt('topic',
177176string)` . All messages sent with ` #write` will use that
178177topic. Alternatively, you can use `#publish(topic, message,
179- [ encoding] )` to given the topic per message.
178+ [ encoding] )` to give the topic per message.
180179
181- A SUB socket must call ` #subscribe(string) ` ** at least once** to
182- receive messages. The argument is a pattern that is matched against
183- message topics; how the matching is done depends on the ` 'routing' `
184- option given to the sockets (they must agree on the value):
180+ A SUB socket may pass in an additional parameter, in the second
181+ position, to ` #connect ` . This extra argument is a pattern that is
182+ matched against message topics; how the matching is done depends on
183+ the ` 'routing' ` option given to the sockets (they must agree on the
184+ value):
185185
186186 - ` 'fanout' ` is the default and means all messages go to all SUB
187- sockets, regardless of the topic or subscription .
188- - ` 'direct' ` means that message topics are matched with subscriptions
187+ sockets, regardless of the topic or topic pattern .
188+ - ` 'direct' ` means that message topics are matched with patterns
189189 using string equality.
190- - ` 'topic' ` uses AMQP's wildcard matching; briefly, a topic consists
191- of ` '.' ` -delimited words, and a pattern is the same but contain
192- wilcards , ` '*' ` meaning "any single word" and ` '#' ` meaning "any
190+ - ` 'topic' ` uses AMQP's wildcard matching: briefly, a topic consists
191+ of ` '.' ` -delimited words, and a pattern is the same but may contain
192+ wildcards , ` '*' ` meaning "any single word" and ` '#' ` meaning "any
193193 sequence of words". So, the pattern ` "*.bar.#" ` will match the
194194 topic ` foo.bar.baz.bam" ` . There's a longer explanation in the
195195 RabbitMQ [ tutorial on topic matching] [ rabbitmq-topic-tute ] .
196196
197- Leaving all the options alone, all SUB sockets connected to X will get
198- all messages sent by PUB sockets connected to X, provided
199- ` #subscribe() ` is called on each SUB socket .
197+ Leaving all the options alone, and using only the two-argument version
198+ of ` #connect ` , all SUB sockets connected to X will get all messages
199+ sent by PUB sockets connected to X .
200200
201201#### Socket options
202202
@@ -207,12 +207,12 @@ the second argument to `Context#socket`.
207207##### ` routing ` and ` topic `
208208
209209` routing ` is supplied to a ** PUB** or ** SUB** socket on creation, and
210- determines the kind of patterns it will use to match messages to
211- subscriptions . Sockets connected to the same address must agree on the
212- routing.
210+ determines how it will match topics to topic patterns, as described
211+ under "Topics" . Sockets connected to the same address must agree on
212+ the routing.
213213
214- ` topic ` may be set on a ** PUB** socket to give the topic for messages
215- sent using ` #write ` .
214+ ` topic ` may be set on a ** PUB** socket to give the topic for
215+ subsequent messages sent using ` #write ` .
216216
217217##### ` expiration `
218218
@@ -405,9 +405,9 @@ rabbit.js makes some simplifying assumptions that must be kept in mind
405405when integrating with other protocols that RabbitMQ supports.
406406
407407PUB and SUB sockets declare exchanges named for the argument given to
408- ` #connect ` . The exchange is durable if the PUB or SUB socket is marked
409- ` persistent ` , so that bindings will survive if the subscription queue
410- does, and ` autoDelete ` , so it doesn't survive otherwise .
408+ ` #connect ` and with the type given by the ` 'routing' ` option. If a
409+ ` topic ` argument is given to ` #connect ` , it's used as the routing key
410+ pattern, otherwise ` '' ` is used .
411411
412412To send to SUB sockets or receive from PUB sockets, publish or bind
413413(or subscribe in the case of STOMP) to the exchange with the same name
0 commit comments