rascal 13.0.6 → 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 +204 -1
- package/README.md +634 -396
- 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 +18 -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 -110
- package/lib/amqp/Vhost.js +366 -171
- 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 -51
- 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 +26 -34
- 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
package/lib/config/configure.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
const debug = require(
|
|
2
|
-
const format = require(
|
|
3
|
-
const url = require(
|
|
4
|
-
const _ = require(
|
|
5
|
-
const uuid = require(
|
|
6
|
-
const baseline = require(
|
|
7
|
-
const fqn = require(
|
|
8
|
-
const XRegExp = require(
|
|
9
|
-
const freeze = require(
|
|
1
|
+
const debug = require("debug")("rascal:config:configure");
|
|
2
|
+
const format = require("util").format;
|
|
3
|
+
const url = require("url");
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
const uuid = require("uuid").v4;
|
|
6
|
+
const baseline = require("./baseline");
|
|
7
|
+
const fqn = require("./fqn");
|
|
8
|
+
const XRegExp = require("xregexp");
|
|
9
|
+
const freeze = require("deep-freeze");
|
|
10
10
|
|
|
11
11
|
module.exports = _.curry((rascalConfig, next) => {
|
|
12
|
-
|
|
13
12
|
rascalConfig = _.defaultsDeep(rascalConfig, baseline);
|
|
14
13
|
|
|
15
14
|
let err;
|
|
@@ -21,11 +20,11 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
21
20
|
configureSubscriptions(rascalConfig.subscriptions, rascalConfig.vhosts);
|
|
22
21
|
configureShovels(rascalConfig.shovels);
|
|
23
22
|
configureCounters(rascalConfig.redeliveries.counters);
|
|
24
|
-
} catch(_err) {
|
|
23
|
+
} catch (_err) {
|
|
25
24
|
err = _err;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
return err ? next(err) :next(null, freeze(rascalConfig));
|
|
27
|
+
return err ? next(err) : next(null, freeze(rascalConfig));
|
|
29
28
|
|
|
30
29
|
function configureVhosts(vhosts) {
|
|
31
30
|
_.each(vhosts, (vhostConfig, name) => {
|
|
@@ -39,54 +38,78 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
function configureVhost(name, vhostConfig) {
|
|
42
|
-
debug(
|
|
43
|
-
rascalConfig.vhosts[name] = _.defaultsDeep(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
debug("Configuring vhost: %s", name);
|
|
42
|
+
rascalConfig.vhosts[name] = _.defaultsDeep(
|
|
43
|
+
vhostConfig,
|
|
44
|
+
{
|
|
45
|
+
name,
|
|
46
|
+
namespace: rascalConfig.defaults.vhosts.namespace,
|
|
47
|
+
connectionStrategy: rascalConfig.defaults.vhosts.connectionStrategy,
|
|
48
|
+
publicationChannelPools:
|
|
49
|
+
rascalConfig.defaults.vhosts.publicationChannelPools,
|
|
50
|
+
},
|
|
51
|
+
{ defaults: rascalConfig.defaults.vhosts }
|
|
52
|
+
);
|
|
53
|
+
rascalConfig.vhosts[name].namespace =
|
|
54
|
+
vhostConfig.namespace === true ? uuid() : vhostConfig.namespace;
|
|
50
55
|
configureConnections(vhostConfig, name);
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
function configureConnections(vhostConfig, vhostName) {
|
|
54
|
-
vhostConfig.connections = _.chain([])
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
vhostConfig.connections = _.chain([])
|
|
60
|
+
.concat(vhostConfig.connections, vhostConfig.connection)
|
|
61
|
+
.compact()
|
|
62
|
+
.uniq()
|
|
63
|
+
.map((connection) => {
|
|
64
|
+
return _.isString(connection) ? { url: connection } : connection;
|
|
65
|
+
})
|
|
66
|
+
.value();
|
|
57
67
|
if (vhostConfig.connections.length === 0) vhostConfig.connections.push({});
|
|
58
68
|
_.each(vhostConfig.connections, (connection, index) => {
|
|
59
69
|
configureConnection(vhostConfig, vhostName, connection, index);
|
|
60
70
|
});
|
|
61
|
-
vhostConfig.connections = _.sortBy(vhostConfig.connections,
|
|
71
|
+
vhostConfig.connections = _.sortBy(vhostConfig.connections, "index");
|
|
62
72
|
delete vhostConfig.connection;
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
function configureConnection(vhostConfig, vhostName, connection, index) {
|
|
66
76
|
_.defaultsDeep(connection, vhostConfig.defaults.connection);
|
|
67
|
-
connection.vhost =
|
|
68
|
-
|
|
69
|
-
connection.
|
|
77
|
+
connection.vhost =
|
|
78
|
+
connection.vhost !== undefined ? connection.vhost : vhostName;
|
|
79
|
+
connection.auth =
|
|
80
|
+
connection.auth || getAuth(connection.user, connection.password);
|
|
81
|
+
connection.pathname = connection.vhost === "/" ? "" : connection.vhost;
|
|
70
82
|
connection.query = connection.options;
|
|
71
83
|
connection.url = connection.url || url.format(connection);
|
|
72
|
-
connection.loggableUrl = connection.url.replace(/:[^:]*?@/,
|
|
73
|
-
connection.index = getConnectionIndex(
|
|
84
|
+
connection.loggableUrl = connection.url.replace(/:[^:]*?@/, ":***@");
|
|
85
|
+
connection.index = getConnectionIndex(
|
|
86
|
+
vhostConfig.connectionStrategy,
|
|
87
|
+
connection,
|
|
88
|
+
index
|
|
89
|
+
);
|
|
74
90
|
configureManagementConnection(vhostConfig, vhostName, connection);
|
|
75
91
|
}
|
|
76
92
|
|
|
77
93
|
function configureManagementConnection(vhostConfig, vhostName, connection) {
|
|
78
94
|
_.defaultsDeep(connection.management, { hostname: connection.hostname });
|
|
79
|
-
connection.management.auth =
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
connection.management.auth =
|
|
96
|
+
connection.management.auth ||
|
|
97
|
+
getAuth(connection.management.user, connection.management.password) ||
|
|
98
|
+
connection.auth;
|
|
99
|
+
connection.management.url =
|
|
100
|
+
connection.management.url || url.format(connection.management);
|
|
101
|
+
connection.management.loggableUrl = connection.management.url.replace(
|
|
102
|
+
/:[^:]*?@/,
|
|
103
|
+
":***@"
|
|
104
|
+
);
|
|
82
105
|
}
|
|
83
106
|
|
|
84
107
|
function getAuth(user, password) {
|
|
85
|
-
return user && password ? user +
|
|
108
|
+
return user && password ? user + ":" + password : undefined;
|
|
86
109
|
}
|
|
87
110
|
|
|
88
111
|
function getConnectionIndex(strategy, connection, index) {
|
|
89
|
-
if (strategy ===
|
|
112
|
+
if (strategy === "fixed") return index;
|
|
90
113
|
const host = url.parse(connection.url).host;
|
|
91
114
|
if (_.has(connectionIndexes, host)) return connectionIndexes[host];
|
|
92
115
|
connectionIndexes[host] = Math.random();
|
|
@@ -102,33 +125,76 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
102
125
|
}
|
|
103
126
|
|
|
104
127
|
function configurePublications(publications, vhosts) {
|
|
105
|
-
const defaultPublications = _.reduce(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
const defaultPublications = _.reduce(
|
|
129
|
+
vhosts,
|
|
130
|
+
(publications, vhost) => {
|
|
131
|
+
_.each(vhost.exchanges, (exchange) => {
|
|
132
|
+
const name =
|
|
133
|
+
vhost.name === "/"
|
|
134
|
+
? format("/%s", exchange.name)
|
|
135
|
+
: format("%s/%s", vhost.name, exchange.name);
|
|
136
|
+
publications[name] = {
|
|
137
|
+
exchange: exchange.name,
|
|
138
|
+
vhost: vhost.name,
|
|
139
|
+
autoCreated: true,
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
_.each(vhost.queues, (queue) => {
|
|
143
|
+
const name =
|
|
144
|
+
vhost.name === "/"
|
|
145
|
+
? format("/%s", queue.name)
|
|
146
|
+
: format("%s/%s", vhost.name, queue.name);
|
|
147
|
+
publications[name] = {
|
|
148
|
+
queue: queue.name,
|
|
149
|
+
vhost: vhost.name,
|
|
150
|
+
autoCreated: true,
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
return publications;
|
|
154
|
+
},
|
|
155
|
+
{}
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
_.each(
|
|
159
|
+
_.defaults({}, publications, defaultPublications),
|
|
160
|
+
configurePublication
|
|
161
|
+
);
|
|
118
162
|
}
|
|
119
163
|
|
|
120
164
|
function configurePublication(publicationConfig, name) {
|
|
121
|
-
debug(
|
|
122
|
-
if (
|
|
123
|
-
|
|
165
|
+
debug("Configuring publication: %s", name);
|
|
166
|
+
if (
|
|
167
|
+
rascalConfig.publications[name] &&
|
|
168
|
+
rascalConfig.publications[name].vhost !== publicationConfig.vhost
|
|
169
|
+
)
|
|
170
|
+
throw new Error(format("Duplicate publication: %s", name));
|
|
171
|
+
rascalConfig.publications[name] = _.defaultsDeep(
|
|
172
|
+
publicationConfig,
|
|
173
|
+
{ name },
|
|
174
|
+
rascalConfig.defaults.publications
|
|
175
|
+
);
|
|
124
176
|
if (!rascalConfig.vhosts[publicationConfig.vhost]) return;
|
|
125
|
-
const destination = Object.prototype.hasOwnProperty.call(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
177
|
+
const destination = Object.prototype.hasOwnProperty.call(
|
|
178
|
+
publicationConfig,
|
|
179
|
+
"exchange"
|
|
180
|
+
)
|
|
181
|
+
? rascalConfig.vhosts[publicationConfig.vhost].exchanges[
|
|
182
|
+
publicationConfig.exchange
|
|
183
|
+
]
|
|
184
|
+
: rascalConfig.vhosts[publicationConfig.vhost].queues[
|
|
185
|
+
publicationConfig.queue
|
|
186
|
+
];
|
|
187
|
+
rascalConfig.publications[name].destination =
|
|
188
|
+
destination.fullyQualifiedName;
|
|
189
|
+
|
|
190
|
+
if (
|
|
191
|
+
publicationConfig.encryption &&
|
|
192
|
+
_.isString(publicationConfig.encryption)
|
|
193
|
+
) {
|
|
194
|
+
rascalConfig.publications[name].encryption = _.defaultsDeep(
|
|
195
|
+
{ name: publicationConfig.encryption },
|
|
196
|
+
rascalConfig.encryption[publicationConfig.encryption]
|
|
197
|
+
);
|
|
132
198
|
}
|
|
133
199
|
}
|
|
134
200
|
|
|
@@ -141,23 +207,50 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
141
207
|
}
|
|
142
208
|
|
|
143
209
|
function configureSubscriptions(subscriptions, vhosts) {
|
|
144
|
-
const defaultSubscriptions = _.reduce(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
210
|
+
const defaultSubscriptions = _.reduce(
|
|
211
|
+
vhosts,
|
|
212
|
+
(subscriptions, vhost) => {
|
|
213
|
+
_.each(vhost.queues, (queue) => {
|
|
214
|
+
const name =
|
|
215
|
+
vhost.name === "/"
|
|
216
|
+
? format("/%s", queue.name)
|
|
217
|
+
: format("%s/%s", vhost.name, queue.name);
|
|
218
|
+
subscriptions[name] = {
|
|
219
|
+
queue: queue.name,
|
|
220
|
+
vhost: vhost.name,
|
|
221
|
+
autoCreated: true,
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
return subscriptions;
|
|
225
|
+
},
|
|
226
|
+
{}
|
|
227
|
+
);
|
|
228
|
+
_.each(
|
|
229
|
+
_.defaults({}, subscriptions, defaultSubscriptions),
|
|
230
|
+
configureSubscription
|
|
231
|
+
);
|
|
152
232
|
}
|
|
153
233
|
|
|
154
234
|
function configureSubscription(subscriptionConfig, name) {
|
|
155
|
-
debug(
|
|
156
|
-
if (
|
|
157
|
-
|
|
235
|
+
debug("Configuring subscription: %s", name);
|
|
236
|
+
if (
|
|
237
|
+
rascalConfig.subscriptions[name] &&
|
|
238
|
+
rascalConfig.subscriptions[name].vhost !== subscriptionConfig.vhost
|
|
239
|
+
)
|
|
240
|
+
throw new Error(format("Duplicate subscription: %s", name));
|
|
241
|
+
rascalConfig.subscriptions[name] = _.defaultsDeep(
|
|
242
|
+
subscriptionConfig,
|
|
243
|
+
{ name },
|
|
244
|
+
rascalConfig.defaults.subscriptions
|
|
245
|
+
);
|
|
158
246
|
if (!rascalConfig.vhosts[subscriptionConfig.vhost]) return;
|
|
159
|
-
subscriptionConfig.source =
|
|
160
|
-
|
|
247
|
+
subscriptionConfig.source =
|
|
248
|
+
rascalConfig.vhosts[subscriptionConfig.vhost].queues[
|
|
249
|
+
subscriptionConfig.queue
|
|
250
|
+
].fullyQualifiedName;
|
|
251
|
+
subscriptionConfig.encryption =
|
|
252
|
+
subscriptionConfig.encryption ||
|
|
253
|
+
_.defaultsDeep({}, rascalConfig.encryption);
|
|
161
254
|
}
|
|
162
255
|
|
|
163
256
|
function configureShovels(shovels) {
|
|
@@ -166,15 +259,28 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
166
259
|
}
|
|
167
260
|
|
|
168
261
|
function configureShovel(shovelConfig, name) {
|
|
169
|
-
debug(
|
|
262
|
+
debug("Configuring shovel: %s", name);
|
|
170
263
|
const parsedConfig = parseShovelName(name);
|
|
171
|
-
rascalConfig.shovels[name] = _.defaultsDeep(
|
|
264
|
+
rascalConfig.shovels[name] = _.defaultsDeep(
|
|
265
|
+
shovelConfig,
|
|
266
|
+
{ name },
|
|
267
|
+
parsedConfig,
|
|
268
|
+
rascalConfig.defaults.shovels
|
|
269
|
+
);
|
|
172
270
|
}
|
|
173
271
|
|
|
174
272
|
function parseShovelName(name) {
|
|
175
|
-
const pattern = XRegExp(
|
|
273
|
+
const pattern = XRegExp(
|
|
274
|
+
"(?<subscription>[\\w:]+)\\s*->\\s*(?<publication>[\\w:]+)"
|
|
275
|
+
);
|
|
176
276
|
const match = XRegExp.exec(name, pattern);
|
|
177
|
-
return match
|
|
277
|
+
return match
|
|
278
|
+
? {
|
|
279
|
+
name,
|
|
280
|
+
subscription: match.groups.subscription,
|
|
281
|
+
publication: match.groups.publication,
|
|
282
|
+
}
|
|
283
|
+
: { name };
|
|
178
284
|
}
|
|
179
285
|
|
|
180
286
|
function configureCounters(counters) {
|
|
@@ -183,55 +289,100 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
183
289
|
}
|
|
184
290
|
|
|
185
291
|
function configureCounter(counterConfig, name) {
|
|
186
|
-
debug(
|
|
292
|
+
debug("Configuring counter: %s", name);
|
|
187
293
|
const counterType = counterConfig.type || name;
|
|
188
|
-
const counterDefaultConfigPath =
|
|
294
|
+
const counterDefaultConfigPath =
|
|
295
|
+
"defaults.redeliveries.counters." + counterType;
|
|
189
296
|
const counterDefaults = _.get(rascalConfig, counterDefaultConfigPath);
|
|
190
|
-
rascalConfig.redeliveries.counters[name] = _.defaultsDeep(
|
|
297
|
+
rascalConfig.redeliveries.counters[name] = _.defaultsDeep(
|
|
298
|
+
counterConfig,
|
|
299
|
+
{ name, type: name },
|
|
300
|
+
counterDefaults
|
|
301
|
+
);
|
|
191
302
|
}
|
|
192
303
|
|
|
193
304
|
function configureExchanges(config) {
|
|
194
|
-
const defaultExchange = {
|
|
195
|
-
config.exchanges = _.defaultsDeep(
|
|
305
|
+
const defaultExchange = { "": {} };
|
|
306
|
+
config.exchanges = _.defaultsDeep(
|
|
307
|
+
ensureKeyedCollection(config.exchanges),
|
|
308
|
+
defaultExchange
|
|
309
|
+
);
|
|
196
310
|
_.each(config.exchanges, (exchangeConfig, name) => {
|
|
197
|
-
debug(
|
|
198
|
-
config.exchanges[name] = _.defaultsDeep(
|
|
311
|
+
debug("Configuring exchange: %s", name);
|
|
312
|
+
config.exchanges[name] = _.defaultsDeep(
|
|
313
|
+
exchangeConfig,
|
|
314
|
+
{ name, fullyQualifiedName: fqn.qualify(name, config.namespace) },
|
|
315
|
+
config.defaults.exchanges
|
|
316
|
+
);
|
|
199
317
|
});
|
|
200
318
|
}
|
|
201
319
|
|
|
202
320
|
function configureQueues(config) {
|
|
203
321
|
config.queues = ensureKeyedCollection(config.queues);
|
|
204
322
|
_.each(config.queues, (queueConfig, name) => {
|
|
205
|
-
debug(
|
|
206
|
-
queueConfig.replyTo =
|
|
207
|
-
|
|
208
|
-
|
|
323
|
+
debug("Configuring queue: %s", name);
|
|
324
|
+
queueConfig.replyTo =
|
|
325
|
+
queueConfig.replyTo === true ? uuid() : queueConfig.replyTo;
|
|
326
|
+
qualifyArguments(
|
|
327
|
+
config.namespace,
|
|
328
|
+
queueConfig.options && queueConfig.options.arguments
|
|
329
|
+
);
|
|
330
|
+
config.queues[name] = _.defaultsDeep(
|
|
331
|
+
queueConfig,
|
|
332
|
+
{
|
|
333
|
+
name,
|
|
334
|
+
fullyQualifiedName: fqn.qualify(
|
|
335
|
+
name,
|
|
336
|
+
config.namespace,
|
|
337
|
+
queueConfig.replyTo
|
|
338
|
+
),
|
|
339
|
+
},
|
|
340
|
+
config.defaults.queues
|
|
341
|
+
);
|
|
209
342
|
});
|
|
210
343
|
}
|
|
211
344
|
|
|
212
345
|
function configureBindings(config) {
|
|
213
|
-
|
|
214
346
|
config.bindings = expandBindings(ensureKeyedCollection(config.bindings));
|
|
215
347
|
|
|
216
348
|
_.each(config.bindings, (bindingConfig, name) => {
|
|
217
|
-
debug(
|
|
349
|
+
debug("Configuring binding: %s", name);
|
|
218
350
|
|
|
219
|
-
config.bindings[name] = _.defaultsDeep(
|
|
351
|
+
config.bindings[name] = _.defaultsDeep(
|
|
352
|
+
bindingConfig,
|
|
353
|
+
config.defaults.bindings
|
|
354
|
+
);
|
|
220
355
|
|
|
221
356
|
if (bindingConfig.qualifyBindingKeys) {
|
|
222
|
-
config.bindings[name].bindingKey = fqn.qualify(
|
|
357
|
+
config.bindings[name].bindingKey = fqn.qualify(
|
|
358
|
+
bindingConfig.bindingKey,
|
|
359
|
+
config.namespace
|
|
360
|
+
);
|
|
223
361
|
}
|
|
224
|
-
if (bindingConfig.destinationType ===
|
|
362
|
+
if (bindingConfig.destinationType === "queue") {
|
|
225
363
|
const queue = config.queues[bindingConfig.destination];
|
|
226
|
-
config.bindings[name].bindingKey = fqn.prefix(
|
|
364
|
+
config.bindings[name].bindingKey = fqn.prefix(
|
|
365
|
+
queue && queue.replyTo,
|
|
366
|
+
bindingConfig.bindingKey,
|
|
367
|
+
"."
|
|
368
|
+
);
|
|
227
369
|
}
|
|
228
370
|
});
|
|
229
371
|
}
|
|
230
372
|
|
|
231
373
|
function parseBindingName(name) {
|
|
232
|
-
const pattern = XRegExp(
|
|
374
|
+
const pattern = XRegExp(
|
|
375
|
+
"(?<source>[\\w:\\.\\-]+)\\s*(?:\\[\\s*(?<keys>.*)\\s*\\])?\\s*->\\s*(?<destination>[\\w:\\.\\-]+)"
|
|
376
|
+
);
|
|
233
377
|
const match = XRegExp.exec(name, pattern);
|
|
234
|
-
return match
|
|
378
|
+
return match
|
|
379
|
+
? {
|
|
380
|
+
name,
|
|
381
|
+
source: match.groups.source,
|
|
382
|
+
destination: match.groups.destination,
|
|
383
|
+
bindingKeys: splitBindingKeys(match.groups.keys),
|
|
384
|
+
}
|
|
385
|
+
: { name };
|
|
235
386
|
}
|
|
236
387
|
|
|
237
388
|
function splitBindingKeys(keys) {
|
|
@@ -242,13 +393,27 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
242
393
|
const result = {};
|
|
243
394
|
_.each(definitions, (bindingConfig, name) => {
|
|
244
395
|
const parsedConfig = parseBindingName(name);
|
|
245
|
-
const bindingKeys = _.chain([])
|
|
396
|
+
const bindingKeys = _.chain([])
|
|
397
|
+
.concat(
|
|
398
|
+
bindingConfig.bindingKeys,
|
|
399
|
+
bindingConfig.bindingKey,
|
|
400
|
+
parsedConfig.bindingKeys
|
|
401
|
+
)
|
|
402
|
+
.compact()
|
|
403
|
+
.uniq()
|
|
404
|
+
.value();
|
|
246
405
|
if (bindingKeys.length <= 1) {
|
|
247
|
-
result[name] = _({ bindingKey: bindingKeys[0] })
|
|
406
|
+
result[name] = _({ bindingKey: bindingKeys[0] })
|
|
407
|
+
.defaults(bindingConfig, parsedConfig)
|
|
408
|
+
.omit("bindingKeys")
|
|
409
|
+
.value();
|
|
248
410
|
return result[name];
|
|
249
411
|
}
|
|
250
412
|
_.each(bindingKeys, (bindingKey) => {
|
|
251
|
-
result[format(
|
|
413
|
+
result[format("%s:%s", name, bindingKey)] = _({ bindingKey })
|
|
414
|
+
.defaults(bindingConfig, parsedConfig)
|
|
415
|
+
.omit("bindingKeys")
|
|
416
|
+
.value();
|
|
252
417
|
});
|
|
253
418
|
});
|
|
254
419
|
return result;
|
|
@@ -256,15 +421,23 @@ module.exports = _.curry((rascalConfig, next) => {
|
|
|
256
421
|
|
|
257
422
|
function qualifyArguments(namespace, args) {
|
|
258
423
|
if (!args) return;
|
|
259
|
-
_.each([
|
|
260
|
-
args[name] =
|
|
424
|
+
_.each(["x-dead-letter-exchange"], (name) => {
|
|
425
|
+
args[name] =
|
|
426
|
+
args[name] !== undefined
|
|
427
|
+
? fqn.qualify(args[name], namespace)
|
|
428
|
+
: args[name];
|
|
261
429
|
});
|
|
262
430
|
}
|
|
263
431
|
|
|
264
432
|
function ensureKeyedCollection(collection) {
|
|
265
433
|
if (!_.isArray(collection)) return collection;
|
|
266
|
-
return _.chain(collection)
|
|
267
|
-
|
|
268
|
-
|
|
434
|
+
return _.chain(collection)
|
|
435
|
+
.map((item) => {
|
|
436
|
+
return _.isString(item)
|
|
437
|
+
? { name: item }
|
|
438
|
+
: _.defaults(item, { name: "unnamed-" + uuid() });
|
|
439
|
+
})
|
|
440
|
+
.keyBy("name")
|
|
441
|
+
.value();
|
|
269
442
|
}
|
|
270
443
|
});
|
package/lib/config/fqn.js
CHANGED
|
@@ -5,16 +5,16 @@ module.exports = {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
function qualify(name, namespace, unique) {
|
|
8
|
-
if (name ===
|
|
8
|
+
if (name === "") return name;
|
|
9
9
|
name = prefix(namespace, name);
|
|
10
10
|
name = suffix(unique || undefined, name);
|
|
11
11
|
return name;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
function prefix(prefix, name, separator) {
|
|
15
|
-
return prefix ? prefix + (separator ||
|
|
15
|
+
return prefix ? prefix + (separator || ":") + name : name;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function suffix(suffix, name, separator) {
|
|
19
|
-
return suffix ? name + (separator ||
|
|
19
|
+
return suffix ? name + (separator || ":") + suffix : name;
|
|
20
20
|
}
|
package/lib/config/tests.js
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
const _ = require(
|
|
2
|
-
const defaultConfig = require(
|
|
1
|
+
const _ = require("lodash").runInContext();
|
|
2
|
+
const defaultConfig = require("./defaults");
|
|
3
3
|
|
|
4
|
-
module.exports = _.defaultsDeep(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
module.exports = _.defaultsDeep(
|
|
5
|
+
{
|
|
6
|
+
defaults: {
|
|
7
|
+
vhosts: {
|
|
8
|
+
connection: {
|
|
9
|
+
options: {
|
|
10
|
+
heartbeat: 50,
|
|
11
|
+
},
|
|
10
12
|
},
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
namespace: true,
|
|
14
|
+
exchanges: {
|
|
15
|
+
options: {
|
|
16
|
+
durable: false,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
queues: {
|
|
20
|
+
purge: true,
|
|
21
|
+
options: {
|
|
22
|
+
durable: false,
|
|
23
|
+
},
|
|
16
24
|
},
|
|
17
25
|
},
|
|
18
|
-
|
|
19
|
-
purge: true,
|
|
26
|
+
publications: {
|
|
20
27
|
options: {
|
|
21
|
-
|
|
28
|
+
persistent: false,
|
|
22
29
|
},
|
|
23
30
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
options: {
|
|
27
|
-
persistent: false,
|
|
31
|
+
subscriptions: {
|
|
32
|
+
deferCloseChannel: 100,
|
|
28
33
|
},
|
|
29
34
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"counters": {
|
|
36
|
-
"inMemory": {
|
|
37
|
-
"size": 1000,
|
|
35
|
+
redeliveries: {
|
|
36
|
+
counters: {
|
|
37
|
+
inMemory: {
|
|
38
|
+
size: 1000,
|
|
39
|
+
},
|
|
38
40
|
},
|
|
39
41
|
},
|
|
40
42
|
},
|
|
41
|
-
|
|
43
|
+
defaultConfig
|
|
44
|
+
);
|