amqplib 0.10.8 → 1.0.0

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 (85) hide show
  1. package/.claude/commands/lint-disable.md +9 -0
  2. package/.claude/commands/lint-enable.md +12 -0
  3. package/.claude/settings.local.json +16 -0
  4. package/.github/workflows/publish.yml +1 -1
  5. package/.github/workflows/test.yml +1 -1
  6. package/CHANGELOG.md +34 -0
  7. package/CLAUDE.md +12 -0
  8. package/Makefile +5 -12
  9. package/bin/generate-defs.js +382 -369
  10. package/biome.json +51 -0
  11. package/callback_api.js +12 -8
  12. package/channel_api.js +5 -10
  13. package/examples/direct_reply_to_client.js +9 -5
  14. package/examples/direct_reply_to_server.js +8 -6
  15. package/examples/headers.js +13 -10
  16. package/examples/receive_generator.js +13 -20
  17. package/examples/send_generators.js +2 -9
  18. package/examples/ssl.js +2 -3
  19. package/examples/stream_queues/receive_stream.js +39 -36
  20. package/examples/stream_queues/send_stream.js +26 -29
  21. package/examples/tutorials/callback_api/emit_log.js +4 -3
  22. package/examples/tutorials/callback_api/emit_log_direct.js +5 -4
  23. package/examples/tutorials/callback_api/emit_log_topic.js +5 -4
  24. package/examples/tutorials/callback_api/new_task.js +5 -4
  25. package/examples/tutorials/callback_api/receive.js +16 -10
  26. package/examples/tutorials/callback_api/receive_logs.js +17 -11
  27. package/examples/tutorials/callback_api/receive_logs_direct.js +19 -13
  28. package/examples/tutorials/callback_api/receive_logs_topic.js +19 -14
  29. package/examples/tutorials/callback_api/rpc_client.js +20 -16
  30. package/examples/tutorials/callback_api/rpc_server.js +27 -21
  31. package/examples/tutorials/callback_api/send.js +4 -3
  32. package/examples/tutorials/callback_api/worker.js +18 -13
  33. package/examples/tutorials/emit_log.js +4 -6
  34. package/examples/tutorials/emit_log_direct.js +5 -7
  35. package/examples/tutorials/emit_log_topic.js +5 -7
  36. package/examples/tutorials/new_task.js +4 -6
  37. package/examples/tutorials/receive.js +8 -4
  38. package/examples/tutorials/receive_logs.js +10 -6
  39. package/examples/tutorials/receive_logs_direct.js +16 -10
  40. package/examples/tutorials/receive_logs_topic.js +16 -11
  41. package/examples/tutorials/rpc_client.js +17 -15
  42. package/examples/tutorials/rpc_server.js +9 -8
  43. package/examples/tutorials/send.js +4 -6
  44. package/examples/tutorials/worker.js +17 -14
  45. package/examples/waitForConfirms.js +2 -2
  46. package/lefthook.yml +14 -0
  47. package/lib/api_args.js +124 -149
  48. package/lib/bitset.js +28 -18
  49. package/lib/callback_model.js +134 -190
  50. package/lib/channel.js +175 -213
  51. package/lib/channel_model.js +41 -85
  52. package/lib/codec.js +257 -228
  53. package/lib/connect.js +74 -82
  54. package/lib/connection.js +204 -240
  55. package/lib/credentials.js +21 -29
  56. package/lib/defs.js +2559 -1927
  57. package/lib/error.js +5 -6
  58. package/lib/format.js +15 -33
  59. package/lib/frame.js +66 -66
  60. package/lib/heartbeat.js +17 -24
  61. package/lib/mux.js +32 -41
  62. package/package.json +8 -5
  63. package/test/bitset.test.js +65 -0
  64. package/test/callback_api.test.js +438 -0
  65. package/test/channel.test.js +592 -0
  66. package/test/channel_api.test.js +537 -0
  67. package/test/codec.test.js +172 -0
  68. package/test/connect.test.js +196 -0
  69. package/test/connection.test.js +330 -0
  70. package/test/data.test.js +33 -0
  71. package/test/frame.test.js +180 -0
  72. package/test/lib/data.js +249 -0
  73. package/test/lib/util.js +223 -0
  74. package/test/mux.test.js +215 -0
  75. package/test/bitset.js +0 -69
  76. package/test/callback_api.js +0 -379
  77. package/test/channel.js +0 -621
  78. package/test/channel_api.js +0 -606
  79. package/test/codec.js +0 -237
  80. package/test/connect.js +0 -197
  81. package/test/connection.js +0 -390
  82. package/test/data.js +0 -269
  83. package/test/frame.js +0 -191
  84. package/test/mux.js +0 -203
  85. package/test/util.js +0 -217
