@rxdi/rabbitmq-pubsub 0.7.227 → 0.7.229
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/dist/common.d.ts +4 -3
- package/dist/common.js +14 -4
- package/dist/consumer.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/producer.js +1 -1
- package/dist/publisher.js +4 -4
- package/dist/subscriber.js +9 -5
- package/package.json +1 -1
package/dist/common.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export interface IQueueNameConfig {
|
|
|
17
17
|
globalPrefetch?: boolean;
|
|
18
18
|
name: string;
|
|
19
19
|
dlq: string;
|
|
20
|
-
|
|
20
|
+
exchange: string;
|
|
21
21
|
strictName?: boolean;
|
|
22
22
|
arguments?: {
|
|
23
23
|
[key: string]: any;
|
|
@@ -26,13 +26,13 @@ export interface IQueueNameConfig {
|
|
|
26
26
|
export declare class DefaultQueueNameConfig implements IQueueNameConfig {
|
|
27
27
|
name: string;
|
|
28
28
|
dlq: string;
|
|
29
|
-
|
|
29
|
+
exchange: string;
|
|
30
30
|
constructor(name: string);
|
|
31
31
|
}
|
|
32
32
|
export declare class DefaultPubSubQueueConfig implements IQueueNameConfig {
|
|
33
33
|
name: string;
|
|
34
34
|
dlq: string;
|
|
35
|
-
|
|
35
|
+
exchange: string;
|
|
36
36
|
constructor(name: string);
|
|
37
37
|
}
|
|
38
38
|
export declare function asQueueNameConfig(config: IQueueNameConfig | string): IQueueNameConfig;
|
|
@@ -41,3 +41,4 @@ export interface IDeadLetterMessage<T> {
|
|
|
41
41
|
data: T;
|
|
42
42
|
error: Error;
|
|
43
43
|
}
|
|
44
|
+
export declare const createQueueConfig: (name: string, options?: Partial<IQueueNameConfig>) => IQueueNameConfig;
|
package/dist/common.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultPubSubQueueConfig = exports.DefaultQueueNameConfig = void 0;
|
|
3
|
+
exports.createQueueConfig = exports.DefaultPubSubQueueConfig = exports.DefaultQueueNameConfig = void 0;
|
|
4
4
|
exports.asQueueNameConfig = asQueueNameConfig;
|
|
5
5
|
exports.asPubSubQueueNameConfig = asPubSubQueueNameConfig;
|
|
6
6
|
class DefaultQueueNameConfig {
|
|
7
7
|
constructor(name) {
|
|
8
8
|
this.name = name;
|
|
9
9
|
this.dlq = `${name}.DLQ`;
|
|
10
|
-
this.
|
|
10
|
+
this.exchange = `${this.dlq}.Exchange`;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.DefaultQueueNameConfig = DefaultQueueNameConfig;
|
|
@@ -15,7 +15,7 @@ class DefaultPubSubQueueConfig {
|
|
|
15
15
|
constructor(name) {
|
|
16
16
|
this.name = name;
|
|
17
17
|
this.dlq = "";
|
|
18
|
-
this.
|
|
18
|
+
this.exchange = `${name}.Exchange`;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.DefaultPubSubQueueConfig = DefaultPubSubQueueConfig;
|
|
@@ -32,7 +32,17 @@ function asPubSubQueueNameConfig(config) {
|
|
|
32
32
|
function isQueueNameConfig(config) {
|
|
33
33
|
if (config.name &&
|
|
34
34
|
config.dlq &&
|
|
35
|
-
config.
|
|
35
|
+
config.exchange) {
|
|
36
36
|
return true;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
const createQueueConfig = (name, options) => {
|
|
40
|
+
const defaultConfig = {
|
|
41
|
+
prefetch: 1,
|
|
42
|
+
globalPrefetch: true,
|
|
43
|
+
strictName: true,
|
|
44
|
+
};
|
|
45
|
+
const finalOptions = Object.assign(Object.assign({}, defaultConfig), options);
|
|
46
|
+
return Object.assign(Object.assign({ name, dlq: `${name}.DLQ`, exchange: `${name}.Exchange` }, finalOptions), { arguments: Object.assign({ 'x-dead-letter-exchange': `${name}.DLQ`, 'x-dead-letter-routing-key': `${name}.DLQ` }, finalOptions.arguments) });
|
|
47
|
+
};
|
|
48
|
+
exports.createQueueConfig = createQueueConfig;
|
package/dist/consumer.js
CHANGED
|
@@ -63,10 +63,10 @@ class RabbitMqConsumer {
|
|
|
63
63
|
}
|
|
64
64
|
getChannelSetup(channel, queueConfig) {
|
|
65
65
|
return [
|
|
66
|
-
channel.assertQueue(queueConfig.name, this.getQueueSettings(queueConfig.
|
|
66
|
+
channel.assertQueue(queueConfig.name, this.getQueueSettings(queueConfig.exchange)),
|
|
67
67
|
channel.assertQueue(queueConfig.dlq, this.getDLSettings()),
|
|
68
|
-
channel.assertExchange(queueConfig.
|
|
69
|
-
channel.bindQueue(queueConfig.dlq, queueConfig.
|
|
68
|
+
channel.assertExchange(queueConfig.exchange, "fanout", this.getDLSettings()),
|
|
69
|
+
channel.bindQueue(queueConfig.dlq, queueConfig.exchange, "*"),
|
|
70
70
|
];
|
|
71
71
|
}
|
|
72
72
|
getQueueSettings(deadletterExchangeName) {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { RabbitMqConsumer, IRabbitMqConsumerDisposer } from "./consumer";
|
|
|
3
3
|
export { RabbitMqProducer } from "./producer";
|
|
4
4
|
export { RabbitMqPublisher } from "./publisher";
|
|
5
5
|
export { RabbitMqSubscriber, IRabbitMqSubscriberDisposer } from "./subscriber";
|
|
6
|
-
export { IQueueNameConfig, IDeadLetterMessage } from "./common";
|
|
6
|
+
export { IQueueNameConfig, IDeadLetterMessage, createQueueConfig } from "./common";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RabbitMqSubscriber = exports.RabbitMqPublisher = exports.RabbitMqProducer = exports.RabbitMqConsumer = exports.RabbitMqSingletonConnectionFactory = exports.RabbitMqConnectionFactory = void 0;
|
|
3
|
+
exports.createQueueConfig = exports.RabbitMqSubscriber = exports.RabbitMqPublisher = exports.RabbitMqProducer = exports.RabbitMqConsumer = exports.RabbitMqSingletonConnectionFactory = exports.RabbitMqConnectionFactory = void 0;
|
|
4
4
|
var connectionFactory_1 = require("./connectionFactory");
|
|
5
5
|
Object.defineProperty(exports, "RabbitMqConnectionFactory", { enumerable: true, get: function () { return connectionFactory_1.RabbitMqConnectionFactory; } });
|
|
6
6
|
Object.defineProperty(exports, "RabbitMqSingletonConnectionFactory", { enumerable: true, get: function () { return connectionFactory_1.RabbitMqSingletonConnectionFactory; } });
|
|
@@ -12,3 +12,5 @@ var publisher_1 = require("./publisher");
|
|
|
12
12
|
Object.defineProperty(exports, "RabbitMqPublisher", { enumerable: true, get: function () { return publisher_1.RabbitMqPublisher; } });
|
|
13
13
|
var subscriber_1 = require("./subscriber");
|
|
14
14
|
Object.defineProperty(exports, "RabbitMqSubscriber", { enumerable: true, get: function () { return subscriber_1.RabbitMqSubscriber; } });
|
|
15
|
+
var common_1 = require("./common");
|
|
16
|
+
Object.defineProperty(exports, "createQueueConfig", { enumerable: true, get: function () { return common_1.createQueueConfig; } });
|
package/dist/producer.js
CHANGED
|
@@ -21,7 +21,7 @@ class RabbitMqProducer {
|
|
|
21
21
|
publish(queue, message, options) {
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
const queueConfig = (0, common_1.asQueueNameConfig)(queue);
|
|
24
|
-
const settings = this.getQueueSettings(queueConfig.
|
|
24
|
+
const settings = this.getQueueSettings(queueConfig.exchange);
|
|
25
25
|
const connection = yield this.connectionFactory.create();
|
|
26
26
|
const channel = yield connection.createChannel();
|
|
27
27
|
if (options === null || options === void 0 ? void 0 : options.prefetch) {
|
package/dist/publisher.js
CHANGED
|
@@ -28,12 +28,12 @@ class RabbitMqPublisher {
|
|
|
28
28
|
channel.prefetch(options.prefetch, options.globalPrefetch);
|
|
29
29
|
}
|
|
30
30
|
yield this.setupChannel(channel, queueConfig);
|
|
31
|
-
channel.publish(queueConfig.
|
|
32
|
-
this.logger.trace("message sent to exchange '%s' (%j)", queueConfig.
|
|
31
|
+
channel.publish(queueConfig.exchange, '', this.getMessageBuffer(message));
|
|
32
|
+
this.logger.trace("message sent to exchange '%s' (%j)", queueConfig.exchange, message);
|
|
33
33
|
return channel.close();
|
|
34
34
|
}
|
|
35
35
|
catch (e) {
|
|
36
|
-
this.logger.error("unable to send message to exchange '%j' {%j}", queueConfig.
|
|
36
|
+
this.logger.error("unable to send message to exchange '%j' {%j}", queueConfig.exchange, message);
|
|
37
37
|
throw new Error('Unable to send message');
|
|
38
38
|
}
|
|
39
39
|
});
|
|
@@ -46,7 +46,7 @@ class RabbitMqPublisher {
|
|
|
46
46
|
return Buffer.from(JSON.stringify(message), 'utf8');
|
|
47
47
|
}
|
|
48
48
|
getChannelSetup(channel, queueConfig) {
|
|
49
|
-
return [channel.assertExchange(queueConfig.
|
|
49
|
+
return [channel.assertExchange(queueConfig.exchange, 'fanout', this.getSettings())];
|
|
50
50
|
}
|
|
51
51
|
getSettings() {
|
|
52
52
|
return {
|
package/dist/subscriber.js
CHANGED
|
@@ -29,7 +29,7 @@ class RabbitMqSubscriber {
|
|
|
29
29
|
this.logger.trace("got channel for queue '%s'", queueConfig.name);
|
|
30
30
|
const queueName = yield this.setupChannel(channel, Object.assign(Object.assign({}, queueConfig), options));
|
|
31
31
|
this.logger.debug("queue name generated for subscription queue '(%s)' is '(%s)'", queueConfig.name, queueName);
|
|
32
|
-
const queConfig = Object.assign(Object.assign({}, queueConfig), { dlq: queueName });
|
|
32
|
+
const queConfig = Object.assign(Object.assign(Object.assign({}, queueConfig), options), { dlq: queueName });
|
|
33
33
|
return this.subscribeToChannel(channel, queConfig, action);
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -41,6 +41,7 @@ class RabbitMqSubscriber {
|
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
42
|
this.logger.trace("subscribing to queue '%s'", queueConfig.name);
|
|
43
43
|
const opts = yield channel.consume(queueConfig.dlq, (message) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
var _a, _b;
|
|
44
45
|
let msg = this.getMessageObject(message);
|
|
45
46
|
this.logger.trace("message arrived from queue '%s' (%j)", queueConfig.name, msg);
|
|
46
47
|
try {
|
|
@@ -51,8 +52,11 @@ class RabbitMqSubscriber {
|
|
|
51
52
|
}
|
|
52
53
|
catch (err) {
|
|
53
54
|
this.logger.error(err, "message processing failed from queue '%j' (%j)", queueConfig, msg);
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const exchange = (_a = queueConfig === null || queueConfig === void 0 ? void 0 : queueConfig.arguments) === null || _a === void 0 ? void 0 : _a['x-dead-letter-exchange'];
|
|
56
|
+
if (!exchange) {
|
|
57
|
+
return channel.nack(message, false, false);
|
|
58
|
+
}
|
|
59
|
+
channel.publish(exchange || queueConfig.exchange, ((_b = queueConfig.arguments) === null || _b === void 0 ? void 0 : _b['x-dead-letter-routing-key']) || '', Buffer.from(JSON.stringify({
|
|
56
60
|
data: msg,
|
|
57
61
|
error: {
|
|
58
62
|
message: err.message,
|
|
@@ -74,9 +78,9 @@ class RabbitMqSubscriber {
|
|
|
74
78
|
}
|
|
75
79
|
getChannelSetup(channel, queueConfig) {
|
|
76
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
yield channel.assertExchange(queueConfig.
|
|
81
|
+
yield channel.assertExchange(queueConfig.exchange, "fanout", this.getDLSettings());
|
|
78
82
|
let result = yield channel.assertQueue(queueConfig.strictName ? queueConfig.name : queueConfig.dlq, this.getQueueSettings(queueConfig.arguments));
|
|
79
|
-
yield channel.bindQueue(result.queue, queueConfig.
|
|
83
|
+
yield channel.bindQueue(result.queue, queueConfig.exchange, "");
|
|
80
84
|
return result.queue;
|
|
81
85
|
});
|
|
82
86
|
}
|