amqplib 0.4.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/Makefile +2 -1
  3. package/README.md +4 -4
  4. package/callback_api.js +1 -0
  5. package/channel_api.js +7 -6
  6. package/examples/headers.js +2 -2
  7. package/examples/receive_generator.js +39 -0
  8. package/examples/send_generators.js +42 -0
  9. package/examples/ssl.js +1 -1
  10. package/examples/tutorials/README.md +1 -1
  11. package/examples/tutorials/callback_api/emit_log.js +1 -1
  12. package/examples/tutorials/callback_api/emit_log_direct.js +1 -1
  13. package/examples/tutorials/callback_api/emit_log_topic.js +1 -1
  14. package/examples/tutorials/callback_api/new_task.js +1 -1
  15. package/examples/tutorials/callback_api/rpc_client.js +1 -1
  16. package/examples/tutorials/callback_api/rpc_server.js +1 -1
  17. package/examples/tutorials/callback_api/send.js +1 -1
  18. package/examples/tutorials/emit_log.js +4 -5
  19. package/examples/tutorials/emit_log_direct.js +4 -5
  20. package/examples/tutorials/emit_log_topic.js +4 -5
  21. package/examples/tutorials/new_task.js +5 -6
  22. package/examples/tutorials/package.json +2 -3
  23. package/examples/tutorials/receive.js +4 -4
  24. package/examples/tutorials/receive_logs.js +1 -1
  25. package/examples/tutorials/receive_logs_direct.js +2 -2
  26. package/examples/tutorials/receive_logs_topic.js +6 -6
  27. package/examples/tutorials/rpc_client.js +25 -26
  28. package/examples/tutorials/rpc_server.js +2 -2
  29. package/examples/tutorials/send.js +4 -5
  30. package/examples/tutorials/worker.js +1 -1
  31. package/examples/waitForConfirms.js +2 -2
  32. package/lib/api_args.js +2 -0
  33. package/lib/callback_model.js +11 -10
  34. package/lib/channel.js +24 -12
  35. package/lib/channel_model.js +57 -65
  36. package/lib/codec.js +64 -38
  37. package/lib/connect.js +26 -15
  38. package/lib/connection.js +6 -4
  39. package/lib/credentials.js +20 -3
  40. package/lib/defs.js +203 -75
  41. package/lib/frame.js +2 -1
  42. package/lib/heartbeat.js +1 -1
  43. package/package.json +10 -8
  44. package/test/callback_api.js +6 -5
  45. package/test/channel.js +125 -107
  46. package/test/channel_api.js +125 -136
  47. package/test/codec.js +48 -9
  48. package/test/connect.js +88 -3
  49. package/test/connection.js +57 -56
  50. package/test/data.js +32 -9
  51. package/test/frame.js +4 -4
  52. package/test/mux.js +10 -6
  53. package/test/util.js +35 -21
  54. package/.npmignore +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,93 @@
1
1
  # Change log for amqplib
2
2
 