package/biome.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "formatter": {
3
+ "enabled": true,
4
+ "formatWithErrors": false,
5
+ "indentStyle": "space",
6
+ "indentWidth": 2,
7
+ "lineWidth": 140,
8
+ "lineEnding": "lf",
9
+ "attributePosition": "auto",
10
+ "includes": ["**/*.js", "!test"]
11
+ },
12
+ "linter": {
13
+ "enabled": true,
14
+ "rules": {
15
+ "complexity": {
16
+ "noCommaOperator": "error",
17
+ "noUselessCatch": "error",
18
+ "useArrowFunction": "error",
19
+ "useOptionalChain": "off",
20
+ "noArguments": "error",
21
+ "useLiteralKeys": "off"
22
+ },
23
+ "suspicious": {
24
+ "noRedundantUseStrict": "error",
25
+ "noAsyncPromiseExecutor": "off",
26
+ "noGlobalIsNan": "error",
27
+ "noGlobalIsFinite": "error",
28
+ "noPrototypeBuiltins": "error",
29
+ "noVar": "error",
30
+ "noExportsInTest": "off",
31
+ "useIterableCallbackReturn": "off"
32
+ },
33
+ "style": {
34
+ "useSingleVarDeclarator": "error"
35
+ }
36
+ },
37
+ "includes": ["**/*.js", "!lib/defs.js"]
38
+ },
39
+ "javascript": {
40
+ "formatter": {
41
+ "arrowParentheses": "always",
42
+ "bracketSameLine": false,
43
+ "bracketSpacing": true,
44
+ "jsxQuoteStyle": "double",
45
+ "quoteProperties": "asNeeded",
46
+ "quoteStyle": "single",
47
+ "semicolons": "always",
48
+ "trailingCommas": "all"
49
+ }
50
+ }
51
+ }
package/callback_api.js CHANGED
@@ -1,21 +1,25 @@
1
- var raw_connect = require('./lib/connect').connect;
2
- var CallbackModel = require('./lib/callback_model').CallbackModel;
1
+ const raw_connect = require('./lib/connect').connect;
2
+ const CallbackModel = require('./lib/callback_model').CallbackModel;
3
3
 
4
4
  // Supports three shapes:
5
5
  // connect(url, options, callback)
6
6
  // connect(url, callback)
7
7
  // connect(callback)
8
8
  function connect(url, options, cb) {
9
- if (typeof url === 'function')
10
- cb = url, url = false, options = false;
11
- else if (typeof options === 'function')
12
- cb = options, options = false;
9
+ if (typeof url === 'function') {
10
+ cb = url;
11
+ url = false;
12
+ options = false;
13
+ } else if (typeof options === 'function') {
14
+ cb = options;
15
+ options = false;
16
+ }
13
17
 
14
- raw_connect(url, options, function(err, c) {
18
+ raw_connect(url, options, (err, c) => {
15
19
  if (err === null) cb(null, new CallbackModel(c));
16
20
  else cb(err);
17
21
  });
18
- };
22
+ }
19
23
 
20
24
  module.exports.connect = connect;
21
25
  module.exports.credentials = require('./lib/credentials');
package/channel_api.js CHANGED
@@ -1,15 +1,10 @@
1
- var raw_connect = require('./lib/connect').connect;
2
- var ChannelModel = require('./lib/channel_model').ChannelModel;
3
- var promisify = require('util').promisify;
1
+ const raw_connect = require('./lib/connect').connect;
2
+ const ChannelModel = require('./lib/channel_model').ChannelModel;
3
+ const promisify = require('node:util').promisify;
4
4
 
5
5
  function connect(url, connOptions) {
6
- return promisify(function(cb) {
7
- return raw_connect(url, connOptions, cb);
8
- })()
9
- .then(function(conn) {
10
- return new ChannelModel(conn);
11
- });
12
- };
6
+ return promisify((cb) => raw_connect(url, connOptions, cb))().then((conn) => new ChannelModel(conn));
7
+ }
13
8
 
14
9
  module.exports.connect = connect;
15
10
  module.exports.credentials = require('./lib/credentials');
@@ -8,11 +8,15 @@ const queue = 'rpc_queue';
8
8
  const connection = await amqp.connect();
