rascal 13.1.2 → 13.1.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.
- package/.husky/pre-commit +1 -1
- package/.prettierrc.json +1 -0
- package/CHANGELOG.md +195 -1
- package/README.md +630 -395
- package/examples/advanced/cluster.js +8 -8
- package/examples/advanced/config.js +117 -114
- package/examples/advanced/handlers/deleteUser.js +23 -17
- package/examples/advanced/handlers/saveUser.js +38 -32
- package/examples/advanced/index.js +105 -78
- package/examples/busy-publisher/config.js +14 -17
- package/examples/busy-publisher/index.js +27 -22
- package/examples/default-exchange/config.js +10 -10
- package/examples/default-exchange/index.js +27 -18
- package/examples/mocha/config.js +9 -11
- package/examples/mocha/test.js +42 -35
- package/examples/promises/config.js +11 -13
- package/examples/promises/index.js +24 -17
- package/examples/simple/config.js +16 -18
- package/examples/simple/index.js +25 -23
- package/index.js +7 -7
- package/lib/amqp/Broker.js +154 -99
- package/lib/amqp/BrokerAsPromised.js +56 -35
- package/lib/amqp/Publication.js +219 -78
- package/lib/amqp/PublicationSession.js +13 -14
- package/lib/amqp/SubscriberError.js +293 -132
- package/lib/amqp/SubscriberSession.js +95 -56
- package/lib/amqp/SubscriberSessionAsPromised.js +4 -6
- package/lib/amqp/Subscription.js +328 -109
- package/lib/amqp/Vhost.js +341 -170
- package/lib/amqp/tasks/applyBindings.js +51 -18
- package/lib/amqp/tasks/assertExchanges.js +20 -11
- package/lib/amqp/tasks/assertQueues.js +13 -9
- package/lib/amqp/tasks/assertVhost.js +21 -17
- package/lib/amqp/tasks/bounceVhost.js +1 -1
- package/lib/amqp/tasks/checkExchanges.js +13 -9
- package/lib/amqp/tasks/checkQueues.js +13 -9
- package/lib/amqp/tasks/checkVhost.js +21 -17
- package/lib/amqp/tasks/closeChannel.js +3 -4
- package/lib/amqp/tasks/closeConnection.js +3 -3
- package/lib/amqp/tasks/createChannel.js +3 -4
- package/lib/amqp/tasks/createConnection.js +71 -53
- package/lib/amqp/tasks/deleteExchanges.js +14 -10
- package/lib/amqp/tasks/deleteQueues.js +13 -9
- package/lib/amqp/tasks/deleteVhost.js +26 -17
- package/lib/amqp/tasks/forewarnVhost.js +1 -1
- package/lib/amqp/tasks/index.js +25 -25
- package/lib/amqp/tasks/initCounters.js +18 -13
- package/lib/amqp/tasks/initPublications.js +17 -13
- package/lib/amqp/tasks/initShovels.js +29 -20
- package/lib/amqp/tasks/initSubscriptions.js +23 -13
- package/lib/amqp/tasks/initVhosts.js +21 -17
- package/lib/amqp/tasks/nukeVhost.js +1 -1
- package/lib/amqp/tasks/purgeQueues.js +13 -9
- package/lib/amqp/tasks/purgeVhost.js +1 -1
- package/lib/amqp/tasks/shutdownVhost.js +1 -1
- package/lib/backoff/exponential.js +9 -8
- package/lib/backoff/index.js +3 -3
- package/lib/backoff/linear.js +5 -7
- package/lib/config/baseline.js +25 -35
- package/lib/config/configure.js +274 -101
- package/lib/config/fqn.js +3 -3
- package/lib/config/tests.js +32 -29
- package/lib/config/validate.js +460 -70
- package/lib/counters/inMemory.js +3 -3
- package/lib/counters/inMemoryCluster.js +48 -30
- package/lib/counters/index.js +4 -4
- package/lib/counters/stub.js +2 -3
- package/lib/management/client.js +47 -17
- package/lib/utils/setTimeoutUnref.js +1 -1
- package/package.json +12 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const cluster = require(
|
|
2
|
-
const inMemory = require(
|
|
3
|
-
const uuid = require(
|
|
4
|
-
const Stashback = require(
|
|
5
|
-
const debug =
|
|
1
|
+
const cluster = require("cluster");
|
|
2
|
+
const inMemory = require("./inMemory");
|
|
3
|
+
const uuid = require("uuid").v4;
|
|
4
|
+
const Stashback = require("stashback");
|
|
5
|
+
const debug = "rascal:counters:inMemoryCluster";
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
master: function master(options) {
|
|
@@ -10,49 +10,67 @@ module.exports = {
|
|
|
10
10
|
const counter = inMemory(options);
|
|
11
11
|
|
|
12
12
|
function handleMessage(worker, message) {
|
|
13
|
-
if (
|
|
13
|
+
if (
|
|
14
|
+
message.sender !== "rascal-in-memory-cluster-counter" ||
|
|
15
|
+
message.cmd !== "incrementAndGet"
|
|
16
|
+
)
|
|
17
|
+
return;
|
|
14
18
|
counter.incrementAndGet(message.key, (err, value) => {
|
|
15
|
-
worker.send({
|
|
19
|
+
worker.send({
|
|
20
|
+
sender: "rascal-in-memory-cluster-counter",
|
|
21
|
+
correlationId: message.correlationId,
|
|
22
|
+
value: err ? 1 : value,
|
|
23
|
+
});
|
|
16
24
|
});
|
|
17
25
|
}
|
|
18
26
|
|
|
19
|
-
cluster
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
cluster
|
|
28
|
+
.on("fork", (worker) => {
|
|
29
|
+
workers[worker.id] = worker;
|
|
30
|
+
worker.on("message", (message) => {
|
|
31
|
+
handleMessage(worker, message);
|
|
32
|
+
});
|
|
33
|
+
})
|
|
34
|
+
.on("disconnect", (worker) => {
|
|
35
|
+
delete workers[worker.id];
|
|
36
|
+
})
|
|
37
|
+
.on("exit", (worker) => {
|
|
38
|
+
delete workers[worker.id];
|
|
23
39
|
});
|
|
24
|
-
}).on('disconnect', (worker) => {
|
|
25
|
-
delete workers[worker.id];
|
|
26
|
-
}).on('exit', (worker) => {
|
|
27
|
-
delete workers[worker.id];
|
|
28
|
-
});
|
|
29
40
|
},
|
|
30
41
|
worker: function worker(options) {
|
|
31
|
-
if (!cluster.isWorker)
|
|
42
|
+
if (!cluster.isWorker)
|
|
43
|
+
throw new Error(
|
|
44
|
+
"You cannot use Rascal's in memmory cluster counter outside of a cluster"
|
|
45
|
+
);
|
|
32
46
|
if (!options) return worker({});
|
|
33
47
|
const timeout = options.timeout || 100;
|
|
34
48
|
const stashback = Stashback({ timeout });
|
|
35
49
|
|
|
36
|
-
process.on(
|
|
37
|
-
if (message.sender !==
|
|
50
|
+
process.on("message", (message) => {
|
|
51
|
+
if (message.sender !== "rascal-in-memory-cluster-counter") return;
|
|
38
52
|
stashback.unstash(message.correlationId, (err, cb) => {
|
|
39
53
|
err ? cb(null, 1) : cb(null, message.value);
|
|
40
54
|
});
|
|
41
55
|
});
|
|
42
56
|
|
|
43
57
|
return {
|
|
44
|
-
incrementAndGet
|
|
58
|
+
incrementAndGet(key, cb) {
|
|
45
59
|
const correlationId = uuid();
|
|
46
|
-
stashback.stash(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
stashback.stash(
|
|
61
|
+
correlationId,
|
|
62
|
+
(err, value) => {
|
|
63
|
+
err ? cb(null, 1) : cb(null, value);
|
|
64
|
+
},
|
|
65
|
+
(err) => {
|
|
66
|
+
if (err) return cb(null, 1);
|
|
67
|
+
process.send({
|
|
68
|
+
sender: "rascal-in-memory-cluster-counter",
|
|
69
|
+
correlationId,
|
|
70
|
+
cmd: "incrementAndGet",
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
);
|
|
56
74
|
},
|
|
57
75
|
};
|
|
58
76
|
},
|
package/lib/counters/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
stub: require(
|
|
3
|
-
inMemory: require(
|
|
4
|
-
inMemoryCluster: require(
|
|
5
|
-
};
|
|
2
|
+
stub: require("./stub"),
|
|
3
|
+
inMemory: require("./inMemory"),
|
|
4
|
+
inMemoryCluster: require("./inMemoryCluster"),
|
|
5
|
+
};
|
package/lib/counters/stub.js
CHANGED
package/lib/management/client.js
CHANGED
|
@@ -1,46 +1,76 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const format = require(
|
|
3
|
-
const _ = require(
|
|
4
|
-
const agent = require(
|
|
1
|
+
const debug = require("debug")("rascal:management:client");
|
|
2
|
+
const format = require("util").format;
|
|
3
|
+
const _ = require("lodash");
|
|
4
|
+
const agent = require("superagent");
|
|
5
5
|
|
|
6
6
|
function assertVhost(name, config, next) {
|
|
7
|
-
debug(
|
|
7
|
+
debug("Asserting vhost: %s", name);
|
|
8
8
|
const options = getVhostOptions(name, config);
|
|
9
|
-
request(
|
|
9
|
+
request("put", options.url, options.timeout, (err) => {
|
|
10
10
|
if (!err) return next();
|
|
11
11
|
const message = err.status
|
|
12
|
-
? format(
|
|
13
|
-
|
|
12
|
+
? format(
|
|
13
|
+
"Failed to assert vhost: %s. %s returned status %d",
|
|
14
|
+
name,
|
|
15
|
+
config.loggableUrl,
|
|
16
|
+
err.status
|
|
17
|
+
)
|
|
18
|
+
: format(
|
|
19
|
+
"Failed to assert vhost: %s. %s errored with: %s",
|
|
20
|
+
name,
|
|
21
|
+
config.loggableUrl,
|
|
22
|
+
err.message
|
|
23
|
+
);
|
|
14
24
|
return next(new Error(message));
|
|
15
25
|
});
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
function checkVhost(name, config, next) {
|
|
19
|
-
debug(
|
|
29
|
+
debug("Checking vhost: %s", name);
|
|
20
30
|
const options = getVhostOptions(name, config);
|
|
21
|
-
request(
|
|
31
|
+
request("get", options.url, options.timeout, (err) => {
|
|
22
32
|
if (!err) return next();
|
|
23
33
|
const message = err.status
|
|
24
|
-
? format(
|
|
25
|
-
|
|
34
|
+
? format(
|
|
35
|
+
"Failed to check vhost: %s. %s returned status %d",
|
|
36
|
+
name,
|
|
37
|
+
config.loggableUrl,
|
|
38
|
+
err.status
|
|
39
|
+
)
|
|
40
|
+
: format(
|
|
41
|
+
"Failed to check vhost: %s. %s errored with: %s",
|
|
42
|
+
name,
|
|
43
|
+
config.loggableUrl,
|
|
44
|
+
err.message
|
|
45
|
+
);
|
|
26
46
|
return next(new Error(message));
|
|
27
47
|
});
|
|
28
48
|
}
|
|
29
49
|
|
|
30
50
|
function deleteVhost(name, config, next) {
|
|
31
|
-
debug(
|
|
51
|
+
debug("Deleting vhost: %s", name);
|
|
32
52
|
const options = getVhostOptions(name, config);
|
|
33
|
-
request(
|
|
53
|
+
request("delete", options.url, options.timeout, (err) => {
|
|
34
54
|
if (!err) return next();
|
|
35
55
|
const message = err.status
|
|
36
|
-
? format(
|
|
37
|
-
|
|
56
|
+
? format(
|
|
57
|
+
"Failed to delete vhost: %s. %s returned status %d",
|
|
58
|
+
name,
|
|
59
|
+
config.loggableUrl,
|
|
60
|
+
err.status
|
|
61
|
+
)
|
|
62
|
+
: format(
|
|
63
|
+
"Failed to delete vhost: %s. %s errored with: %s",
|
|
64
|
+
name,
|
|
65
|
+
config.loggableUrl,
|
|
66
|
+
err.message
|
|
67
|
+
);
|
|
38
68
|
return next(new Error(message));
|
|
39
69
|
});
|
|
40
70
|
}
|
|
41
71
|
|
|
42
72
|
function getVhostOptions(name, config) {
|
|
43
|
-
const url = format(
|
|
73
|
+
const url = format("%s/%s/%s", config.url, "api/vhosts", name);
|
|
44
74
|
return _.defaultsDeep({ url }, config.options);
|
|
45
75
|
}
|
|
46
76
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rascal",
|
|
3
|
-
"version": "13.1.
|
|
3
|
+
"version": "13.1.3",
|
|
4
4
|
"description": "A config driven wrapper for amqplib supporting multi-host connections, automatic error recovery, redelivery flood protection, transparent encryption / decryption, channel pooling and publication timeouts",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"async": "^3.2.
|
|
7
|
+
"async": "^3.2.1",
|
|
8
8
|
"debug": "^4.1.1",
|
|
9
9
|
"deep-freeze": "0.0.1",
|
|
10
10
|
"forward-emitter": "^0.1.1",
|
|
@@ -21,10 +21,13 @@
|
|
|
21
21
|
"amqplib": "^0.8.0",
|
|
22
22
|
"chalk": "^4.0.0",
|
|
23
23
|
"chance": "^1.1.4",
|
|
24
|
-
"eslint": "^
|
|
25
|
-
"eslint-config-
|
|
24
|
+
"eslint": "^7.32.0",
|
|
25
|
+
"eslint-config-prettier": "^8.3.0",
|
|
26
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
26
27
|
"husky": "^6.0.0",
|
|
28
|
+
"lint-staged": "^11.2.4",
|
|
27
29
|
"nyc": "^15.1.0",
|
|
30
|
+
"prettier": "2.4.1",
|
|
28
31
|
"random-readable": "^1.0.1",
|
|
29
32
|
"zunit": "^3.0.8"
|
|
30
33
|
},
|
|
@@ -36,11 +39,16 @@
|
|
|
36
39
|
},
|
|
37
40
|
"scripts": {
|
|
38
41
|
"test": "zUnit",
|
|
42
|
+
"prettier": "prettier --check .",
|
|
39
43
|
"lint": "eslint .",
|
|
44
|
+
"lint-staged": "lint-staged",
|
|
40
45
|
"coverage": "nyc --report html --reporter lcov --reporter text-summary zUnit",
|
|
41
46
|
"docker": "docker run -d --name rascal-rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management",
|
|
42
47
|
"prepare": "husky install"
|
|
43
48
|
},
|
|
49
|
+
"lint-staged": {
|
|
50
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
51
|
+
},
|
|
44
52
|
"keywords": [
|
|
45
53
|
"amqplib",
|
|
46
54
|
"amqp",
|