@@ -71,13 +71,6 @@ pub.connect('alerts');
7171sub .connect (' alerts' );
7272```
7373
74- ` Context#socket ` can take a second argument, which is an object
75- containing options to set on the socket at its creation.
76-
77- ``` js
78- var worker = context .socket (' WORKER' , {persistent: true });
79- ```
80-
8174Sockets are [ Streams] [ nodejs-stream ] in object mode, with buffers as
8275the objects. In particular, you can ` #read() ` buffers from those that
8376are readable (or supply a callback for the ` 'data' ` event, if you are
@@ -101,8 +94,6 @@ stream, making relaying simple:
10194sub .pipe (process .stdout );
10295```
10396
104- #### Connecting sockets
105-
10697A socket may be connected more than once, by calling
10798` socket.connect(x) ` with different ` x ` s. What this entails depends on
10899the socket type (see below). Messages to and from different
@@ -216,8 +207,8 @@ subsequent messages sent using `#write`.
216207
217208##### ` expiration `
218209
219- The option ` 'expiration' ` may be set at any time on writable sockets,
220- i.e., PUB, PUSH, REQ and REP. It is given as a number of milliseconds:
210+ The option ` 'expiration' ` may be set on writable sockets, i.e., PUB ,
211+ PUSH, REQ and REP. It is given as a number of milliseconds:
221212
222213``` js
223214pub .setsockopt (' expiration' , 60 * 1000 )
@@ -233,8 +224,6 @@ You need to be careful when using expiry with a **WORKER**, **REQ** or
233224sending one request at a time, and giving requests a time limit, may
234225help.
235226
236- ##### ` prefetch `
237-
238227The option ` 'prefetch' ` , determines how many messages RabbitMQ will
239228send to the socket before waiting for some to be processed. This only
240229has a noticable effect for ** WORKER** and ** REP** sockets. It is best
@@ -255,8 +244,6 @@ If you set it to `0`, RabbitMQ will forget any such
255244constraint and just send what it has, when it has it. The default
256245value is ` 0 ` .
257246
258- ##### ` persistent `
259-
260247The option ` 'persistent' ` governs the lifetime of messages. Setting it
261248to ` true ` means RabbitMQ will keep messages over restarts, by writing
262249them to disk. This is an option for all sockets, and crucially,
@@ -268,9 +255,8 @@ In the case of **REQ** and **REP** sockets, the requests may be
268255persistent, but replies never are; in other words, ` 'persistent' `
269256applies only to requests.
270257
271- In the case of ** SUB** and ** PUB** sockets, ` 'persistent' ` only has
272- effect if the ** SUB** socket is resumable (see the option
273- ` 'resume_name' ` below).
258+ In the case of ** SUB** and ** PUB** sockets, ` 'persistent' ` currently
259+ has no effect, but they may nonetheless have the option set.
274260
275261Setting this option to ` false ` using ` #setsockopt ` means that the
276262messages following will not survive restarts, and any connections made
@@ -280,36 +266,6 @@ meantime.
280266
281267See below for what ` 'persistent' ` means in AMQP terms.
282268
283- ##### ` resume_name ` and ` resume_grace_period `
284-
285- Using these options when creating a ** SUB** socket to keep messages
286- accumulating after the socket is closed, so another socket can resume
287- reading from where it left off.
288-
289- The socket must be given a ` 'resume_name' ` which is used to identify
290- the connections and messages kept. Successive sockets using the same
291- ` 'resume_name' ` will receive any messages sent in the meantime. If the
292- socket is persistent, the connections and messages will survive
293- restarts.
294-
295- ` 'resume_grace_period' ` , in milliseconds, is the minimum time that the
296- connections and messages will be kept while there is no socket using
297- them. After that time, the connections may be cleaned up, losing any
298- messages. If not supplied, it defaults to five minutes.
299-
300- ``` js
301- var sub = context .socket (' SUB' , {resume_name: ' subs.abc123' });
302- sub .connect (' events' );
303- // ...
304- sub .close ();
305- // ... messages are sent to 'events'
306- var sub2 = context .socket (' SUB' , {resume_name: ' subs.abc123' });
307- // sub2 will be connected to 'events', and have the messages
308- // sent after sub was closed.
309- ```
310-
311- See below for what ` 'resume_*' ` mean in AMQP terms.
312-
313269## Using with servers
314270
315271A few modules have a socket-server-like abstraction; canonically, the
@@ -414,35 +370,21 @@ To send to SUB sockets or receive from PUB sockets, publish or bind
414370as given to ` #connect ` .
415371
416372PUSH, PULL, REQ and REP sockets use non-exclusive queues named for the
417- argument given to ` # connect` . If you are replying via AMQP or STOMP,
418- be sure to follow the convention of sending the response to the queue
419- given in the ` replyTo ` property of the request message, and copying
420- the ` correlationId ` property from the request in the reply. If you
373+ argument given to ` connect ` . If you are replying via AMQP or STOMP, be
374+ sure to follow the convention of sending the response to the queue
375+ given in the ` ' replyTo' ` property of the request message, and copying
376+ the ` ' correlationId' ` property from the request in the reply. If you
421377are requesting via AMQP or STOMP, at least supply a ` replyTo ` , and
422378consider supplying a ` correlationId ` .
423379
424380The option ` 'persistent' ` relates both to the ` durable ` property of
425381queues and to the ` deliveryMode ` property given to messages. If a
426382socket is ` persistent ` , it will declare queues as ` durable ` , and send
427- messages with ` deliveryMode ` of ` 2 ` .
428-
429- The exceptions are SUB sockets, which won't declare their subscription
430- queue as durable unless they are persistent ** and** resumable,
431- although PUB sockets are allowed to publish persistent
432- (` deliveryMode=2 ` ) messages; and REQ sockets, which ** do** declare the
433- request queue (that they send to) as durable, but not their own reply
434- queue.
435-
436- The option ` 'resume_name' ` changes the nature of the queue declared by
437- a SUB socket: instead of being auto-delete and exclusive (to the
438- connection), and getting a server-generated random name, it is given
439- the name ` 'resume_name' ` and is not auto-delete or exclusive, so it
440- survives the channel closing and the AMQP connection
441- dropping.
442-
443- ` 'resume_grace_period' ` corresponds to the queue property ` x-expires ` ,
444- a RabbitMQ extension (available since v2.0.0).
445-
383+ messages with ` deliveryMode ` of ` 2 ` . The exceptions are SUB sockets,
384+ which don't declare their subscription queue as durable, although PUB
385+ sockets are allowed to publish persistent (` deliveryMode=2 ` ) messages;
386+ and REQ sockets, which ** do** declare the request queue (that they
387+ send to) as durable, but not their own reply queue.
446388
447389[ amqplib ] : https://github.com/squaremo/amqp.node/
448390[ node-amqp ] : https://github.com/postwait/node-amqp/
0 commit comments