9
9
  const channel = await connection.createChannel();
10
10
 
11
- await channel.consume('amq.rabbitmq.reply-to', async (message) => {
12
- console.log(message.content.toString());
13
- await channel.close();
14
- await connection.close();
15
- }, { noAck: true });
11
+ await channel.consume(
12
+ 'amq.rabbitmq.reply-to',
13
+ async (message) => {
14
+ console.log(message.content.toString());
15
+ await channel.close();
16
+ await connection.close();
17
+ },
18
+ { noAck: true },
19
+ );
16
20
 
17
21
  await channel.assertQueue(queue, { durable: false });
18
22
 
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const amqp = require('../');
4
- const { v4: uuid } = require('uuid');
5
4
 
6
5
  const queue = 'rpc_queue';
7
6
 
@@ -15,11 +14,14 @@ const queue = 'rpc_queue';
15
14
  });
16
15
 
17
16
  await channel.assertQueue(queue, { durable: false });
18
- await channel.consume(queue, (message) => {
19
- console.log(message.content.toString());
20
- channel.sendToQueue(message.properties.replyTo, Buffer.from(' [.] pong'));
21
- }, { noAck: true });
17
+ await channel.consume(
18
+ queue,
19
+ (message) => {
20
+ console.log(message.content.toString());
21
+ channel.sendToQueue(message.properties.replyTo, Buffer.from(' [.] pong'));
22
+ },
23
+ { noAck: true },
24
+ );
22
25
 
23
26
  console.log(' [x] To exit press CTRL+C.');
24
-
25
27
  })();
@@ -3,7 +3,6 @@
3
3
  const amqp = require('../');
4
4
 
5
5
  (async () => {
6
-
7
6
  const connection = await amqp.connect();
8
7
  const channel = await connection.createChannel();
9
8
 
@@ -24,17 +23,21 @@ const amqp = require('../');
24
23
  // matched go in subsequent fields.
25
24
  await channel.bindQueue(queue, exchange, '', {
26
25
  'x-match': 'any',
27
- 'foo': 'bar',
28
- 'baz': 'boo'
26
+ foo: 'bar',
27
+ baz: 'boo',
29
28
  });
30
29
 
31
- await channel.consume(queue, (message) => {
32
- console.log(message.content.toString());
33
- }, { noAck: true });
34
-
35
- channel.publish(exchange, '', Buffer.from('hello'), { headers: { baz: 'boo' }});
36
- channel.publish(exchange, '', Buffer.from('hello'), { headers: { foo: 'bar' }});
37
- channel.publish(exchange, '', Buffer.from('lost'), { headers: { meh: 'nah' }});
30
+ await channel.consume(
31
+ queue,
32
+ (message) => {
33
+ console.log(message.content.toString());
34
+ },
35
+ { noAck: true },
36
+ );
37
+
38
+ channel.publish(exchange, '', Buffer.from('hello'), { headers: { baz: 'boo' } });
39
+ channel.publish(exchange, '', Buffer.from('hello'), { headers: { foo: 'bar' } });
40
+ channel.publish(exchange, '', Buffer.from('lost'), { headers: { meh: 'nah' } });
38
41
 
39
42
  console.log(' [x] To exit press CTRL+C.');
40
43
  })();
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env node
2
-
3
- 'use strict';
4
2
  const co = require('co');
5
3
  const amqp = require('amqplib');
6
- const readline = require('readline');
4
+ const readline = require('node:readline');
7
5
 