3
+ ## Changes in v0.5.3
4
+
5
+ git log v0.5.2..v0.5.3
6
+
7
+ * Bump bitsyntax to remove some `Buffer` misuse deprecation notices
8
+ ([PR 480])(https://github.com/squaremo/amqp.node/pull/480)
9
+ * Test on node 11.1
10
+ ([PR 473])(https://github.com/squaremo/amqp.node/pull/464); thanks
11
+ @kibertoad
12
+ * Updated various dependencies
13
+ * Support queue mode during assertQueue
14
+ ([PR 464])(https://github.com/squaremo/amqp.node/pull/464); thanks
15
+ @JoeTheFkingFrypan
16
+ * Expose serverProperties in the connection object
17
+ ([PR 452])(https://github.com/squaremo/amqp.node/pull/452); thanks
18
+ @jfromaniello
19
+ * Test on Node 10
20
+ ([PR 454])(https://github.com/squaremo/amqp.node/pull/454); thanks
21
+ @kibertoad
22
+ * Support amqplain credentials
23
+ ([PR 451])(https://github.com/squaremo/amqp.node/pull/451); thanks
24
+ @jfromaniello
25
+ * Decorate channel errors with methodId and classId
26
+ ([PR 447])(https://github.com/squaremo/amqp.node/pull/447); thanks
27
+ @MitMaro
28
+ * Resolve issues caused by Node 10 `readable` changes
29
+ ([PR 442])(https://github.com/squaremo/amqp.node/pull/442)
30
+ * Bump uglify to 2.6.x and node to 9.1 due to nodejs/node#16781.
31
+ ([PR 439])(https://github.com/squaremo/amqp.node/pull/439)
32
+ * Updated README with more modern Buffer syntax
33
+ ([PR 438](https://github.com/squaremo/amqp.node/pull/438); thanks
34
+ @ravshansbox
35
+ * Support overflow option to assert queue
36
+ ([PR 436])(https://github.com/squaremo/amqp.node/pull/436); thanks
37
+ to @honestserpent
38
+ * Replace instances of keyword `await`
39
+ ([PR 396])(https://github.com/squaremo/amqp.node/pull/396),
40
+ as discussed in
41
+ [issue 235](https://github.com/squaremo/amqp.node/issues/235)
42
+ * Use 3rd party url for better decoding of username/password
43
+ ([PR 395])(https://github.com/squaremo/amqp.node/pull/395),
44
+ as discussed in
45
+ [issue 385](https://github.com/squaremo/amqp.node/issues/385))
46
+
47
+ ## Changes in v0.5.2
48
+
49
+ git log v0.5.1..v0.5.2
50
+
51
+ * Increase encoding buffer to accommodate large header values
52
+ ([PR 367](https://github.com/squaremo/amqp.node/pull/367))
53
+ * Bring code up to date with new Buffer interface
54
+ ([PR 350](https://github.com/squaremo/amqp.node/pull/350))
55
+ * Fix dangling connection problem
56
+ ([PR 340](https://github.com/squaremo/amqp.node/pull/340))
57
+ * Clear up URL credentials parsing
58
+ ([PR 330](https://github.com/squaremo/amqp.node/pull/330))
59
+ * Allow connection params to be suppied in object
60
+ ([PR 304](https://github.com/squaremo/amqp.node/pull/304))
61
+ * Support explicit numeric types in field tables (e.g., headers)
62
+ ([PR 389](https://github.com/squaremo/amqp.node/pull/389), from a
63
+ suggestion in
64
+ [issue 358](https://github.com/squaremo/amqp.node/issues/358))
65
+
66
+ Thank you to all contributors, of PRs, issues and comments.
67
+
68
+ ## Changes in v0.5.1
69
+
70
+ git log v0.5.0..v0.5.1
71
+
72
+ * Fix mistake in closeBecause
73
+ ([PR 298](https://github.com/squaremo/amqp.node/pull/298); thanks
74
+ to @lholznagel and others who reported the issue, and to @nfantone
75
+ for the rapid fix)
76
+
77
+ ## Changes in v0.5.0
78
+
79
+ git log v0.4.2..v0.5.0
80
+
81
+ * Port to use bluebird rather than when.js
82
+ ([PR 295](https://github.com/squaremo/amqp.node/pull/295); thanks
83
+ to @nfantone, and special mention to @myndzi for #158)
84
+ * Fixed a problem with using `channel.get` in the callback model
85
+ ([PR 283](https://github.com/squaremo/amqp.node/pull/283); good
86
+ catch, @shanksauce)
87
+ * Added an example that uses generators (thanks @rudijs)
88
+ * Fixed a link in the comments relating to heartbeats (thanks
89
+ @tapickell)
90
+
3
91
  ## Changes in v0.4.2
4
92
 
5
93
  git log v0.4.1..v0.4.2
package/Makefile CHANGED
@@ -2,7 +2,8 @@ RABBITMQ_SRC_VERSION=rabbitmq_v3_2_1
2
2
  JSON=amqp-rabbitmq-0.9.1.json
3
3
  RABBITMQ_CODEGEN=https://raw.githubusercontent.com/rabbitmq/rabbitmq-codegen
4
4
  AMQP_JSON=$(RABBITMQ_CODEGEN)/$(RABBITMQ_SRC_VERSION)/$(JSON)
5
- NODEJS_VERSIONS='0.8' '0.9' '0.10' '0.11' '0.12' '1.6' '2.5' '3.3' '4.2' '5.5' '6.2'
5
+
6
+ NODEJS_VERSIONS='0.8' '0.9' '0.10' '0.11' '0.12' '1.6' '2.5' '3.3' '4.2' '5.5' '6.2' '8.9' '9.11' '10.7' '11.1'
6
7
 
7
8
  MOCHA=./node_modules/.bin/mocha
8
9
  _MOCHA=./node_modules/.bin/_mocha
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  * [Examples from RabbitMQ tutorials][tutes]
11
11
 
12
12
  A library for making AMQP 0-9-1 clients for Node.JS, and an AMQP 0-9-1
13
- client for Node.JS v0.8-12, v4.0, and the intervening io.js
13
+ client for Node.JS v0.8-0.12, v4-v9, and the intervening io.js
14
14
  releases.
15
15
 
16
16
  This library does not implement [AMQP
@@ -21,6 +21,7 @@ Project status:
21
21
 
22
22
  - Expected to work
23
23
  - Complete high-level and low-level APIs (i.e., all bits of the protocol)
24
+ - Stable APIs
24
25
  - A fair few tests
25
26
  - Measured test coverage
26
27
  - Ports of the [RabbitMQ tutorials][rabbitmq-tutes] as [examples][tutes]
@@ -29,7 +30,6 @@ Project status:
29
30
  Still working on:
30
31
 
31
32
  - Getting to 100% (or very close to 100%) test coverage
32
- - Settling on completely stable APIs
33
33
 
34
34
  ## Callback API example
35
35
 
@@ -47,7 +47,7 @@ function publisher(conn) {
47
47
  function on_open(err, ch) {
48
48
  if (err != null) bail(err);
49
49
  ch.assertQueue(q);
50
- ch.sendToQueue(q, new Buffer('something to do'));
50
+ ch.sendToQueue(q, Buffer.from('something to do'));
51
51
  }
52
52
  }
53
53
 
@@ -86,7 +86,7 @@ open.then(function(conn) {
86
86
  return conn.createChannel();
87
87
  }).then(function(ch) {
88
88
  return ch.assertQueue(q).then(function(ok) {
89
- return ch.sendToQueue(q, new Buffer('something to do'));
89
+ return ch.sendToQueue(q, Buffer.from('something to do'));
90
90
  });
91
91
  }).catch(console.warn);
92
92
 
package/callback_api.js CHANGED
@@ -19,3 +19,4 @@ function connect(url, options, cb) {
19
19
 
20
20
  module.exports.connect = connect;
21
21
  module.exports.credentials = require('./lib/credentials');
22
+ module.exports.IllegalOperationError = require('./lib/error').IllegalOperationError;
package/channel_api.js CHANGED
@@ -1,15 +1,16 @@
1
1
  var raw_connect = require('./lib/connect').connect;
2
2
  var ChannelModel = require('./lib/channel_model').ChannelModel;
3
- var defer = require('when').defer;
3
+ var Promise = require('bluebird');
4
4
 
5
5
  function connect(url, connOptions) {
6
- var opened = defer();
7
- raw_connect(url, connOptions, function(err, conn) {
8
- if (err === null) opened.resolve(new ChannelModel(conn));
9
- else opened.reject(err);
6
+ return Promise.fromCallback(function(cb) {
7
+ return raw_connect(url, connOptions, cb);
8
+ })
9
+ .then(function(conn) {
10
+ return new ChannelModel(conn);
10
11
  });
11
- return opened.promise;
12
12
  };
13
13
 
14
14
  module.exports.connect = connect;
15
15
  module.exports.credentials = require('./lib/credentials');
16
+ module.exports.IllegalOperationError = require('./lib/error').IllegalOperationError;
@@ -37,6 +37,6 @@ function bindAndConsume(ch, ex, q) {
37
37
 
38
38
  function send(ch, ex) {
39
39
  // The headers for a message are given as an option to `publish`:
40
- ch.publish(ex.exchange, '', new Buffer('hello'), {headers: {baz: 'boo'}});
41
- ch.publish(ex.exchange, '', new Buffer('world'), {headers: {foo: 'bar'}});
40
+ ch.publish(ex.exchange, '', Buffer.from('hello'), {headers: {baz: 'boo'}});
41
+ ch.publish(ex.exchange, '', Buffer.from('world'), {headers: {foo: 'bar'}});
42
42
  }
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+ const co = require('co');
5
+ const amqp = require('amqplib');
6
+ const readline = require('readline');
7
+
8
+ co(function* () {
9
+ const myConsumer = (msg) => {
10
+ if (msg !== null) {
11
+ console.log('consuming message %s in generator', JSON.stringify(msg.content.toString()));
12
+ }
13
+ };
14
+ const conn = yield amqp.connect('amqp://localhost');
15
+ try {
16
+ // create a message to consume
17
+ const q = 'hello';
18
+ const msg = 'Hello World!';
19
+ const channel = yield conn.createChannel();
20
+ yield channel.assertQueue(q);
21
+ channel.sendToQueue(q, Buffer.from(msg));
22
+ console.log(" [x] Sent '%s'", msg);
23
+ // consume the message
24
+ yield channel.consume(q, myConsumer, { noAck: true });
25
+ }
26
+ catch (e) {
27
+ throw e;
28
+ }
29
+ }).catch(err => {
30
+ console.warn('Error:', err);
31
+ });
32
+
33
+ const rl = readline.createInterface({
34
+ input: process.stdin,
35
+ output: process.stdout
36
+ });
37
+
38
+ // pend until message is consumed
39
+ rl.question('newline to exit', () => process.exit());
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ // NB this requires the module 'co':
6
+ // npm install co
7
+ const co = require('co');
8
+ const amqp = require('amqplib');
9
+
10
+ co(function* () {
11
+ // connection errors are handled in the co .catch handler
12
+ const conn = yield amqp.connect('amqp://localhost');
13
+
14
+ // try catch will throw any errors from the yielding the following promises to the co .catch handler
15
+ try {
16
+ const q = 'hello';
17
+ const msg = 'Hello World!';
18
+
19
+ // use a confirm channel so we can check the message is sent OK.
20
+ const channel = yield conn.createConfirmChannel();
21
+
22
+ yield channel.assertQueue(q);
23
+
24
+ channel.sendToQueue(q, Buffer.from(msg));
25
+
26
+ // if message has been nacked, this will result in an error (rejected promise);
27
+ yield channel.waitForConfirms();
28
+
29
+ console.log(" [x] Sent '%s'", msg);
30
+
31
+ channel.close();
32
+ }
33
+ catch (e) {
34
+ throw e;
35
+ }
36
+ finally {
37
+ conn.close();
38
+ }
39
+
40
+ }).catch(err => {
41
+ console.warn('Error:', err);
42
+ });
package/examples/ssl.js CHANGED
@@ -59,6 +59,6 @@ var open = amqp.connect('amqps://localhost', opts);
59
59
  open.then(function(conn) {
60
60
  process.on('SIGINT', conn.close.bind(conn));
61
61
  return conn.createChannel().then(function(ch) {
62
- ch.sendToQueue('foo', new Buffer('Hello World!'));
62
+ ch.sendToQueue('foo', Buffer.from('Hello World!'));
63
63
  });
64
64
  }).then(null, console.warn);
@@ -9,7 +9,7 @@ of the tutorial programs to the callback-oriented API.
9
9
  To run the tutorial code, you need amqplib installed. Assuming you are
10
10
  in a clone of the amqplib repository, from the tutorials directory:
11
11
 
12
- npm install ../..
12
+ npm install
13
13
 
14
14
  or to use the latest released version,
15
15
 
@@ -17,7 +17,7 @@ function on_connect(err, conn) {
17
17
  ch.assertExchange(ex, 'fanout', {durable: false});
18
18
  var msg = process.argv.slice(2).join(' ') ||
19
19
  'info: Hello World!';
20
- ch.publish(ex, '', new Buffer(msg));
20
+ ch.publish(ex, '', Buffer.from(msg));
21
21
  console.log(" [x] Sent '%s'", msg);
22
22
  ch.close(function() { conn.close(); });
23
23
  }
@@ -20,7 +20,7 @@ function on_connect(err, conn) {
20
20
  function on_channel_open(err, ch) {
21
21
  if (err !== null) return bail(err, conn);
22
22
  ch.assertExchange(ex, 'direct', exopts, function(err, ok) {
23
- ch.publish(ex, severity, new Buffer(message));
23
+ ch.publish(ex, severity, Buffer.from(message));
24
24
  ch.close(function() { conn.close(); });
25
25
  });
26
26
  }
@@ -17,7 +17,7 @@ function on_connect(err, conn) {
17
17
  conn.createChannel(function(err, ch) {
18
18
  ch.assertExchange(ex, 'topic', exopts, function(err, ok) {
19
19
  if (err !== null) return bail(err, conn);
20
- ch.publish(ex, key, new Buffer(message));
20
+ ch.publish(ex, key, Buffer.from(message));
21
21
  console.log(" [x] Sent %s:'%s'", key, message);
22
22
  ch.close(function() { conn.close(); });
23
23
  });
@@ -17,7 +17,7 @@ function on_connect(err, conn) {
17
17
  ch.assertQueue(q, {durable: true}, function(err, _ok) {
18
18
  if (err !== null) return bail(err, conn);
19
19
  var msg = process.argv.slice(2).join(' ') || "Hello World!";
20
- ch.sendToQueue(q, new Buffer(msg), {persistent: true});
20
+ ch.sendToQueue(q, Buffer.from(msg), {persistent: true});
21
21
  console.log(" [x] Sent '%s'", msg);
22
22
  ch.close(function() { conn.close(); });
23
23
  });
@@ -39,7 +39,7 @@ function on_connect(err, conn) {
39
39
  var queue = ok.queue;
40
40
  ch.consume(queue, maybeAnswer, {noAck:true});
41
41
  console.log(' [x] Requesting fib(%d)', n);
42
- ch.sendToQueue('rpc_queue', new Buffer(n.toString()), {
42
+ ch.sendToQueue('rpc_queue', Buffer.from(n.toString()), {
43
43
  replyTo: queue, correlationId: correlationId
44
44
  });
45
45
  });
@@ -35,7 +35,7 @@ function on_connect(err, conn) {
35
35
  var n = parseInt(msg.content.toString());
36
36
  console.log(' [.] fib(%d)', n);
37
37
  ch.sendToQueue(msg.properties.replyTo,
38
- new Buffer(fib(n).toString()),
38
+ Buffer.from(fib(n).toString()),
39
39
  {correlationId: msg.properties.correlationId});
40
40
  ch.ack(msg);
41
41
  }
@@ -17,7 +17,7 @@ function on_connect(err, conn) {
17
17
  if (err !== null) return bail(err, conn);
18
18
  ch.assertQueue(q, {durable: false}, function(err, ok) {
19
19
  if (err !== null) return bail(err, conn);
20
- ch.sendToQueue(q, new Buffer(msg));
20
+ ch.sendToQueue(q, Buffer.from(msg));
21
21
  console.log(" [x] Sent '%s'", msg);
22
22
  ch.close(function() { conn.close(); });
23
23
  });
@@ -1,10 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  var amqp = require('amqplib');
4
- var when = require('when');
5
4
 
6
5
  amqp.connect('amqp://localhost').then(function(conn) {
7
- return when(conn.createChannel().then(function(ch) {
6
+ return conn.createChannel().then(function(ch) {
8
7
  var ex = 'logs';
9
8
  var ok = ch.assertExchange(ex, 'fanout', {durable: false})
10
9
 
@@ -12,9 +11,9 @@ amqp.connect('amqp://localhost').then(function(conn) {
12
11
  'info: Hello World!';
13
12
 
14
13
  return ok.then(function() {
15
- ch.publish(ex, '', new Buffer(message));
14
+ ch.publish(ex, '', Buffer.from(message));
16
15
  console.log(" [x] Sent '%s'", message);
17
16
  return ch.close();
18
17
  });
19
- })).ensure(function() { conn.close(); });
20
- }).then(null, console.warn);
18
+ }).finally(function() { conn.close(); });
19
+ }).catch(console.warn);
@@ -1,21 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  var amqp = require('amqplib');
4
- var when = require('when');
5
4
 
6
5
  var args = process.argv.slice(2);
7
6
  var severity = (args.length > 0) ? args[0] : 'info';
8
7
  var message = args.slice(1).join(' ') || 'Hello World!';
9
8
 
10
9
  amqp.connect('amqp://localhost').then(function(conn) {
11
- return when(conn.createChannel().then(function(ch) {
10
+ return conn.createChannel().then(function(ch) {
12
11
  var ex = 'direct_logs';
13
12
  var ok = ch.assertExchange(ex, 'direct', {durable: false});
14
13
 
15
14
  return ok.then(function() {
16
- ch.publish(ex, severity, new Buffer(message));
15
+ ch.publish(ex, severity, Buffer.from(message));
17
16
  console.log(" [x] Sent %s:'%s'", severity, message);
18
17
  return ch.close();
19
18
  });
20
- })).ensure(function() { conn.close(); });
21
- }).then(null, console.warn);
19
+ }).finally(function() { conn.close(); });
20
+ }).catch(console.warn);
@@ -1,20 +1,19 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  var amqp = require('amqplib');
4
- var when = require('when');
5
4
 
6
5
  var args = process.argv.slice(2);
7
6
  var key = (args.length > 0) ? args[0] : 'info';
8
7
  var message = args.slice(1).join(' ') || 'Hello World!';
9
8
 
10
9
  amqp.connect('amqp://localhost').then(function(conn) {
11
- return when(conn.createChannel().then(function(ch) {
10
+ return conn.createChannel().then(function(ch) {
12
11
  var ex = 'topic_logs';
13
12
  var ok = ch.assertExchange(ex, 'topic', {durable: false});
14
13
  return ok.then(function() {
15
- ch.publish(ex, key, new Buffer(message));
14
+ ch.publish(ex, key, Buffer.from(message));
16
15
  console.log(" [x] Sent %s:'%s'", key, message);
17
16
  return ch.close();
18
17
  });
19
- })).ensure(function() { conn.close(); })
20
- }).then(null, console.log);
18
+ }).finally(function() { conn.close(); })
19
+ }).catch(console.log);
@@ -2,18 +2,17 @@
2
2
  // Post a new task to the work queue
3
3
 
4
4
  var amqp = require('amqplib');
5
- var when = require('when');
6
5
 
7
6
  amqp.connect('amqp://localhost').then(function(conn) {
8
- return when(conn.createChannel().then(function(ch) {
7
+ return conn.createChannel().then(function(ch) {
9
8
  var q = 'task_queue';
10
9
  var ok = ch.assertQueue(q, {durable: true});
11
-
10
+
12
11
  return ok.then(function() {
13
12
  var msg = process.argv.slice(2).join(' ') || "Hello World!";
14
- ch.sendToQueue(q, new Buffer(msg), {deliveryMode: true});
13
+ ch.sendToQueue(q, Buffer.from(msg), {deliveryMode: true});
15
14
  console.log(" [x] Sent '%s'", msg);
16
15
  return ch.close();
17
16
  });
18
- })).ensure(function() { conn.close(); });
19
- }).then(null, console.warn);
17
+ }).finally(function() { conn.close(); });
18
+ }).catch(console.warn);
@@ -4,9 +4,8 @@
4
4
  "description": "The RabbitMQ tutorials, ported to amqplib",
5
5
  "main": "send.js",
6
6
  "dependencies": {
7
- "amqplib": "",
8
- "when": "",
9
- "node-uuid": ""
7
+ "amqplib": "../..",
8
+ "node-uuid": "*"
10
9
  },
11
10
  "scripts": {
12
11
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -5,17 +5,17 @@ var amqp = require('amqplib');
5
5
  amqp.connect('amqp://localhost').then(function(conn) {
6
6
  process.once('SIGINT', function() { conn.close(); });
7
7
  return conn.createChannel().then(function(ch) {
8
-
8
+
9
9
  var ok = ch.assertQueue('hello', {durable: false});
10
-
10
+
11
11
  ok = ok.then(function(_qok) {
12
12
  return ch.consume('hello', function(msg) {
13
13
  console.log(" [x] Received '%s'", msg.content.toString());
14
14
  }, {noAck: true});
15
15
  });
16
-
16
+
17
17
  return ok.then(function(_consumeOk) {
18
18
  console.log(' [*] Waiting for messages. To exit press CTRL+C');
19
19
  });
20
20
  });
21
- }).then(null, console.warn);
21
+ }).catch(console.warn);
@@ -25,4 +25,4 @@ amqp.connect('amqp://localhost').then(function(conn) {
25
25
  console.log(" [x] '%s'", msg.content.toString());
26
26
  }
27
27
  });
28
- }).then(null, console.warn);
28
+ }).catch(console.warn);
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  var amqp = require('amqplib');
4
- var all = require('when').all;
4
+ var all = require('bluebird').all;
5
5
  var basename = require('path').basename;
6
6
 
7
7
  var severities = process.argv.slice(2);
@@ -42,4 +42,4 @@ amqp.connect('amqp://localhost').then(function(conn) {
42
42
  msg.content.toString());
43
43
  }
44
44
  });
45
- }).then(null, console.warn);
45
+ }).catch(console.warn);
@@ -2,7 +2,7 @@
2
2
 
3
3
  var amqp = require('amqplib');
4
4
  var basename = require('path').basename;
5
- var all = require('when').all;
5
+ var all = require('bluebird').all;
6
6
 
7
7
  var keys = process.argv.slice(2);
8
8
  if (keys.length < 1) {
@@ -16,29 +16,29 @@ amqp.connect('amqp://localhost').then(function(conn) {
16
16
  return conn.createChannel().then(function(ch) {
17
17
  var ex = 'topic_logs';
18
18
  var ok = ch.assertExchange(ex, 'topic', {durable: false});
19
-
19
+
20
20
  ok = ok.then(function() {
21
21
  return ch.assertQueue('', {exclusive: true});
22
22
  });
23
-
23
+
24
24
  ok = ok.then(function(qok) {
25
25
  var queue = qok.queue;
26
26
  return all(keys.map(function(rk) {
27
27
  ch.bindQueue(queue, ex, rk);
28
28
  })).then(function() { return queue; });
29
29
  });
30
-
30
+
31
31
  ok = ok.then(function(queue) {
32
32
  return ch.consume(queue, logMessage, {noAck: true});
33
33
  });
34
34
  return ok.then(function() {
35
35
  console.log(' [*] Waiting for logs. To exit press CTRL+C.');
36
36
  });
37
-
37
+
38
38
  function logMessage(msg) {
39
39
  console.log(" [x] %s:'%s'",
40
40
  msg.fields.routingKey,
41
41
  msg.content.toString());
42
42
  }
43
43
  });
44
- }).then(null, console.warn);
44
+ }).catch(console.warn);
@@ -2,8 +2,7 @@
2
2
 
3
3
  var amqp = require('amqplib');
4
4
  var basename = require('path').basename;
5
- var when = require('when');
6
- var defer = when.defer;
5
+ var Promise = require('bluebird');
7
6
  var uuid = require('node-uuid');
8
7
 
9
8
  // I've departed from the form of the original RPC tutorial, which
@@ -22,33 +21,33 @@ catch (e) {
22
21
  }
23
22
 
24
23
  amqp.connect('amqp://localhost').then(function(conn) {
25
- return when(conn.createChannel().then(function(ch) {
26
- var answer = defer();
27
- var corrId = uuid();
28
- function maybeAnswer(msg) {
29
- if (msg.properties.correlationId === corrId) {
30
- answer.resolve(msg.content.toString());
24
+ return conn.createChannel().then(function(ch) {
25
+ return new Promise(function(resolve) {
26
+ var corrId = uuid();
27
+ function maybeAnswer(msg) {
28
+ if (msg.properties.correlationId === corrId) {
29
+ resolve(msg.content.toString());
30
+ }
31
31
  }
32
- }
33
32
 
34
- var ok = ch.assertQueue('', {exclusive: true})
35
- .then(function(qok) { return qok.queue; });
33
+ var ok = ch.assertQueue('', {exclusive: true})
34
+ .then(function(qok) { return qok.queue; });
36
35
 
37
- ok = ok.then(function(queue) {
38
- return ch.consume(queue, maybeAnswer, {noAck: true})
39
- .then(function() { return queue; });
40
- });
41
-
42
- ok = ok.then(function(queue) {
43
- console.log(' [x] Requesting fib(%d)', n);
44
- ch.sendToQueue('rpc_queue', new Buffer(n.toString()), {
45
- correlationId: corrId, replyTo: queue
36
+ ok = ok.then(function(queue) {
37
+ return ch.consume(queue, maybeAnswer, {noAck: true})
38
+ .then(function() { return queue; });
46
39
  });
47
- return answer.promise;
48
- });
49
40
 
50
- return ok.then(function(fibN) {
51
- console.log(' [.] Got %d', fibN);
41
+ ok = ok.then(function(queue) {
42
+ console.log(' [x] Requesting fib(%d)', n);
43
+ ch.sendToQueue('rpc_queue', Buffer.from(n.toString()), {
44
+ correlationId: corrId, replyTo: queue
45
+ });
46
+ });
52
47
  });
53
- })).ensure(function() { conn.close(); });
54
- }).then(null, console.warn);
48
+ })
49
+ .then(function(fibN) {
50
+ console.log(' [.] Got %d', fibN);
51
+ })
52
+ .finally(function() { conn.close(); });
53
+ }).catch(console.warn);
@@ -31,9 +31,9 @@ amqp.connect('amqp://localhost').then(function(conn) {
31
31
  console.log(' [.] fib(%d)', n);
32
32
  var response = fib(n);
33
33
  ch.sendToQueue(msg.properties.replyTo,
34
- new Buffer(response.toString()),
34
+ Buffer.from(response.toString()),
35
35
  {correlationId: msg.properties.correlationId});
36
36
  ch.ack(msg);
37
37
  }
38
38
  });
39
- }).then(null, console.warn);
39
+ }).catch(console.warn);