rascal 13.1.0 → 14.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 (66) hide show
  1. package/.husky/pre-commit +1 -1
  2. package/.prettierrc.json +4 -0
  3. package/CHANGELOG.md +212 -1
  4. package/README.md +601 -382
  5. package/examples/advanced/cluster.js +8 -8
  6. package/examples/advanced/config.js +121 -123
  7. package/examples/advanced/handlers/deleteUser.js +16 -17
  8. package/examples/advanced/handlers/saveUser.js +32 -33
  9. package/examples/advanced/index.js +85 -80
  10. package/examples/busy-publisher/config.js +19 -22
  11. package/examples/busy-publisher/index.js +11 -12
  12. package/examples/default-exchange/config.js +13 -13
  13. package/examples/default-exchange/index.js +22 -18
  14. package/examples/mocha/config.js +13 -15
  15. package/examples/mocha/test.js +34 -35
  16. package/examples/promises/config.js +15 -17
  17. package/examples/promises/index.js +14 -12
  18. package/examples/simple/config.js +21 -23
  19. package/examples/simple/index.js +20 -22
  20. package/index.js +1 -1
  21. package/lib/amqp/Broker.js +105 -82
  22. package/lib/amqp/BrokerAsPromised.js +40 -28
  23. package/lib/amqp/Publication.js +15 -14
  24. package/lib/amqp/PublicationSession.js +6 -7
  25. package/lib/amqp/SubscriberError.js +159 -124
  26. package/lib/amqp/SubscriberSession.js +87 -68
  27. package/lib/amqp/SubscriberSessionAsPromised.js +1 -3
  28. package/lib/amqp/Subscription.js +25 -24
  29. package/lib/amqp/Vhost.js +92 -68
  30. package/lib/amqp/tasks/applyBindings.js +9 -6
  31. package/lib/amqp/tasks/assertExchanges.js +9 -5
  32. package/lib/amqp/tasks/assertQueues.js +9 -5
  33. package/lib/amqp/tasks/assertVhost.js +17 -13
  34. package/lib/amqp/tasks/bounceVhost.js +1 -1
  35. package/lib/amqp/tasks/checkExchanges.js +9 -5
  36. package/lib/amqp/tasks/checkQueues.js +9 -5
  37. package/lib/amqp/tasks/checkVhost.js +17 -13
  38. package/lib/amqp/tasks/closeChannel.js +0 -1
  39. package/lib/amqp/tasks/createChannel.js +0 -1
  40. package/lib/amqp/tasks/createConnection.js +20 -15
  41. package/lib/amqp/tasks/deleteExchanges.js +9 -5
  42. package/lib/amqp/tasks/deleteQueues.js +9 -5
  43. package/lib/amqp/tasks/deleteVhost.js +17 -13
  44. package/lib/amqp/tasks/forewarnVhost.js +1 -1
  45. package/lib/amqp/tasks/initCounters.js +12 -8
  46. package/lib/amqp/tasks/initPublications.js +13 -9
  47. package/lib/amqp/tasks/initShovels.js +9 -5
  48. package/lib/amqp/tasks/initSubscriptions.js +12 -8
  49. package/lib/amqp/tasks/initVhosts.js +16 -12
  50. package/lib/amqp/tasks/nukeVhost.js +1 -1
  51. package/lib/amqp/tasks/purgeQueues.js +9 -5
  52. package/lib/amqp/tasks/purgeVhost.js +1 -1
  53. package/lib/amqp/tasks/shutdownVhost.js +1 -1
  54. package/lib/backoff/exponential.js +1 -2
  55. package/lib/backoff/index.js +1 -1
  56. package/lib/backoff/linear.js +2 -4
  57. package/lib/config/baseline.js +12 -23
  58. package/lib/config/configure.js +89 -41
  59. package/lib/config/tests.js +30 -27
  60. package/lib/config/validate.js +22 -3
  61. package/lib/counters/inMemoryCluster.js +33 -22
  62. package/lib/counters/index.js +1 -1
  63. package/lib/counters/stub.js +2 -3
  64. package/lib/management/client.js +3 -9
  65. package/lib/utils/setTimeoutUnref.js +1 -1
  66. package/package.json +12 -4