8
6
  co(function* () {
9
7
  const myConsumer = (msg) => {
@@ -12,28 +10,23 @@ co(function* () {
12
10
  }
13
11
  };
14
12
  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 => {
13
+ // create a message to consume
14
+ const q = 'hello';
15
+ const msg = 'Hello World!';
16
+ const channel = yield conn.createChannel();
17
+ yield channel.assertQueue(q);
18
+ channel.sendToQueue(q, Buffer.from(msg));
19
+ console.log(" [x] Sent '%s'", msg);
20
+ // consume the message
21
+ yield channel.consume(q, myConsumer, { noAck: true });
22
+ }).catch((err) => {
30
23
  console.warn('Error:', err);
31
24
  });
32
25
 
33
26
  const rl = readline.createInterface({
34
27
  input: process.stdin,
35
- output: process.stdout
28
+ output: process.stdout,
36
29
  });
37
30
 
38
31
  // pend until message is consumed
39
- rl.question('newline to exit', () => process.exit());
32
+ rl.question('newline to exit', () => process.exit());
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- 'use strict';
4
-
5
3
  // NB this requires the module 'co':
6
4
  // npm install co
7
5
  const co = require('co');
@@ -29,14 +27,9 @@ co(function* () {
29
27
  console.log(" [x] Sent '%s'", msg);
30
28
 
31
29
  channel.close();
32
- }
33
- catch (e) {
34
- throw e;
35
- }
36
- finally {
30
+ } finally {
37
31
  conn.close();
38
32
  }
39
-
40
- }).catch(err => {
33
+ }).catch((err) => {
41
34
  console.warn('Error:', err);
42
35
  });
package/examples/ssl.js CHANGED
@@ -19,7 +19,7 @@
19
19
  // openssl s_client -connect localhost:5671
20
20
 
21
21
  const amqp = require('../');
22
- const fs = require('fs');
22
+ const fs = require('node:fs');
23
23
 
24
24
  // Assemble the SSL options; for verification we need at least
25
25
  // * a certificate to present to the server ('cert', in PEM format)
@@ -40,7 +40,7 @@ const opts = {
40
40
  // cert and key or
41
41
  // pfx: fs.readFileSync('../etc/client/keycert.p12'),
42
42
  passphrase: 'MySecretPassword',
43
- ca: [fs.readFileSync('../etc/testca/cacert.pem')]
43
+ ca: [fs.readFileSync('../etc/testca/cacert.pem')],
44
44
  };
45
45
 
46
46
  // Options for just confidentiality. This requires RabbitMQ's SSL
@@ -67,4 +67,3 @@ const opts = {
67
67
 
68
68
  console.log(' [x] To exit press CTRL+C.');
69
69
  })();
70
-
@@ -1,34 +1,37 @@
1
1
  const amqp = require('amqplib');
2
2
 
3
3
  (async () => {
4
- try {
5
- const connection = await amqp.connect('amqp://localhost');
6
- process.once('SIGINT', connection.close);
7
-
8
- const channel = await connection.createChannel();
9
- const queue = 'my_first_stream';
10
-
11
- // Define the queue stream
12
- // Mandatory: exclusive: false, durable: true autoDelete: false
13
- await channel.assertQueue(queue, {
14
- exclusive: false,
15
- durable: true,
16
- autoDelete: false,
17
- arguments: {
18
- 'x-queue-type': 'stream', // Mandatory to define stream queue
19
- 'x-max-length-bytes': 2_000_000_000 // Set the queue retention to 2GB else the stream doesn't have any limit
20
- }
21
- });
22
-
23
- channel.qos(100); // This is mandatory
24
-
25
- channel.consume(queue, (msg) => {
26
- console.log(" [x] Received '%s'", msg.content.toString());
27
- channel.ack(msg); // Mandatory
28
- }, {
29
- noAck: false,
30
- arguments: {
31
- /*
4
+ try {
5
+ const connection = await amqp.connect('amqp://localhost');
6
+ process.once('SIGINT', connection.close);
7
+
8
+ const channel = await connection.createChannel();
9
+ const queue = 'my_first_stream';
10
+
11
+ // Define the queue stream
12
+ // Mandatory: exclusive: false, durable: true autoDelete: false
13
+ await channel.assertQueue(queue, {
14
+ exclusive: false,
15
+ durable: true,
16
+ autoDelete: false,
17
+ arguments: {
18
+ 'x-queue-type': 'stream', // Mandatory to define stream queue
19
+ 'x-max-length-bytes': 2_000_000_000, // Set the queue retention to 2GB else the stream doesn't have any limit
20
+ },
21
+ });
22
+
23
+ channel.qos(100); // This is mandatory
24
+
25
+ channel.consume(
26
+ queue,
27
+ (msg) => {
28
+ console.log(" [x] Received '%s'", msg.content.toString());
29
+ channel.ack(msg); // Mandatory
30
+ },
31
+ {
32
+ noAck: false,
33
+ arguments: {
34
+ /*
32
35
  Here you can specify the offset: : first, last, next, offset, timestamp and interval, i.e.
33
36
 
34
37
  'x-stream-offset': 'first'
@@ -42,14 +45,14 @@ const amqp = require('amqplib');
42
45
  The interval units can be Y, M, D, h, m, s
43
46
 
44
47
  */
45
- 'x-stream-offset': 'first'
46
- }
47
- });
48
+ 'x-stream-offset': 'first',
49
+ },
50
+ },
51
+ );
48
52
 
