rascal 13.1.3 → 14.2.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 +23 -0
- package/README.md +200 -209
- 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.json +40 -0
- package/examples/busy-publisher/index.js +14 -20
- package/examples/default-exchange/config.json +25 -0
- package/examples/default-exchange/index.js +10 -15
- package/examples/mocha/config.json +21 -0
- package/examples/mocha/test.js +16 -24
- package/examples/promises/config.json +27 -0
- package/examples/promises/index.js +9 -14
- package/examples/simple/config.json +37 -0
- package/examples/simple/index.js +11 -15
- package/index.js +6 -6
- package/lib/amqp/Broker.js +65 -95
- 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 +120 -265
- 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 +6 -4
- package/lib/amqp/tasks/checkExchanges.js +4 -4
- package/lib/amqp/tasks/checkQueues.js +4 -4
- package/lib/amqp/tasks/checkVhost.js +6 -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 +12 -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 +8 -8
- 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/schema.json +686 -0
- 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 +55 -0
- package/package.json +2 -1
- package/examples/busy-publisher/config.js +0 -39
- package/examples/default-exchange/config.js +0 -24
- package/examples/mocha/config.js +0 -20
- package/examples/promises/config.js +0 -26
- package/examples/simple/config.js +0 -36
- package/lib/management/client.js +0 -90
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
var Rascal = require(
|
|
2
|
-
var cluster = require(
|
|
1
|
+
var Rascal = require('../..');
|
|
2
|
+
var cluster = require('cluster');
|
|
3
3
|
|
|
4
4
|
if (cluster.isMaster) {
|
|
5
5
|
Rascal.counters.inMemoryCluster.master();
|
|
6
6
|
cluster.fork();
|
|
7
|
-
cluster.on(
|
|
7
|
+
cluster.on('exit', function () {
|
|
8
8
|
cluster.fork();
|
|
9
9
|
});
|
|
10
10
|
} else {
|
|
11
|
-
require(
|
|
11
|
+
require('./index');
|
|
12
12
|
}
|
|
@@ -2,7 +2,7 @@ module.exports = {
|
|
|
2
2
|
rascal: {
|
|
3
3
|
vhosts: {
|
|
4
4
|
// Define the name of the vhost
|
|
5
|
-
|
|
5
|
+
'customer-vhost': {
|
|
6
6
|
// Creates the vhost if it doesn't exist (requires the RabbitMQ management plugin to be installed)
|
|
7
7
|
assert: true,
|
|
8
8
|
|
|
@@ -10,11 +10,11 @@ module.exports = {
|
|
|
10
10
|
// Rascal will randomise the list, and cycle through the entries until it finds one that works
|
|
11
11
|
connections: [
|
|
12
12
|
{
|
|
13
|
-
url:
|
|
13
|
+
url: 'amqp://does-not-exist-1b9935d9-5066-4b13-84dc-a8e2bb618154:5672/customer-vhost',
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
user:
|
|
17
|
-
password:
|
|
16
|
+
user: 'guest',
|
|
17
|
+
password: 'guest',
|
|
18
18
|
port: 5672,
|
|
19
19
|
options: {
|
|
20
20
|
heartbeat: 1,
|
|
@@ -27,94 +27,89 @@ module.exports = {
|
|
|
27
27
|
|
|
28
28
|
// Define exchanges within the registration vhost
|
|
29
29
|
exchanges: [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
'service', // Shared exchange for all services within this vhost
|
|
31
|
+
'delay', // To delay failed messages before a retry
|
|
32
|
+
'retry', // To retry failed messages up to maximum number of times
|
|
33
|
+
'dead_letters', // When retrying fails, messages end up here
|
|
34
34
|
],
|
|
35
35
|
|
|
36
36
|
// Define queues within the registration vhost
|
|
37
37
|
// A good naming convention for queues is consumer:entity:action
|
|
38
38
|
queues: {
|
|
39
39
|
// Create a queue for saving users
|
|
40
|
-
|
|
40
|
+
'registration_service:user:save': {
|
|
41
41
|
options: {
|
|
42
42
|
arguments: {
|
|
43
43
|
// Route nacked messages to a service specific dead letter queue
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
'x-dead-letter-exchange': 'dead_letters',
|
|
45
|
+
'x-dead-letter-routing-key': 'registration_service.dead_letter',
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
49
|
|
|
50
50
|
// Create a queue for deleting users
|
|
51
|
-
|
|
51
|
+
'registration_service:user:delete': {
|
|
52
52
|
options: {
|
|
53
53
|
arguments: {
|
|
54
54
|
// Route nacked messages to a service specific dead letter queue
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
'x-dead-letter-exchange': 'dead_letters',
|
|
56
|
+
'x-dead-letter-routing-key': 'registration_service.dead_letter',
|
|
57
57
|
},
|
|
58
58
|
},
|
|
59
59
|
},
|
|
60
60
|
|
|
61
61
|
// Create a delay queue to hold failed messages for a short interval before retrying
|
|
62
|
-
|
|
62
|
+
'delay:1m': {
|
|
63
63
|
options: {
|
|
64
64
|
arguments: {
|
|
65
65
|
// Configure messages to expire after 1 minute, then route them to the retry exchange
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
'x-message-ttl': 60000,
|
|
67
|
+
'x-dead-letter-exchange': 'retry',
|
|
68
68
|
},
|
|
69
69
|
},
|
|
70
70
|
},
|
|
71
71
|
|
|
72
72
|
// Queue for holding dead letters until they can be resolved
|
|
73
|
-
|
|
73
|
+
'dead_letters:registration_service': {},
|
|
74
74
|
},
|
|
75
75
|
|
|
76
76
|
// Bind the queues to the exchanges.
|
|
77
77
|
// A good naming convention for routing keys is producer.entity.event
|
|
78
78
|
bindings: {
|
|
79
79
|
// Route create/update user messages to the save queue
|
|
80
|
-
|
|
81
|
-
{},
|
|
80
|
+
'service[registration_webapp.user.created.#,registration_webapp.user.updated.#] -> registration_service:user:save': {},
|
|
82
81
|
|
|
83
82
|
// Route delete user messages to the delete queue
|
|
84
|
-
|
|
85
|
-
{},
|
|
83
|
+
'service[registration_webapp.user.deleted.#] -> registration_service:user:delete': {},
|
|
86
84
|
|
|
87
85
|
// Route delayed messages to the 1 minute delay queue
|
|
88
|
-
|
|
86
|
+
'delay[delay.1m] -> delay:1m': {},
|
|
89
87
|
|
|
90
88
|
// Route retried messages back to their original queue using the CC routing keys set by Rascal
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"retry[registration_service:user:delete.#] -> registration_service:user:delete":
|
|
94
|
-
{},
|
|
89
|
+
'retry[registration_service:user:save.#] -> registration_service:user:save': {},
|
|
90
|
+
'retry[registration_service:user:delete.#] -> registration_service:user:delete': {},
|
|
95
91
|
|
|
96
92
|
// Route dead letters the service specific dead letter queue
|
|
97
|
-
|
|
98
|
-
{},
|
|
93
|
+
'dead_letters[registration_service.dead_letter] -> dead_letters:registration_service': {},
|
|
99
94
|
},
|
|
100
95
|
|
|
101
96
|
// Setup subscriptions
|
|
102
97
|
subscriptions: {
|
|
103
98
|
save_user: {
|
|
104
|
-
queue:
|
|
105
|
-
handler:
|
|
99
|
+
queue: 'registration_service:user:save',
|
|
100
|
+
handler: 'saveUser.js',
|
|
106
101
|
redeliveries: {
|
|
107
102
|
limit: 5,
|
|
108
|
-
counter:
|
|
103
|
+
counter: 'shared',
|
|
109
104
|
},
|
|
110
105
|
},
|
|
111
106
|
|
|
112
107
|
delete_user: {
|
|
113
|
-
queue:
|
|
114
|
-
handler:
|
|
108
|
+
queue: 'registration_service:user:delete',
|
|
109
|
+
handler: 'deleteUser.js',
|
|
115
110
|
redeliveries: {
|
|
116
111
|
limit: 5,
|
|
117
|
-
counter:
|
|
112
|
+
counter: 'shared',
|
|
118
113
|
},
|
|
119
114
|
},
|
|
120
115
|
},
|
|
@@ -123,29 +118,29 @@ module.exports = {
|
|
|
123
118
|
publications: {
|
|
124
119
|
// Always publish a notification of success (it's useful for testing if nothing else)
|
|
125
120
|
save_user_succeeded: {
|
|
126
|
-
exchange:
|
|
121
|
+
exchange: 'service',
|
|
127
122
|
},
|
|
128
123
|
delete_user_succeeded: {
|
|
129
|
-
exchange:
|
|
130
|
-
encryption:
|
|
124
|
+
exchange: 'service',
|
|
125
|
+
encryption: 'well-known-v1',
|
|
131
126
|
},
|
|
132
127
|
|
|
133
128
|
// Forward messages to the 1 minute delay queue when retrying
|
|
134
129
|
retry_in_1m: {
|
|
135
|
-
exchange:
|
|
130
|
+
exchange: 'delay',
|
|
136
131
|
options: {
|
|
137
|
-
CC: [
|
|
132
|
+
CC: ['delay.1m'],
|
|
138
133
|
},
|
|
139
134
|
},
|
|
140
135
|
|
|
141
136
|
// Publication for generating user create, update and delete messages
|
|
142
137
|
// This would probably be the job of another application (e.g. a web application)
|
|
143
138
|
user_event: {
|
|
144
|
-
exchange:
|
|
139
|
+
exchange: 'service',
|
|
145
140
|
// Specifying an encryption profile in the publication will cause the message content to be encrypted
|
|
146
141
|
// The profile name and iv are added as headers, and used to automatically decrypt messages,
|
|
147
142
|
// providing the consumer configuration has a matching profile.
|
|
148
|
-
encryption:
|
|
143
|
+
encryption: 'well-known-v1',
|
|
149
144
|
},
|
|
150
145
|
},
|
|
151
146
|
|
|
@@ -166,13 +161,13 @@ module.exports = {
|
|
|
166
161
|
// Deferred retry is a good strategy for temporary (connection timeout) or unknown errors
|
|
167
162
|
deferred_retry: [
|
|
168
163
|
{
|
|
169
|
-
strategy:
|
|
164
|
+
strategy: 'forward',
|
|
170
165
|
attempts: 10,
|
|
171
|
-
publication:
|
|
166
|
+
publication: 'retry_in_1m',
|
|
172
167
|
xDeathFix: true, // See https://github.com/rabbitmq/rabbitmq-server/issues/161
|
|
173
168
|
},
|
|
174
169
|
{
|
|
175
|
-
strategy:
|
|
170
|
+
strategy: 'nack',
|
|
176
171
|
},
|
|
177
172
|
],
|
|
178
173
|
|
|
@@ -181,7 +176,7 @@ module.exports = {
|
|
|
181
176
|
// causing it to be routed to the services dead letter queue
|
|
182
177
|
dead_letter: [
|
|
183
178
|
{
|
|
184
|
-
strategy:
|
|
179
|
+
strategy: 'republish',
|
|
185
180
|
immediateNack: true,
|
|
186
181
|
},
|
|
187
182
|
],
|
|
@@ -191,16 +186,16 @@ module.exports = {
|
|
|
191
186
|
counters: {
|
|
192
187
|
shared: {
|
|
193
188
|
size: 10,
|
|
194
|
-
type:
|
|
189
|
+
type: 'inMemoryCluster',
|
|
195
190
|
},
|
|
196
191
|
},
|
|
197
192
|
},
|
|
198
193
|
// Define encryption profiles
|
|
199
194
|
encryption: {
|
|
200
|
-
|
|
201
|
-
key:
|
|
195
|
+
'well-known-v1': {
|
|
196
|
+
key: 'f81db52a3b2c717fe65d9a3b7dd04d2a08793e1a28e3083db3ea08db56e7c315',
|
|
202
197
|
ivLength: 16,
|
|
203
|
-
algorithm:
|
|
198
|
+
algorithm: 'aes-256-cbc',
|
|
204
199
|
},
|
|
205
200
|
},
|
|
206
201
|
},
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
var chalk = require(
|
|
2
|
-
var format = require(
|
|
1
|
+
var chalk = require('chalk');
|
|
2
|
+
var format = require('util').format;
|
|
3
3
|
|
|
4
4
|
module.exports = function (broker) {
|
|
5
5
|
return function (user, cb) {
|
|
6
6
|
// Pretend we'd really asynchronously deleted something
|
|
7
7
|
setImmediate(function () {
|
|
8
|
-
console.log(chalk.cyan(
|
|
8
|
+
console.log(chalk.cyan('Deleting user:'), user.username);
|
|
9
9
|
|
|
10
|
-
if (user.crash) throw new Error(
|
|
10
|
+
if (user.crash) throw new Error('Crashing on user: ' + user.username);
|
|
11
11
|
|
|
12
|
-
var routingKey = format(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"delete_user_succeeded",
|
|
18
|
-
routingKey,
|
|
19
|
-
function (err, publication) {
|
|
20
|
-
if (err) return cb(err);
|
|
21
|
-
publication.on("success", () => cb).on("error", console.error);
|
|
22
|
-
}
|
|
23
|
-
);
|
|
12
|
+
var routingKey = format('registration_service.user.deleted.%s', user.username);
|
|
13
|
+
broker.publish('delete_user_succeeded', routingKey, function (err, publication) {
|
|
14
|
+
if (err) return cb(err);
|
|
15
|
+
publication.on('success', () => cb).on('error', console.error);
|
|
16
|
+
});
|
|
24
17
|
});
|
|
25
18
|
};
|
|
26
19
|
};
|
|
@@ -1,40 +1,33 @@
|
|
|
1
|
-
var chalk = require(
|
|
2
|
-
var format = require(
|
|
1
|
+
var chalk = require('chalk');
|
|
2
|
+
var format = require('util').format;
|
|
3
3
|
|
|
4
4
|
module.exports = function (broker) {
|
|
5
5
|
return function (user, cb) {
|
|
6
6
|
// Pretend we'd really asynchronously saved something
|
|
7
7
|
setImmediate(function () {
|
|
8
|
-
console.log(chalk.magenta(
|
|
8
|
+
console.log(chalk.magenta('Saving user:'), user.username);
|
|
9
9
|
|
|
10
|
-
if (user.crash) throw new Error(
|
|
10
|
+
if (user.crash) throw new Error('Crashing on user: ' + user.username);
|
|
11
11
|
|
|
12
12
|
// Simulate errors and success
|
|
13
13
|
var err;
|
|
14
14
|
switch (Math.floor(Math.random() * 10)) {
|
|
15
15
|
case 5: {
|
|
16
|
-
err = new Error(
|
|
16
|
+
err = new Error('Connection Timeout');
|
|
17
17
|
err.recoverable = true;
|
|
18
18
|
return cb(err);
|
|
19
19
|
}
|
|
20
20
|
case 7: {
|
|
21
|
-
err = new Error(
|
|
21
|
+
err = new Error('Duplicate Key Violation');
|
|
22
22
|
err.recoverable = false;
|
|
23
23
|
return cb(err);
|
|
24
24
|
}
|
|
25
25
|
default: {
|
|
26
|
-
var routingKey = format(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"save_user_succeeded",
|
|
32
|
-
routingKey,
|
|
33
|
-
function (err, publication) {
|
|
34
|
-
if (err) return cb(err);
|
|
35
|
-
publication.on("success", () => cb).on("error", console.error);
|
|
36
|
-
}
|
|
37
|
-
);
|
|
26
|
+
var routingKey = format('registration_service.user.saved.%s', user.username);
|
|
27
|
+
broker.publish('save_user_succeeded', routingKey, function (err, publication) {
|
|
28
|
+
if (err) return cb(err);
|
|
29
|
+
publication.on('success', () => cb).on('error', console.error);
|
|
30
|
+
});
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
33
|
});
|
|
@@ -1,117 +1,95 @@
|
|
|
1
|
-
var Rascal = require(
|
|
2
|
-
var config = require(
|
|
3
|
-
var _ = require(
|
|
4
|
-
var Chance = require(
|
|
1
|
+
var Rascal = require('../..');
|
|
2
|
+
var config = require('./config');
|
|
3
|
+
var _ = require('lodash');
|
|
4
|
+
var Chance = require('Chance');
|
|
5
5
|
var chance = new Chance();
|
|
6
|
-
var format = require(
|
|
6
|
+
var format = require('util').format;
|
|
7
7
|
|
|
8
|
-
Rascal.Broker.create(
|
|
9
|
-
|
|
10
|
-
function (err, broker) {
|
|
11
|
-
if (err) bail(err);
|
|
8
|
+
Rascal.Broker.create(Rascal.withDefaultConfig(config.rascal), function (err, broker) {
|
|
9
|
+
if (err) bail(err);
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
broker.on('error', function (err) {
|
|
12
|
+
console.error(err.message);
|
|
13
|
+
});
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
function (subscriptionConfig, subscriptionName) {
|
|
20
|
-
if (!subscriptionConfig.handler) return;
|
|
15
|
+
_.each(broker.config.subscriptions, function (subscriptionConfig, subscriptionName) {
|
|
16
|
+
if (!subscriptionConfig.handler) return;
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
broker
|
|
24
|
-
);
|
|
18
|
+
var handler = require('./handlers/' + subscriptionConfig.handler)(broker);
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
.on("cancel", function (err) {
|
|
50
|
-
console.warn(err.message);
|
|
51
|
-
})
|
|
52
|
-
.on("error", function (err) {
|
|
53
|
-
console.error(err.message);
|
|
54
|
-
});
|
|
20
|
+
broker.subscribe(subscriptionName, function (err, subscription) {
|
|
21
|
+
if (err) return bail(err);
|
|
22
|
+
subscription
|
|
23
|
+
.on('message', function (message, content, ackOrNack) {
|
|
24
|
+
handler(content, function (err) {
|
|
25
|
+
if (!err) return ackOrNack();
|
|
26
|
+
console.log(err);
|
|
27
|
+
ackOrNack(err, err.recoverable ? broker.config.recovery.deferred_retry : broker.config.recovery.dead_letter);
|
|
28
|
+
});
|
|
29
|
+
})
|
|
30
|
+
.on('invalid_content', function (err, message, ackOrNack) {
|
|
31
|
+
console.error('Invalid Content', err.message);
|
|
32
|
+
ackOrNack(err, broker.config.recovery.dead_letter);
|
|
33
|
+
})
|
|
34
|
+
.on('redeliveries_exceeded', function (err, message, ackOrNack) {
|
|
35
|
+
console.error('Redeliveries Exceeded', err.message);
|
|
36
|
+
ackOrNack(err, broker.config.recovery.dead_letter);
|
|
37
|
+
})
|
|
38
|
+
.on('cancel', function (err) {
|
|
39
|
+
console.warn(err.message);
|
|
40
|
+
})
|
|
41
|
+
.on('error', function (err) {
|
|
42
|
+
console.error(err.message);
|
|
55
43
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// Simulate a web app handling user registrations
|
|
60
|
-
setInterval(function () {
|
|
61
|
-
var user = {
|
|
62
|
-
username: chance.first() + "_" + chance.last(),
|
|
63
|
-
crash: randomInt(10) === 10,
|
|
64
|
-
};
|
|
65
|
-
var events = { 1: "created", 2: "updated", 3: "deleted" };
|
|
66
|
-
var event = events[randomInt(3)];
|
|
67
|
-
var routingKey = format(
|
|
68
|
-
"registration_webapp.user.%s.%s",
|
|
69
|
-
event,
|
|
70
|
-
user.username
|
|
71
|
-
);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
72
46
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
})
|
|
83
|
-
.on("error", function (err) {
|
|
84
|
-
console.error(err.message);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
}, 1000);
|
|
47
|
+
// Simulate a web app handling user registrations
|
|
48
|
+
setInterval(function () {
|
|
49
|
+
var user = {
|
|
50
|
+
username: chance.first() + '_' + chance.last(),
|
|
51
|
+
crash: randomInt(10) === 10,
|
|
52
|
+
};
|
|
53
|
+
var events = { 1: 'created', 2: 'updated', 3: 'deleted' };
|
|
54
|
+
var event = events[randomInt(3)];
|
|
55
|
+
var routingKey = format('registration_webapp.user.%s.%s', event, user.username);
|
|
89
56
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
process.exit();
|
|
99
|
-
});
|
|
100
|
-
})
|
|
101
|
-
.on("unhandledRejection", (reason, p) => {
|
|
102
|
-
console.error(reason, "Unhandled Rejection at Promise", p);
|
|
103
|
-
broker.shutdown(function () {
|
|
104
|
-
process.exit(-1);
|
|
105
|
-
});
|
|
106
|
-
})
|
|
107
|
-
.on("uncaughtException", (err) => {
|
|
108
|
-
console.error(err, "Uncaught Exception thrown");
|
|
109
|
-
broker.shutdown(function () {
|
|
110
|
-
process.exit(-2);
|
|
57
|
+
broker.publish('user_event', user, routingKey, function (err, publication) {
|
|
58
|
+
if (err) return console.log(err.message);
|
|
59
|
+
publication
|
|
60
|
+
.on('success', function () {
|
|
61
|
+
// confirmed
|
|
62
|
+
})
|
|
63
|
+
.on('error', function (err) {
|
|
64
|
+
console.error(err.message);
|
|
111
65
|
});
|
|
66
|
+
});
|
|
67
|
+
}, 1000);
|
|
68
|
+
|
|
69
|
+
process
|
|
70
|
+
.on('SIGINT', function () {
|
|
71
|
+
broker.shutdown(function () {
|
|
72
|
+
process.exit();
|
|
73
|
+
});
|
|
74
|
+
})
|
|
75
|
+
.on('SIGTERM', () => {
|
|
76
|
+
broker.shutdown(function () {
|
|
77
|
+
process.exit();
|
|
112
78
|
});
|
|
113
|
-
|
|
114
|
-
)
|
|
79
|
+
})
|
|
80
|
+
.on('unhandledRejection', (reason, p) => {
|
|
81
|
+
console.error(reason, 'Unhandled Rejection at Promise', p);
|
|
82
|
+
broker.shutdown(function () {
|
|
83
|
+
process.exit(-1);
|
|
84
|
+
});
|
|
85
|
+
})
|
|
86
|
+
.on('uncaughtException', (err) => {
|
|
87
|
+
console.error(err, 'Uncaught Exception thrown');
|
|
88
|
+
broker.shutdown(function () {
|
|
89
|
+
process.exit(-2);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
115
93
|
|
|
116
94
|
function randomInt(max) {
|
|
117
95
|
return Math.floor(Math.random() * max) + 1;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../lib/config/schema.json",
|
|
3
|
+
"vhosts": {
|
|
4
|
+
"/": {
|
|
5
|
+
"publicationChannelPools": {
|
|
6
|
+
"confirmPool": {
|
|
7
|
+
"max": 10,
|
|
8
|
+
"min": 10,
|
|
9
|
+
"evictionRunIntervalMillis": 1000,
|
|
10
|
+
"idleTimeoutMillis": 5000,
|
|
11
|
+
"autostart": true
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"connection": {
|
|
15
|
+
"heartbeat": 5,
|
|
16
|
+
"socketOptions": {
|
|
17
|
+
"timeout": 1000
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"exchanges": ["demo_ex"],
|
|
21
|
+
"queues": ["demo_q"],
|
|
22
|
+
"bindings": ["demo_ex[a.b.c] -> demo_q"],
|
|
23
|
+
"publications": {
|
|
24
|
+
"demo_pub": {
|
|
25
|
+
"exchange": "demo_ex",
|
|
26
|
+
"routingKey": "a.b.c",
|
|
27
|
+
"confirm": false,
|
|
28
|
+
"options": {
|
|
29
|
+
"persistent": false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"subscriptions": {
|
|
34
|
+
"demo_sub": {
|
|
35
|
+
"queue": "demo_q"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,38 +1,32 @@
|
|
|
1
|
-
const Rascal = require(
|
|
2
|
-
const config = require(
|
|
3
|
-
const random = require(
|
|
1
|
+
const Rascal = require('../..');
|
|
2
|
+
const config = require('./config');
|
|
3
|
+
const random = require('random-readable');
|
|
4
4
|
|
|
5
5
|
Rascal.Broker.create(Rascal.withDefaultConfig(config), (err, broker) => {
|
|
6
6
|
if (err) throw err;
|
|
7
7
|
|
|
8
|
-
broker.on(
|
|
8
|
+
broker.on('error', console.error);
|
|
9
9
|
|
|
10
10
|
const stream = random
|
|
11
11
|
.createRandomStream()
|
|
12
|
-
.on(
|
|
13
|
-
.on(
|
|
14
|
-
broker.publish(
|
|
12
|
+
.on('error', console.error)
|
|
13
|
+
.on('data', (data) => {
|
|
14
|
+
broker.publish('demo_pub', data, (err, publication) => {
|
|
15
15
|
if (err) throw err;
|
|
16
|
-
publication.on(
|
|
16
|
+
publication.on('error', console.error);
|
|
17
17
|
});
|
|
18
18
|
})
|
|
19
|
-
.on(
|
|
20
|
-
console.log(
|
|
19
|
+
.on('end', () => {
|
|
20
|
+
console.log('end');
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
broker.on(
|
|
24
|
-
console.log(
|
|
25
|
-
Date.now(),
|
|
26
|
-
`Pausing vhost: ${details.vhost} (mode: ${details.mode}, queue: ${details.queue}, size: ${details.size}, borrowed: ${details.borrowed}, available: ${details.available})`
|
|
27
|
-
);
|
|
23
|
+
broker.on('busy', (details) => {
|
|
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
25
|
stream.pause();
|
|
29
26
|
});
|
|
30
27
|
|
|
31
|
-
broker.on(
|
|
32
|
-
console.log(
|
|
33
|
-
Date.now(),
|
|
34
|
-
`Resuming vhost: ${details.vhost} (mode: ${details.mode}, queue: ${details.queue}, size: ${details.size}, borrowed: ${details.borrowed}, available: ${details.available})`
|
|
35
|
-
);
|
|
28
|
+
broker.on('ready', (details) => {
|
|
29
|
+
console.log(Date.now(), `Resuming vhost: ${details.vhost} (mode: ${details.mode}, queue: ${details.queue}, size: ${details.size}, borrowed: ${details.borrowed}, available: ${details.available})`);
|
|
36
30
|
stream.resume();
|
|
37
31
|
});
|
|
38
32
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "../../lib/config/schema.json",
|
|
3
|
+
"vhosts": {
|
|
4
|
+
"/": {
|
|
5
|
+
"connection": {
|
|
6
|
+
"heartbeat": 1,
|
|
7
|
+
"socketOptions": {
|
|
8
|
+
"timeout": 1000
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"exchanges": [""],
|
|
12
|
+
"queues": ["demo_q"],
|
|
13
|
+
"publications": {
|
|
14
|
+
"demo_pub": {
|
|
15
|
+
"exchange": ""
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"subscriptions": {
|
|
19
|
+
"demo_sub": {
|
|
20
|
+
"queue": "demo_q"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|