@@ -1,42 +1,39 @@
1
1
  module.exports = {
2
2
  vhosts: {
3
- "/": {
3
+ '/': {
4
4
  publicationChannelPools: {
5
5
  confirmPool: {
6
6
  max: 10,
7
7
  min: 10,
8
8
  evictionRunIntervalMillis: 1000,
9
9
  idleTimeoutMillis: 5000,
10
- autostart: true
11
- }
10
+ autostart: true,
11
+ },
12
12
  },
13
13
  connection: {
14
14
  heartbeat: 5,
15
15
  socketOptions: {
16
- timeout: 1000
17
- }
16
+ timeout: 1000,
17
+ },
18
18
  },
19
- exchanges: ["demo_ex"],
20
- queues: ["demo_q"],
21
- bindings: [
22
- "demo_ex[a.b.c] -> demo_q"
23
- ],
19
+ exchanges: ['demo_ex'],
20
+ queues: ['demo_q'],
21
+ bindings: ['demo_ex[a.b.c] -> demo_q'],
24
22
  publications: {
25
23
  demo_pub: {
26
- exchange: "demo_ex",
27
- routingKey: "a.b.c",
24
+ exchange: 'demo_ex',
25
+ routingKey: 'a.b.c',
28
26
  confirm: false,
29
27
  options: {
30
- persistent: false
31
- }
32
- }
28
+ persistent: false,
29
+ },
30
+ },
33
31
  },
34
32
  subscriptions: {
35
33
  demo_sub: {
36
- queue: "demo_q"
37
- }
38
- }
39
- }
40
- }
41
- }
42
-
34
+ queue: 'demo_q',
35
+ },
36
+ },
37
+ },
38
+ },
39
+ };
@@ -1,23 +1,24 @@
1
- const Rascal = require('../..')
2
- const config = require('./config')
1
+ const Rascal = require('../..');
2
+ const config = require('./config');
3
3
  const random = require('random-readable');
4
4
 
5
5
  Rascal.Broker.create(Rascal.withDefaultConfig(config), (err, broker) => {
6
- if (err) throw err
6
+ if (err) throw err;
7
7
 
8
8
  broker.on('error', console.error);
9
9
 
10
- const stream = random.createRandomStream()
10
+ const stream = random
11
+ .createRandomStream()
11
12
  .on('error', console.error)
12
- .on('data', data => {
13
+ .on('data', (data) => {
13
14
  broker.publish('demo_pub', data, (err, publication) => {
14
- if (err) throw err
15
- publication.on('error', console.error)
16
- })
15
+ if (err) throw err;
16
+ publication.on('error', console.error);
17
+ });
17
18
  })
18
19
  .on('end', () => {
19
20
  console.log('end');
20
- })
21
+ });
21
22
 
22
23
  broker.on('busy', (details) => {
23
24
  console.log(Date.now(), `Pausing vhost: ${details.vhost} (mode: ${details.mode}, queue: ${details.queue}, size: ${details.size}, borrowed: ${details.borrowed}, available: ${details.available})`);
@@ -28,6 +29,4 @@ Rascal.Broker.create(Rascal.withDefaultConfig(config), (err, broker) => {
28
29
  console.log(Date.now(), `Resuming vhost: ${details.vhost} (mode: ${details.mode}, queue: ${details.queue}, size: ${details.size}, borrowed: ${details.borrowed}, available: ${details.available})`);
29
30
  stream.resume();
30
31
  });
31
- })
32
-
33
-
32
+ });
@@ -1,24 +1,24 @@
1
1
  module.exports = {
2
2
  vhosts: {
3
- "/": {
3
+ '/': {
4
4
  connection: {
5
5
  heartbeat: 1,
6
6
  socketOptions: {
7
- timeout: 1000
8
- }
7
+ timeout: 1000,
8
+ },
9
9
  },
10
- exchanges: [""],
11
- queues: ["demo_q"],
10
+ exchanges: [''],
11
+ queues: ['demo_q'],
12
12
  publications: {
13
13
  demo_pub: {
14
- exchange: ""
15
- }
14
+ exchange: '',
15
+ },
16
16
  },
17
17
  subscriptions: {
18
18
  demo_sub: {
19
- queue: "demo_q"
20
- }
21
- }
22
- }
23
- }
24
- }
19
+ queue: 'demo_q',
20
+ },
21
+ },
22
+ },
23
+ },
24
+ };
@@ -1,21 +1,25 @@
1
- var Rascal = require('../..')
2
- var config = require('./config')
1
+ var Rascal = require('../..');
2
+ var config = require('./config');
3
3
 