49
- console.log(' [*] Waiting for messages. To exit press CTRL+C');
50
- }
53
+ console.log(' [*] Waiting for messages. To exit press CTRL+C');
54
+ } catch (e) {
51
55
  // Catch and display any errors in the console
52
- catch(e) {
53
- console.log(e)
54
- }
56
+ console.log(e);
57
+ }
55
58
  })();
@@ -1,38 +1,35 @@
1
1
  const amqp = require('amqplib');
2
2
 
3
-
4
3
  (async () => {
5
- try {
6
- const connection = await amqp.connect('amqp://localhost');
7
- process.once('SIGINT', connection.close);
4
+ try {
5
+ const connection = await amqp.connect('amqp://localhost');
6
+ process.once('SIGINT', connection.close);
8
7
 
9
- const channel = await connection.createChannel();
10
- const queue = 'my_first_stream';
11
- const msg = `Hello World! ${Date.now()}`;
8
+ const channel = await connection.createChannel();
9
+ const queue = 'my_first_stream';
10
+ const msg = `Hello World! ${Date.now()}`;
12
11
 
13
- // Define the queue stream
14
- // Mandatory: exclusive: false, durable: true autoDelete: false
15
- await channel.assertQueue(queue, {
16
- exclusive: false,
17
- durable: true,
18
- autoDelete: false,
19
- arguments: {
20
- 'x-queue-type': 'stream', // Mandatory to define stream queue
21
- 'x-max-length-bytes': 2_000_000_000 // Set the queue retention to 2GB else the stream doesn't have any limit
22
- }
23
- });
12
+ // Define the queue stream
13
+ // Mandatory: exclusive: false, durable: true autoDelete: false
14
+ await channel.assertQueue(queue, {
15
+ exclusive: false,
16
+ durable: true,
17
+ autoDelete: false,
18
+ arguments: {
19
+ 'x-queue-type': 'stream', // Mandatory to define stream queue
20
+ 'x-max-length-bytes': 2_000_000_000, // Set the queue retention to 2GB else the stream doesn't have any limit
21
+ },
22
+ });
24
23
 
25
- // Send the message to the stream queue
26
- await channel.sendToQueue(queue, Buffer.from(msg));
27
- console.log(" [x] Sent '%s'", msg);
28
- await channel.close();
24
+ // Send the message to the stream queue
25
+ await channel.sendToQueue(queue, Buffer.from(msg));
26
+ console.log(" [x] Sent '%s'", msg);
27
+ await channel.close();
29
28
 
30
- // Close connection
31
- connection.close();
32
- }
29
+ // Close connection
30
+ connection.close();
31
+ } catch (e) {
33
32
  // Catch and display any errors in the console
34
- catch(e) {
35
- console.log(e)
36
- }
33
+ console.log(e);
34
+ }
37
35
  })();
