Skip to content

Commit a0d65d9

Browse files
committed
Revert "Resumable SUB sockets"
This reverts commit 8cabba0. Conflicts: README.md lib/sockets.js
1 parent 1698f8c commit a0d65d9

2 files changed

Lines changed: 16 additions & 78 deletions

File tree

README.md

Lines changed: 13 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ pub.connect('alerts');
7171
sub.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-
8174
Sockets are [Streams][nodejs-stream] in object mode, with buffers as
8275
the objects. In particular, you can `#read()` buffers from those that
8376
are readable (or supply a callback for the `'data'` event, if you are
@@ -101,8 +94,6 @@ stream, making relaying simple:
10194
sub.pipe(process.stdout);
10295
```
10396

104-
#### Connecting sockets
105-
10697
A socket may be connected more than once, by calling
10798
`socket.connect(x)` with different `x`s. What this entails depends on
10899
the 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
223214
pub.setsockopt('expiration', 60 * 1000)
@@ -233,8 +224,6 @@ You need to be careful when using expiry with a **WORKER**, **REQ** or
233224
sending one request at a time, and giving requests a time limit, may
234225
help.
235226

236-
##### `prefetch`
237-
238227
The option `'prefetch'`, determines how many messages RabbitMQ will
239228
send to the socket before waiting for some to be processed. This only
240229
has 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
255244
constraint and just send what it has, when it has it. The default
256245
value is `0`.
257246

258-
##### `persistent`
259-
260247
The option `'persistent'` governs the lifetime of messages. Setting it
261248
to `true` means RabbitMQ will keep messages over restarts, by writing
262249
them 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
268255
persistent, but replies never are; in other words, `'persistent'`
269256
applies 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

275261
Setting this option to `false` using `#setsockopt` means that the
276262
messages following will not survive restarts, and any connections made
@@ -280,36 +266,6 @@ meantime.
280266

281267
See 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

315271
A 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
414370
as given to `#connect`.
415371

416372
PUSH, 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
421377
are requesting via AMQP or STOMP, at least supply a `replyTo`, and
422378
consider supplying a `correlationId`.
423379

424380
The option `'persistent'` relates both to the `durable` property of
425381
queues and to the `deliveryMode` property given to messages. If a
426382
socket 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/

lib/sockets.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,11 @@ function SubSocket(channel, opts) {
192192

193193
this.subs = [], this.patterns = [];
194194
var self = this;
195-
var queue = '', qopts = {exclusive: true, autoDelete: true};
196-
if (opts && opts.resume_name !== undefined) {
197-
queue = opts.resume_name;
198-
qopts = {durable: true,
199-
expires: opts.resume_grace_period || 5 * 60 * 1000};
200-
}
201195

202196
var setup = channel.then(function(ch) {
203-
return ch.assertQueue(queue, qopts).then(function(ok) {
197+
return ch.assertQueue('', {
198+
exclusive: true, autoDelete: true
199+
}).then(function(ok) {
204200
self.queue = ok.queue; // for inspection
205201
return ch.consume(ok.queue, function(msg) {
206202
// if msg is null, this indicates a cancel, i.e., end of

0 commit comments

Comments
 (0)