4
- Rascal.Broker.create(Rascal.withDefaultConfig(config), function(err, broker) {
5
- if (err) throw err
4
+ Rascal.Broker.create(Rascal.withDefaultConfig(config), function (err, broker) {
5
+ if (err) throw err;
6
6
 
7
- broker.subscribe('demo_sub', function(err, subscription) {
8
- if (err) throw err
9
- subscription.on('message', function(message, content, ackOrNack) {
10
- console.log(content)
11
- ackOrNack()
12
- }).on('error', console.error)
13
- }).on('error', console.error)
14
-
15
- setInterval(function() {
16
- broker.publish('demo_pub', new Date().toISOString() + ': hello world', "demo_q", function(err, publication) {
17
- if (err) throw err
18
- publication.on('error', console.error)
7
+ broker
8
+ .subscribe('demo_sub', function (err, subscription) {
9
+ if (err) throw err;
10
+ subscription
11
+ .on('message', function (message, content, ackOrNack) {
12
+ console.log(content);
13
+ ackOrNack();
14
+ })
15
+ .on('error', console.error);
19
16
  })
20
- }, 1000)
21
- })
17
+ .on('error', console.error);
18
+
19
+ setInterval(function () {
20
+ broker.publish('demo_pub', new Date().toISOString() + ': hello world', 'demo_q', function (err, publication) {
21
+ if (err) throw err;
22
+ publication.on('error', console.error);
23
+ });
24
+ }, 1000);
25
+ });
@@ -1,22 +1,20 @@
1
1
  module.exports = {
2
2
  vhosts: {
3
- "/": {
4
- exchanges: ["demo_ex"],
5
- queues: ["demo_q"],
6
- bindings: [
7
- "demo_ex[a.b.c] -> demo_q"
8
- ],
3
+ '/': {
4
+ exchanges: ['demo_ex'],
5
+ queues: ['demo_q'],
6
+ bindings: ['demo_ex[a.b.c] -> demo_q'],
9
7
  publications: {
10
8
  demo_pub: {
11
- exchange: "demo_ex",
12
- routingKey: "a.b.c"
13
- }
9
+ exchange: 'demo_ex',
10
+ routingKey: 'a.b.c',
11
+ },
14
12
  },
15
13
  subscriptions: {
16
14
  demo_sub: {
17
- queue: "demo_q"
18
- }
19
- }
20
- }
21
- }
22
- }
15
+ queue: 'demo_q',
16
+ },
17
+ },
18
+ },
19
+ },
20
+ };
@@ -1,41 +1,40 @@
1
- var assert = require('assert')
2
- var Rascal = require('../..')
3
- var config = require('./config.js')
1
+ var assert = require('assert');
2
+ var Rascal = require('../..');
3
+ var config = require('./config.js');
4
4
 