38
-
@@ -22,7 +22,8 @@ amqp.connect((err, connection) => {
22
22
 
23
23
  function bail(err, connection) {
24
24
  console.error(err);
25
- if (connection) connection.close(() => {
26
- process.exit(1);
27
- });
25
+ if (connection)
26
+ connection.close(() => {
27
+ process.exit(1);
28
+ });
28
29
  }
@@ -4,7 +4,7 @@ const amqp = require('amqplib/callback_api');
4
4
 
5
5
  const exchange = 'direct_logs';
6
6
  const args = process.argv.slice(2);
7
- const routingKey = (args.length > 0) ? args[0] : 'info';
7
+ const routingKey = args.length > 0 ? args[0] : 'info';
8
8
  const text = args.slice(1).join(' ') || 'Hello World!';
9
9
 
10
10
  amqp.connect((err, connection) => {
@@ -24,7 +24,8 @@ amqp.connect((err, connection) => {
24
24
 
25
25
  function bail(err, connection) {
26
26
  console.error(err);
27
- if (connection) connection.close(() => {
28
- process.exit(1);
29
- });
27
+ if (connection)
28
+ connection.close(() => {
29
+ process.exit(1);
30
+ });
30
31
  }
@@ -4,7 +4,7 @@ const amqp = require('amqplib/callback_api');
4
4
 
5
5
  const exchange = 'topic_logs';
6
6
  const args = process.argv.slice(2);
7
- const routingKey = (args.length > 0) ? args[0] : 'info';
7
+ const routingKey = args.length > 0 ? args[0] : 'info';
8
8
  const text = args.slice(1).join(' ') || 'Hello World!';
9
9
 
10
10
  amqp.connect((err, connection) => {
@@ -24,7 +24,8 @@ amqp.connect((err, connection) => {
24
24
 
25
25
  function bail(err, connection) {
26
26
  console.error(err);
27
- if (connection) connection.close(() => {
28
- process.exit(1);
29
- });
27
+ if (connection)
28
+ connection.close(() => {
29
+ process.exit(1);
30
+ });
30
31
  }
@@ -3,7 +3,7 @@
3
3
  const amqp = require('amqplib/callback_api');
4
4
 
5
5
  const queue = 'task_queue';
6
- const text = process.argv.slice(2).join(' ') || "Hello World!";
6
+ const text = process.argv.slice(2).join(' ') || 'Hello World!';
7
7
 
8
8
  amqp.connect((err, connection) => {
9
9
  if (err) return bail(err);
@@ -22,7 +22,8 @@ amqp.connect((err, connection) => {
22
22
 
23
23
  function bail(err, connection) {
24
24
  console.error(err);
25
- if (connection) connection.close(() => {
26
- process.exit(1);
27
- });
25
+ if (connection)
26
+ connection.close(() => {
27
+ process.exit(1);
28
+ });
28
29
  }
@@ -17,20 +17,26 @@ amqp.connect((err, connection) => {
17
17
 
18
18
  channel.assertQueue(queue, { durable: false }, (err) => {
19
19
  if (err) return bail(err, connection);
20
- channel.consume(queue, (message) => {
21
- if (message) console.log(" [x] Received '%s'", message.content.toString());
22
- else console.warn(' [x] Consumer cancelled');
23
- }, { noAck: true }, (err) => {
24
- if (err) return bail(err, connection);
25
- console.log(" [*] Waiting for logs. To exit press CTRL+C.");
26
- });
20
+ channel.consume(
21
+ queue,
22
+ (message) => {
23
+ if (message) console.log(" [x] Received '%s'", message.content.toString());
24
+ else console.warn(' [x] Consumer cancelled');
25
+ },
26
+ { noAck: true },
27
+ (err) => {
28
+ if (err) return bail(err, connection);
29
+ console.log(' [*] Waiting for logs. To exit press CTRL+C.');
30
+ },
31
+ );
27
32
  });
28
33
  });
29
34
  });
30
35
 
31
36
  function bail(err, connection) {
32
37
  console.error(err);
33
- if (connection) connection.close(() => {
34
- process.exit(1);
35
- });
38
+ if (connection)
39
+ connection.close(() => {
40
+ process.exit(1);
41
+ });
36
42
  }
@@ -15,19 +15,24 @@ amqp.connect((err, connection) => {
15
15
  });
16
16
  });
17
17
 
18
- channel.assertExchange(exchange, 'fanout', { durable: false }, (err, { queue }) => {
18
+ channel.assertExchange(exchange, 'fanout', { durable: false }, (err, { queue: _queue }) => {
19
19
  if (err) return bail(err, connection);
20
20
  channel.assertQueue('', { exclusive: true }, (err, { queue }) => {
21
21
  if (err) return bail(err, connection);
22
22
  channel.bindQueue(queue, exchange, '', {}, (err) => {
23
23
  if (err) return bail(err, connection);
24
- channel.consume(queue, (message) => {
25
- if (message) console.log(" [x] '%s'", message.content.toString());
26
- else console.warn(' [x] Consumer cancelled');
27
- }, { noAck: true }, (err) => {
28
- if (err) return bail(err, connection);
29
- console.log(" [*] Waiting for logs. To exit press CTRL+C.");
30
- });
24
+ channel.consume(
25
+ queue,
26
+ (message) => {
27
+ if (message) console.log(" [x] '%s'", message.content.toString());
28
+ else console.warn(' [x] Consumer cancelled');
29
+ },
30
+ { noAck: true },
31
+ (err) => {
32
+ if (err) return bail(err, connection);
33
+ console.log(' [*] Waiting for logs. To exit press CTRL+C.');
34
+ },
35
+ );
31
36
  });
32
37
  });
33
38
  });
@@ -36,7 +41,8 @@ amqp.connect((err, connection) => {
36
41
 
37
42
  function bail(err, connection) {
38
43
  console.error(err);
39
- if (connection) connection.close(() => {
40
- process.exit(1);
41
- });
44
+ if (connection)
45
+ connection.close(() => {
46
+ process.exit(1);
47
+ });
42
48
  }