sb-rabbitmq-provider 1.0.23 → 1.0.27
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/index.d.ts +4 -0
- package/dist/index.js +20 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -15,13 +15,16 @@ interface rabbitMQConfig {
|
|
15
15
|
vhost?: string | undefined;
|
16
16
|
exchangeName?: string;
|
17
17
|
exchangeType: string;
|
18
|
+
dropMessageOnChannelFailure?: boolean;
|
18
19
|
}
|
19
20
|
type MyCallback = (data: any) => any;
|
20
21
|
declare class RabbitMqConnection {
|
21
22
|
config: rabbitMQConfig;
|
22
23
|
exchange: string;
|
23
24
|
exchangeType: string;
|
25
|
+
dropMessageOnChannelFailure: boolean;
|
24
26
|
connection: any;
|
27
|
+
channel: any;
|
25
28
|
/**
|
26
29
|
* constructor for initialising url, exchange name, exchange type
|
27
30
|
* @param url rabbitmq url
|
@@ -38,6 +41,7 @@ declare class RabbitMqConnection {
|
|
38
41
|
/**
|
39
42
|
* single connection can have multiple channel like publishChannel and consumeChannel
|
40
43
|
* @returns channel object
|
44
|
+
* No need to use this method, as channel is created in createConnection method.
|
41
45
|
*/
|
42
46
|
createChannel(): Promise<RabbitMQChannel>;
|
43
47
|
/**
|
package/dist/index.js
CHANGED
@@ -27,12 +27,16 @@ class RabbitMqConnection {
|
|
27
27
|
constructor(config) {
|
28
28
|
this.exchange = 'EXCHANGE';
|
29
29
|
this.exchangeType = 'direct';
|
30
|
+
this.dropMessageOnChannelFailure = false;
|
30
31
|
if (config.exchangeName && typeof config.exchangeName === 'string') {
|
31
32
|
this.exchange = config.exchangeName;
|
32
33
|
}
|
33
34
|
if (config.exchangeType && typeof config.exchangeType === 'string') {
|
34
35
|
this.exchangeType = config.exchangeType;
|
35
36
|
}
|
37
|
+
if (config.dropMessageOnChannelFailure) {
|
38
|
+
this.dropMessageOnChannelFailure = true;
|
39
|
+
}
|
36
40
|
this.config = config;
|
37
41
|
}
|
38
42
|
/**
|
@@ -44,6 +48,8 @@ class RabbitMqConnection {
|
|
44
48
|
return __awaiter(this, void 0, void 0, function* () {
|
45
49
|
try {
|
46
50
|
const connection = yield amqplib_1.default.connect(this.config);
|
51
|
+
const channel = yield this.createChannel();
|
52
|
+
this.channel = channel;
|
47
53
|
// console.log('---RabbitMQ Connection Created---')
|
48
54
|
this.connection = connection;
|
49
55
|
return connection;
|
@@ -56,6 +62,7 @@ class RabbitMqConnection {
|
|
56
62
|
/**
|
57
63
|
* single connection can have multiple channel like publishChannel and consumeChannel
|
58
64
|
* @returns channel object
|
65
|
+
* No need to use this method, as channel is created in createConnection method.
|
59
66
|
*/
|
60
67
|
createChannel() {
|
61
68
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -103,8 +110,19 @@ class RabbitMqConnection {
|
|
103
110
|
const { queue } = yield channel.assertQueue(queueName, queueOptions);
|
104
111
|
yield channel.bindQueue(queue, this.exchange, queueName);
|
105
112
|
channel.consume(queueName, (message) => {
|
106
|
-
|
107
|
-
|
113
|
+
try {
|
114
|
+
// channel.ack(message);
|
115
|
+
onMessage(message);
|
116
|
+
}
|
117
|
+
catch (e) {
|
118
|
+
console.log('Rabbitmq consume catch block ', e);
|
119
|
+
if (message !== null) {
|
120
|
+
if (this.dropMessageOnChannelFailure) {
|
121
|
+
return channel.nack(message, false, false);
|
122
|
+
}
|
123
|
+
return channel.nack(message);
|
124
|
+
}
|
125
|
+
}
|
108
126
|
}, options);
|
109
127
|
return { status: true, message: `Started consuming Queue: ${queueName}` };
|
110
128
|
}
|