5
- describe('Example rascal test', function() {
5
+ describe('Example rascal test', function () {
6
+ var broker;
6
7
 
7
- var broker
8
+ before(function (done) {
9
+ config.vhosts['/'].publications.test_pub = { exchange: 'demo_ex' };
10
+ Rascal.Broker.create(Rascal.withTestConfig(config), function (err, _broker) {
11
+ if (err) return done(err);
12
+ broker = _broker;
13
+ done();
14
+ });
15
+ });
8
16
 
9
- before(function(done) {
10
- config.vhosts["/"].publications.test_pub = { exchange: "demo_ex" }
11
- Rascal.Broker.create(Rascal.withTestConfig(config), function(err, _broker) {
12
- if (err) return done(err)
13
- broker = _broker
14
- done()
15
- })
16
- })
17
+ beforeEach(function (done) {
18
+ broker.purge(done);
19
+ });
17
20
 
18
- beforeEach(function(done) {
19
- broker.purge(done)
20
- })
21
+ after(function (done) {
22
+ if (!broker) return done();
23
+ broker.nuke(done);
24
+ });
21
25
 
22
- after(function(done) {
23
- if (!broker) return done()
24
- broker.nuke(done)
25
- })
26
+ it('should demonstrate tests', function (done) {
27
+ broker.subscribe('demo_sub', function (err, subscription) {
28
+ assert.ifError(err);
29
+ subscription.on('message', function (message, content, ackOrNack) {
30
+ subscription.cancel();
31
+ ackOrNack();
32
+ done();
33
+ });
34
+ });
26
35
 
27
- it('should demonstrate tests', function(done) {
28
- broker.subscribe('demo_sub', function(err, subscription) {
29
- assert.ifError(err)
30
- subscription.on('message', function(message, content, ackOrNack) {
31
- subscription.cancel()
32
- ackOrNack()
33
- done()
34
- })
35
- })
36
-
37
- broker.publish('test_pub', 'Hello Test', 'a.b.c', function(err, publication) {
38
- assert.ifError(err)
39
- })
40
- })
41
- })
36
+ broker.publish('test_pub', 'Hello Test', 'a.b.c', function (err, publication) {
37
+ assert.ifError(err);
38
+ });
39
+ });
40
+ });
@@ -1,28 +1,26 @@
1
1
  module.exports = {
2
2
  vhosts: {
3
- "/": {
3
+ '/': {
4
4
  connection: {
5
5
  heartbeat: 1,
6
6
  socketOptions: {
7
- timeout: 1000
8
- }
7
+ timeout: 1000,
8
+ },
9
9
  },
10
- exchanges: ["demo_ex"],
11
- queues: ["demo_q"],
12
- bindings: [
13
- "demo_ex[a.b.c] -> demo_q"
14
- ],
10
+ exchanges: ['demo_ex'],
11
+ queues: ['demo_q'],
12
+ bindings: ['demo_ex[a.b.c] -> demo_q'],
15
13
  publications: {
16
14
  demo_pub: {
17
- exchange: "demo_ex",
18
- routingKey: "a.b.c"
19
- }
15
+ exchange: 'demo_ex',
16
+ routingKey: 'a.b.c',
17
+ },
20
18
  },
21
19
  subscriptions: {
22
20
  demo_sub: {
23
- queue: "demo_q"
24
- }
25
- }
26
- }
27
- }
28
- }
21
+ queue: 'demo_q',
22
+ },
23
+ },
24
+ },
25
+ },
26
+ };
@@ -1,30 +1,32 @@
1
1
  var Rascal = require('../..');
2
2
  var config = require('./config');
3
3
 
