rascal 13.1.3 → 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.
- package/.prettierrc.json +4 -1
- package/CHANGELOG.md +11 -0
- package/README.md +189 -208
- package/examples/advanced/cluster.js +4 -4
- package/examples/advanced/config.js +45 -50
- package/examples/advanced/handlers/deleteUser.js +9 -16
- package/examples/advanced/handlers/saveUser.js +11 -18
- package/examples/advanced/index.js +81 -103
- package/examples/busy-publisher/config.js +7 -7
- package/examples/busy-publisher/index.js +14 -20
- package/examples/default-exchange/config.js +5 -5
- package/examples/default-exchange/index.js +10 -15
- package/examples/mocha/config.js +7 -7
- package/examples/mocha/test.js +16 -24
- package/examples/promises/config.js +7 -7
- package/examples/promises/index.js +9 -14
- package/examples/simple/config.js +7 -7
- package/examples/simple/index.js +11 -15
- package/index.js +6 -6
- package/lib/amqp/Broker.js +56 -88
- package/lib/amqp/BrokerAsPromised.js +7 -16
- package/lib/amqp/Publication.js +72 -212
- package/lib/amqp/PublicationSession.js +8 -8
- package/lib/amqp/SubscriberError.js +107 -233
- package/lib/amqp/SubscriberSession.js +56 -76
- package/lib/amqp/SubscriberSessionAsPromised.js +3 -3
- package/lib/amqp/Subscription.js +96 -313
- package/lib/amqp/Vhost.js +116 -262
- package/lib/amqp/tasks/applyBindings.js +12 -42
- package/lib/amqp/tasks/assertExchanges.js +6 -11
- package/lib/amqp/tasks/assertQueues.js +4 -4
- package/lib/amqp/tasks/assertVhost.js +4 -4
- package/lib/amqp/tasks/checkExchanges.js +4 -4
- package/lib/amqp/tasks/checkQueues.js +4 -4
- package/lib/amqp/tasks/checkVhost.js +4 -4
- package/lib/amqp/tasks/closeChannel.js +3 -3
- package/lib/amqp/tasks/closeConnection.js +3 -3
- package/lib/amqp/tasks/createChannel.js +3 -3
- package/lib/amqp/tasks/createConnection.js +38 -53
- package/lib/amqp/tasks/deleteExchanges.js +5 -5
- package/lib/amqp/tasks/deleteQueues.js +4 -4
- package/lib/amqp/tasks/deleteVhost.js +11 -16
- package/lib/amqp/tasks/index.js +25 -25
- package/lib/amqp/tasks/initCounters.js +5 -6
- package/lib/amqp/tasks/initPublications.js +4 -4
- package/lib/amqp/tasks/initShovels.js +15 -20
- package/lib/amqp/tasks/initSubscriptions.js +5 -11
- package/lib/amqp/tasks/initVhosts.js +5 -5
- package/lib/amqp/tasks/purgeQueues.js +4 -4
- package/lib/backoff/exponential.js +6 -8
- package/lib/backoff/index.js +2 -2
- package/lib/backoff/linear.js +3 -3
- package/lib/config/baseline.js +15 -16
- package/lib/config/configure.js +68 -193
- package/lib/config/fqn.js +3 -3
- package/lib/config/tests.js +3 -3
- package/lib/config/validate.js +87 -458
- package/lib/counters/inMemory.js +3 -3
- package/lib/counters/inMemoryCluster.js +16 -23
- package/lib/counters/index.js +3 -3
- package/lib/management/client.js +14 -50
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const format = require(
|
|
3
|
-
const _ = require(
|
|
4
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:applyBindings');
|
|
2
|
+
const format = require('util').format;
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const async = require('async');
|
|
5
5
|
|
|
6
6
|
module.exports = _.curry((config, ctx, next) => {
|
|
7
7
|
const bind = {
|
|
@@ -22,52 +22,22 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
22
22
|
|
|
23
23
|
function bindQueue(config, channel, binding, next) {
|
|
24
24
|
const destination = config.queues[binding.destination];
|
|
25
|
-
if (!destination)
|
|
26
|
-
return next(
|
|
27
|
-
new Error(format("Unknown destination: %s", binding.destination))
|
|
28
|
-
);
|
|
25
|
+
if (!destination) return next(new Error(format('Unknown destination: %s', binding.destination)));
|
|
29
26
|
|
|
30
27
|
const source = config.exchanges[binding.source];
|
|
31
|
-
if (!source)
|
|
32
|
-
return next(new Error(format("Unknown source: %s", binding.source)));
|
|
28
|
+
if (!source) return next(new Error(format('Unknown source: %s', binding.source)));
|
|
33
29
|
|
|
34
|
-
debug(
|
|
35
|
-
|
|
36
|
-
destination.fullyQualifiedName,
|
|
37
|
-
source.fullyQualifiedName,
|
|
38
|
-
binding.bindingKey
|
|
39
|
-
);
|
|
40
|
-
channel.bindQueue(
|
|
41
|
-
destination.fullyQualifiedName,
|
|
42
|
-
source.fullyQualifiedName,
|
|
43
|
-
binding.bindingKey,
|
|
44
|
-
binding.options,
|
|
45
|
-
next
|
|
46
|
-
);
|
|
30
|
+
debug('Binding queue: %s to exchange: %s with binding key: %s', destination.fullyQualifiedName, source.fullyQualifiedName, binding.bindingKey);
|
|
31
|
+
channel.bindQueue(destination.fullyQualifiedName, source.fullyQualifiedName, binding.bindingKey, binding.options, next);
|
|
47
32
|
}
|
|
48
33
|
|
|
49
34
|
function bindExchange(config, channel, binding, next) {
|
|
50
35
|
const destination = config.exchanges[binding.destination];
|
|
51
|
-
if (!destination)
|
|
52
|
-
return next(
|
|
53
|
-
new Error(format("Unknown destination: %s", binding.destination))
|
|
54
|
-
);
|
|
36
|
+
if (!destination) return next(new Error(format('Unknown destination: %s', binding.destination)));
|
|
55
37
|
|
|
56
38
|
const source = config.exchanges[binding.source];
|
|
57
|
-
if (!source)
|
|
58
|
-
return next(new Error(format("Unknown source: %s", binding.source)));
|
|
39
|
+
if (!source) return next(new Error(format('Unknown source: %s', binding.source)));
|
|
59
40
|
|
|
60
|
-
debug(
|
|
61
|
-
|
|
62
|
-
destination.fullyQualifiedName,
|
|
63
|
-
source.fullyQualifiedName,
|
|
64
|
-
binding.bindingKey
|
|
65
|
-
);
|
|
66
|
-
channel.bindExchange(
|
|
67
|
-
destination.fullyQualifiedName,
|
|
68
|
-
source.fullyQualifiedName,
|
|
69
|
-
binding.bindingKey,
|
|
70
|
-
binding.options,
|
|
71
|
-
next
|
|
72
|
-
);
|
|
41
|
+
debug('Binding exchange: %s to exchange: %s with binding key: %s', destination.fullyQualifiedName, source.fullyQualifiedName, binding.bindingKey);
|
|
42
|
+
channel.bindExchange(destination.fullyQualifiedName, source.fullyQualifiedName, binding.bindingKey, binding.options, next);
|
|
73
43
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:assertExchanges');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -16,12 +16,7 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
16
16
|
|
|
17
17
|
function assertExchange(channel, config, next) {
|
|
18
18
|
if (!config.assert) return next();
|
|
19
|
-
if (config.fullyQualifiedName ===
|
|
20
|
-
debug(
|
|
21
|
-
channel.assertExchange(
|
|
22
|
-
config.fullyQualifiedName,
|
|
23
|
-
config.type,
|
|
24
|
-
config.options,
|
|
25
|
-
next
|
|
26
|
-
);
|
|
19
|
+
if (config.fullyQualifiedName === '') return next();
|
|
20
|
+
debug('Asserting exchange: %s', config.fullyQualifiedName);
|
|
21
|
+
channel.assertExchange(config.fullyQualifiedName, config.type, config.options, next);
|
|
27
22
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:assertQueues');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -16,6 +16,6 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
16
16
|
|
|
17
17
|
function assertQueue(channel, config, next) {
|
|
18
18
|
if (!config.assert) return next();
|
|
19
|
-
debug(
|
|
19
|
+
debug('Asserting queue: %s', config.fullyQualifiedName);
|
|
20
20
|
channel.assertQueue(config.fullyQualifiedName, config.options, next);
|
|
21
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
4
|
-
const client = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:assertVhost');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
|
+
const client = require('../../management/client');
|
|
5
5
|
|
|
6
6
|
module.exports = _.curry((config, ctx, next) => {
|
|
7
7
|
if (!config.assert) return next(null, config, ctx);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:checkExchanges');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -16,6 +16,6 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
16
16
|
|
|
17
17
|
function checkExchange(channel, config, next) {
|
|
18
18
|
if (!config.check) return next();
|
|
19
|
-
debug(
|
|
19
|
+
debug('Checking exchange: %s', config.fullyQualifiedName);
|
|
20
20
|
channel.checkExchange(config.fullyQualifiedName, next);
|
|
21
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:checkQueues');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -16,6 +16,6 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
16
16
|
|
|
17
17
|
function checkQueue(channel, config, next) {
|
|
18
18
|
if (!config.check) return next();
|
|
19
|
-
debug(
|
|
19
|
+
debug('Checking queue: %s', config.fullyQualifiedName);
|
|
20
20
|
channel.checkQueue(config.fullyQualifiedName, next);
|
|
21
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
4
|
-
const client = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:checkVhost');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
|
+
const client = require('../../management/client');
|
|
5
5
|
|
|
6
6
|
module.exports = _.curry((config, ctx, next) => {
|
|
7
7
|
if (!config.check) return next(null, config, ctx);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:closeChannel');
|
|
2
|
+
const _ = require('lodash');
|
|
3
3
|
|
|
4
4
|
module.exports = _.curry((config, ctx, next) => {
|
|
5
|
-
debug(
|
|
5
|
+
debug('Closing channel');
|
|
6
6
|
|
|
7
7
|
ctx.channel.close((err) => {
|
|
8
8
|
if (err) return next(err, config, ctx);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:checkQueues');
|
|
2
|
+
const _ = require('lodash');
|
|
3
3
|
|
|
4
4
|
module.exports = _.curry((config, ctx, next) => {
|
|
5
|
-
debug(
|
|
5
|
+
debug('Closing connection: %s', ctx.connectionConfig.loggableUrl);
|
|
6
6
|
if (!ctx.connection) return next(null, config, ctx);
|
|
7
7
|
ctx.connection.close((err) => {
|
|
8
8
|
next(err, config, ctx);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:createChannel');
|
|
2
|
+
const _ = require('lodash');
|
|
3
3
|
|
|
4
4
|
module.exports = _.curry((config, ctx, next) => {
|
|
5
|
-
debug(
|
|
5
|
+
debug('Creating channel');
|
|
6
6
|
|
|
7
7
|
ctx.connection.createChannel((err, channel) => {
|
|
8
8
|
if (err) return next(err, config, ctx);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const amqplib = require(
|
|
4
|
-
const async = require(
|
|
5
|
-
const format = require(
|
|
6
|
-
const uuid = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:createConnection');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const amqplib = require('amqplib/callback_api');
|
|
4
|
+
const async = require('async');
|
|
5
|
+
const format = require('util').format;
|
|
6
|
+
const uuid = require('uuid').v4;
|
|
7
7
|
|
|
8
8
|
module.exports = _.curry((config, ctx, next) => {
|
|
9
9
|
const candidates = config.connections;
|
|
@@ -29,62 +29,47 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
function connect(connectionConfig, cb) {
|
|
32
|
-
debug(
|
|
32
|
+
debug('Connecting to broker using url: %s', connectionConfig.loggableUrl);
|
|
33
33
|
|
|
34
34
|
// See https://github.com/guidesmiths/rascal/issues/17
|
|
35
35
|
const once = _.once(cb);
|
|
36
36
|
let invocations = 0;
|
|
37
37
|
|
|
38
|
-
amqplib.connect(
|
|
39
|
-
|
|
40
|
-
connectionConfig.socketOptions,
|
|
41
|
-
(err, connection) => {
|
|
42
|
-
invocations++;
|
|
38
|
+
amqplib.connect(connectionConfig.url, connectionConfig.socketOptions, (err, connection) => {
|
|
39
|
+
invocations++;
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
err.message = betterMessage;
|
|
51
|
-
return once(err);
|
|
52
|
-
}
|
|
41
|
+
if (err) {
|
|
42
|
+
const betterMessage = format('Failed to connect to: %s. Original message was:', connectionConfig.loggableUrl, err.message);
|
|
43
|
+
err.message = betterMessage;
|
|
44
|
+
return once(err);
|
|
45
|
+
}
|
|
53
46
|
|
|
54
|
-
|
|
55
|
-
|
|
47
|
+
connection._rascal_id = uuid();
|
|
48
|
+
debug('Obtained connection: %s', connection._rascal_id);
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
connectionConfig.loggableUrl
|
|
72
|
-
);
|
|
73
|
-
once(err);
|
|
74
|
-
});
|
|
50
|
+
/*
|
|
51
|
+
* If an error occurs during initialisation (e.g. if checkExchanges fails),
|
|
52
|
+
* and no error handler has been bound to the connection, then the error will bubble up
|
|
53
|
+
* to the UncaughtException handler, potentially crashing the node process.
|
|
54
|
+
*
|
|
55
|
+
* By adding an error handler now, we ensure that instead of being emitted as events
|
|
56
|
+
* errors will be passed via the callback chain, so they can still be handled by the caller
|
|
57
|
+
*
|
|
58
|
+
* This error handle is removed in the vhost after the initialiation has complete
|
|
59
|
+
*/
|
|
60
|
+
connection.on('error', (err) => {
|
|
61
|
+
debug('Received error: %s from %s', err.message, connectionConfig.loggableUrl);
|
|
62
|
+
once(err);
|
|
63
|
+
});
|
|
75
64
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
);
|
|
82
|
-
return connection.close();
|
|
83
|
-
}
|
|
65
|
+
// See https://github.com/squaremo/amqp.node/issues/388
|
|
66
|
+
if (invocations > 1) {
|
|
67
|
+
debug('Closing superfluous connection: %s previously reported as errored', connection._rascal_id);
|
|
68
|
+
return connection.close();
|
|
69
|
+
}
|
|
84
70
|
|
|
85
|
-
|
|
71
|
+
connection.setMaxListeners(0);
|
|
86
72
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
);
|
|
73
|
+
once(null, connection);
|
|
74
|
+
});
|
|
90
75
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:deleteExchanges');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -15,7 +15,7 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
function deleteExchange(channel, config, next) {
|
|
18
|
-
if (config.fullyQualifiedName ===
|
|
19
|
-
debug(
|
|
18
|
+
if (config.fullyQualifiedName === '') return next();
|
|
19
|
+
debug('Deleting exchange: %s', config.fullyQualifiedName);
|
|
20
20
|
channel.deleteExchange(config.fullyQualifiedName, {}, next);
|
|
21
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:deleteQueues');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -15,6 +15,6 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
function deleteQueue(channel, config, next) {
|
|
18
|
-
debug(
|
|
18
|
+
debug('Deleting queue: %s', config.fullyQualifiedName);
|
|
19
19
|
channel.deleteQueue(config.fullyQualifiedName, {}, next);
|
|
20
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
4
|
-
const client = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:deleteVhost');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
|
+
const client = require('../../management/client');
|
|
5
5
|
|
|
6
6
|
module.exports = _.curry((config, ctx, next) => {
|
|
7
7
|
const vhostConfig = config.vhosts[ctx.vhost.name];
|
|
@@ -13,19 +13,14 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
13
13
|
candidates.length,
|
|
14
14
|
(cb) => {
|
|
15
15
|
const connectionConfig = candidates[ctx.vhost.connectionIndex];
|
|
16
|
-
client.deleteVhost(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (err) {
|
|
21
|
-
ctx.vhost.connectionIndex =
|
|
22
|
-
(ctx.vhost.connectionIndex + 1) % candidates.length;
|
|
23
|
-
return cb(err);
|
|
24
|
-
}
|
|
25
|
-
ctx.connectionConfig = connectionConfig;
|
|
26
|
-
cb();
|
|
16
|
+
client.deleteVhost(vhostConfig.name, connectionConfig.management, (err) => {
|
|
17
|
+
if (err) {
|
|
18
|
+
ctx.vhost.connectionIndex = (ctx.vhost.connectionIndex + 1) % candidates.length;
|
|
19
|
+
return cb(err);
|
|
27
20
|
}
|
|
28
|
-
|
|
21
|
+
ctx.connectionConfig = connectionConfig;
|
|
22
|
+
cb();
|
|
23
|
+
});
|
|
29
24
|
},
|
|
30
25
|
(err) => {
|
|
31
26
|
next(err, config, ctx);
|
package/lib/amqp/tasks/index.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
exports.applyBindings = require(
|
|
2
|
-
exports.assertExchanges = require(
|
|
3
|
-
exports.assertQueues = require(
|
|
4
|
-
exports.assertVhost = require(
|
|
5
|
-
exports.bounceVhost = require(
|
|
6
|
-
exports.checkExchanges = require(
|
|
7
|
-
exports.checkQueues = require(
|
|
8
|
-
exports.checkVhost = require(
|
|
9
|
-
exports.closeChannel = require(
|
|
10
|
-
exports.closeConnection = require(
|
|
11
|
-
exports.createChannel = require(
|
|
12
|
-
exports.createConnection = require(
|
|
13
|
-
exports.deleteExchanges = require(
|
|
14
|
-
exports.deleteQueues = require(
|
|
15
|
-
exports.deleteVhost = require(
|
|
16
|
-
exports.initCounters = require(
|
|
17
|
-
exports.initPublications = require(
|
|
18
|
-
exports.initShovels = require(
|
|
19
|
-
exports.initSubscriptions = require(
|
|
20
|
-
exports.initVhosts = require(
|
|
21
|
-
exports.nukeVhost = require(
|
|
22
|
-
exports.purgeQueues = require(
|
|
23
|
-
exports.purgeVhost = require(
|
|
24
|
-
exports.forewarnVhost = require(
|
|
25
|
-
exports.shutdownVhost = require(
|
|
1
|
+
exports.applyBindings = require('./applyBindings.js');
|
|
2
|
+
exports.assertExchanges = require('./assertExchanges.js');
|
|
3
|
+
exports.assertQueues = require('./assertQueues.js');
|
|
4
|
+
exports.assertVhost = require('./assertVhost.js');
|
|
5
|
+
exports.bounceVhost = require('./bounceVhost.js');
|
|
6
|
+
exports.checkExchanges = require('./checkExchanges.js');
|
|
7
|
+
exports.checkQueues = require('./checkQueues.js');
|
|
8
|
+
exports.checkVhost = require('./checkVhost.js');
|
|
9
|
+
exports.closeChannel = require('./closeChannel.js');
|
|
10
|
+
exports.closeConnection = require('./closeConnection.js');
|
|
11
|
+
exports.createChannel = require('./createChannel.js');
|
|
12
|
+
exports.createConnection = require('./createConnection.js');
|
|
13
|
+
exports.deleteExchanges = require('./deleteExchanges.js');
|
|
14
|
+
exports.deleteQueues = require('./deleteQueues.js');
|
|
15
|
+
exports.deleteVhost = require('./deleteVhost.js');
|
|
16
|
+
exports.initCounters = require('./initCounters.js');
|
|
17
|
+
exports.initPublications = require('./initPublications.js');
|
|
18
|
+
exports.initShovels = require('./initShovels.js');
|
|
19
|
+
exports.initSubscriptions = require('./initSubscriptions.js');
|
|
20
|
+
exports.initVhosts = require('./initVhosts.js');
|
|
21
|
+
exports.nukeVhost = require('./nukeVhost.js');
|
|
22
|
+
exports.purgeQueues = require('./purgeQueues.js');
|
|
23
|
+
exports.purgeVhost = require('./purgeVhost.js');
|
|
24
|
+
exports.forewarnVhost = require('./forewarnVhost.js');
|
|
25
|
+
exports.shutdownVhost = require('./shutdownVhost.js');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const format = require(
|
|
3
|
-
const _ = require(
|
|
4
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:initCounters');
|
|
2
|
+
const format = require('util').format;
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const async = require('async');
|
|
5
5
|
|
|
6
6
|
module.exports = _.curry((config, ctx, next) => {
|
|
7
7
|
ctx.counters = {};
|
|
@@ -20,7 +20,6 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
function initCounter(config, ctx, next) {
|
|
23
|
-
if (!ctx.components.counters[config.type])
|
|
24
|
-
return next(new Error(format("Unknown counter type: %s", config.type)));
|
|
23
|
+
if (!ctx.components.counters[config.type]) return next(new Error(format('Unknown counter type: %s', config.type)));
|
|
25
24
|
next(null, ctx.components.counters[config.type](config));
|
|
26
25
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
4
|
-
const Publication = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:initPublication');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
|
+
const Publication = require('../Publication');
|
|
5
5
|
|
|
6
6
|
module.exports = _.curry((config, ctx, next) => {
|
|
7
7
|
async.eachSeries(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:initShovels');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -15,31 +15,26 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
function initShovel(config, ctx, next) {
|
|
18
|
-
debug(
|
|
18
|
+
debug('Initialising shovel: %s', config.name);
|
|
19
19
|
|
|
20
20
|
ctx.broker.subscribe(config.subscription, {}, (err, subscription) => {
|
|
21
21
|
if (err) return next(err);
|
|
22
22
|
|
|
23
|
-
subscription.on(
|
|
24
|
-
ctx.broker.forward(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
publication.on("success", () => {
|
|
31
|
-
ackOrNack();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
);
|
|
23
|
+
subscription.on('message', (message, content, ackOrNack) => {
|
|
24
|
+
ctx.broker.forward(config.publication, message, {}, (err, publication) => {
|
|
25
|
+
if (err) return next(err);
|
|
26
|
+
publication.on('success', () => {
|
|
27
|
+
ackOrNack();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
35
30
|
});
|
|
36
31
|
|
|
37
|
-
subscription.on(
|
|
38
|
-
ctx.broker.emit(
|
|
32
|
+
subscription.on('error', (err) => {
|
|
33
|
+
ctx.broker.emit('error', err);
|
|
39
34
|
});
|
|
40
35
|
|
|
41
|
-
subscription.on(
|
|
42
|
-
ctx.broker.emit(
|
|
36
|
+
subscription.on('cancelled', (err) => {
|
|
37
|
+
ctx.broker.emit('cancelled', err) || ctx.broker.emit('error', err);
|
|
43
38
|
});
|
|
44
39
|
|
|
45
40
|
next();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
4
|
-
const Subscription = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:initSubscriptions');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
|
+
const Subscription = require('../Subscription');
|
|
5
5
|
|
|
6
6
|
module.exports = _.curry((config, ctx, next) => {
|
|
7
7
|
async.eachSeries(
|
|
@@ -19,11 +19,5 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
function initSubscription(config, ctx, next) {
|
|
22
|
-
Subscription.create(
|
|
23
|
-
ctx.broker,
|
|
24
|
-
ctx.vhosts[config.vhost],
|
|
25
|
-
ctx.counters[config.redeliveries.counter],
|
|
26
|
-
config,
|
|
27
|
-
next
|
|
28
|
-
);
|
|
22
|
+
Subscription.create(ctx.broker, ctx.vhosts[config.vhost], ctx.counters[config.redeliveries.counter], config, next);
|
|
29
23
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
4
|
-
const forwardEvents = require(
|
|
5
|
-
const Vhost = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:initVhosts');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
|
+
const forwardEvents = require('forward-emitter');
|
|
5
|
+
const Vhost = require('../Vhost');
|
|
6
6
|
|
|
7
7
|
module.exports = _.curry((config, ctx, next) => {
|
|
8
8
|
ctx.vhosts = {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const _ = require(
|
|
3
|
-
const async = require(
|
|
1
|
+
const debug = require('debug')('rascal:tasks:purgeQueues');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const async = require('async');
|
|
4
4
|
|
|
5
5
|
module.exports = _.curry((config, ctx, next) => {
|
|
6
6
|
async.eachSeries(
|
|
@@ -16,6 +16,6 @@ module.exports = _.curry((config, ctx, next) => {
|
|
|
16
16
|
|
|
17
17
|
function purgeQueue(channel, config, ctx, next) {
|
|
18
18
|
if (!config.purge && !ctx.purge) return next();
|
|
19
|
-
debug(
|
|
19
|
+
debug('Purging queue: %s', config.fullyQualifiedName);
|
|
20
20
|
channel.purgeQueue(config.fullyQualifiedName, next);
|
|
21
21
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
const get = require(
|
|
1
|
+
const get = require('lodash').get;
|
|
2
2
|
|
|
3
3
|
module.exports = function (options) {
|
|
4
|
-
const min = get(options,
|
|
5
|
-
const max = get(options,
|
|
6
|
-
const factor = get(options,
|
|
7
|
-
const randomise = get(options,
|
|
4
|
+
const min = get(options, 'min', 1000);
|
|
5
|
+
const max = get(options, 'max', Math.pow(min, 10));
|
|
6
|
+
const factor = get(options, 'factor', 2);
|
|
7
|
+
const randomise = get(options, 'randomise', true);
|
|
8
8
|
let lower = min;
|
|
9
9
|
|
|
10
10
|
function next() {
|
|
11
11
|
if (lower > max) return max;
|
|
12
12
|
const upper = lower * factor;
|
|
13
|
-
const value = randomise
|
|
14
|
-
? Math.floor(Math.random() * (upper - lower + 1) + lower)
|
|
15
|
-
: lower;
|
|
13
|
+
const value = randomise ? Math.floor(Math.random() * (upper - lower + 1) + lower) : lower;
|
|
16
14
|
const capped = Math.min(max, value);
|
|
17
15
|
lower = upper;
|
|
18
16
|
return capped;
|