4
- (async function() {
4
+ (async function () {
5
5
  try {
6
6
  const broker = await Rascal.BrokerAsPromised.create(Rascal.withDefaultConfig(config));
7
- broker.on('error', console.error)
7
+ broker.on('error', console.error);
8
8
 
9
9
  try {
10
10
  const subscription = await broker.subscribe('demo_sub');
11
- subscription.on('message', function(message, content, ackOrNack) {
12
- console.log(content);
13
- ackOrNack();
14
- }).on('error', console.error);
15
- } catch(err) {
11
+ subscription
12
+ .on('message', function (message, content, ackOrNack) {
13
+ console.log(content);
14
+ ackOrNack();
15
+ })
16
+ .on('error', console.error);
17
+ } catch (err) {
16
18
  console.error(err);
17
19
  }
18
20
 
19
- setInterval(async function() {
21
+ setInterval(async function () {
20
22
  try {
21
23
  const publication = await broker.publish('demo_pub', new Date().toISOString() + ': hello world');
22
- publication.on('error', console.error)
23
- } catch(err) {
24
+ publication.on('error', console.error);
25
+ } catch (err) {
24
26
  console.error(err);
25
27
  }
26
- }, 1000)
27
- } catch(err) {
28
+ }, 1000);
29
+ } catch (err) {
28
30
  console.error(err);
29
31
  }
30
32
  })();
@@ -1,38 +1,36 @@
1
1
  module.exports = {
2
2
  vhosts: {
3
- "/": {
3
+ '/': {
4
4
  publicationChannelPools: {
5
- "confirmPool": {
6
- autostart: true
7
- }
5
+ confirmPool: {
6
+ autostart: true,
7
+ },
8
8
  },
9
9
  connection: {
10
10
  options: {
11
- heartbeat: 10
11
+ heartbeat: 10,
12
12
  },
13
13
  socketOptions: {
14
- timeout: 1000
15
- }
14
+ timeout: 1000,
15
+ },
16
16
  },
17
- exchanges: ["demo_ex"],
18
- queues: ["demo_q"],
19
- bindings: [
20
- "demo_ex[a.b.c] -> demo_q"
21
- ],
17
+ exchanges: ['demo_ex'],
18
+ queues: ['demo_q'],
19
+ bindings: ['demo_ex[a.b.c] -> demo_q'],
22
20
  publications: {
23
21
  demo_pub: {
24
- exchange: "demo_ex",
25
- routingKey: "a.b.c",
22
+ exchange: 'demo_ex',
23
+ routingKey: 'a.b.c',
26
24
  options: {
27
- persistent: false
28
- }
29
- }
25
+ persistent: false,
26
+ },
27
+ },
30
28
  },
31
29
  subscriptions: {
32
30
  demo_sub: {
33
- queue: "demo_q"
34
- }
35
- }
36
- }
37
- }
38
- }
31
+ queue: 'demo_q',
32
+ },
33
+ },
34
+ },
35
+ },
36
+ };
@@ -1,26 +1,24 @@
1
- var Rascal = require('../..')
2
- var config = require('./config')
1
+ var Rascal = require('../..');
2
+ var config = require('./config');
3
3
 
4
- Rascal.Broker.create(Rascal.withDefaultConfig(config), function(err, broker) {
5
- if (err) throw err
4
+ Rascal.Broker.create(Rascal.withDefaultConfig(config), function (err, broker) {
5
+ if (err) throw err;
6
6
 
7
- broker.subscribe('demo_sub', function(err, subscription) {
8
- if (err) throw err
9
- subscription.on('message', function(message, content, ackOrNack) {
10
- console.log(content)
11
- ackOrNack()
12
- })
13
- subscription.on('error', console.error)
7
+ broker.subscribe('demo_sub', function (err, subscription) {
8
+ if (err) throw err;
9
+ subscription.on('message', function (message, content, ackOrNack) {
10
+ console.log(content);
11
+ ackOrNack();
12
+ });
13
+ subscription.on('error', console.error);
14
14
  subscription.on('cancel', console.warn);
15
- })
16
- broker.on('error', console.error)
17
-
18
- setInterval(function() {
19
- broker.publish('demo_pub', new Date().toISOString() + ': hello world', function(err, publication) {
20
- if (err) throw err
21
- publication.on('error', console.error)
22
- })
23
- }, 1000)
24
- })
25
-
15
+ });
16
+ broker.on('error', console.error);
26
17
 
18
+ setInterval(function () {
19
+ broker.publish('demo_pub', new Date().toISOString() + ': hello world', function (err, publication) {
20
+ if (err) throw err;
21
+ publication.on('error', console.error);
22
+ });
23
+ }, 1000);
24
+ });
package/index.js CHANGED
@@ -4,7 +4,7 @@ const testConfig = require('./lib/config/tests');
4
4
  const Broker = require('./lib/amqp/Broker');
5
5
  const BrokerAsPromised = require('./lib/amqp/BrokerAsPromised');
6
6
 
7
- module.exports = (function() {
7
+ module.exports = (function () {
8
8
  return {
9
9
  Broker,
10
10
  BrokerAsPromised,