@autofleet/rabbit 2.1.8 → 2.1.10
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 +3 -3
- package/dist/index.js +11 -6
- package/package.json +2 -2
- package/src/index.ts +14 -7
package/dist/index.d.ts
CHANGED
|
@@ -50,13 +50,13 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
50
50
|
getNewChannel(): Promise<ChannelWrapper>;
|
|
51
51
|
assertChannel(): Promise<ChannelWrapper>;
|
|
52
52
|
assertExchange(exchangeName: string, options?: any): Promise<any>;
|
|
53
|
-
getQueueLength(queue: string): Promise<
|
|
54
|
-
bindQueue(queue: string, exchange: string): Promise<
|
|
53
|
+
getQueueLength(queue: string): Promise<import("amqplib").Replies.AssertQueue>;
|
|
54
|
+
bindQueue(queue: string, exchange: string): Promise<void>;
|
|
55
55
|
assertQueue(queue: string, options?: Options.AssertQueue): Promise<void>;
|
|
56
56
|
consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
57
57
|
consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
58
58
|
publish(exchange: string, content: any, customHeaders?: any): Promise<unknown>;
|
|
59
|
-
sendToQueue(queue: string, content: any, options?: any, customHeaders?: any): Promise<
|
|
59
|
+
sendToQueue(queue: string, content: any, options?: any, customHeaders?: any): Promise<boolean>;
|
|
60
60
|
isConnected(): Promise<boolean>;
|
|
61
61
|
}
|
|
62
62
|
export default RabbitMq;
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ const bluebird = __importStar(require("bluebird"));
|
|
|
37
37
|
const moment_1 = __importDefault(require("moment"));
|
|
38
38
|
const amqp_connection_manager_1 = require("amqp-connection-manager");
|
|
39
39
|
const events_1 = require("events");
|
|
40
|
-
|
|
40
|
+
// import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
41
41
|
const logger_1 = __importDefault(require("./logger"));
|
|
42
42
|
const rabbitError_1 = __importDefault(require("./rabbitError"));
|
|
43
43
|
const redis_1 = __importDefault(require("./redis"));
|
|
@@ -123,7 +123,7 @@ class RabbitMq {
|
|
|
123
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
124
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
125
125
|
if (this.creatingConnection) {
|
|
126
|
-
this.em.
|
|
126
|
+
this.em.once(connectionCreatedConst, resolve);
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
if (this.connection !== null) {
|
|
@@ -163,8 +163,8 @@ class RabbitMq {
|
|
|
163
163
|
if (this.channel) {
|
|
164
164
|
return resolve(this.channel);
|
|
165
165
|
}
|
|
166
|
-
const connection = yield this.getConnection();
|
|
167
166
|
try {
|
|
167
|
+
const connection = yield this.getConnection();
|
|
168
168
|
if (this.channel === null) {
|
|
169
169
|
this.channel = connection.createChannel({});
|
|
170
170
|
}
|
|
@@ -223,13 +223,18 @@ class RabbitMq {
|
|
|
223
223
|
return Promise.all([
|
|
224
224
|
c.consume(queue, (msg) => __awaiter(this, void 0, void 0, function* () {
|
|
225
225
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
226
|
-
|
|
226
|
+
// newTrace(traceTypes.RABBIT);
|
|
227
227
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
228
228
|
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
229
229
|
if (!shouldConsume) {
|
|
230
230
|
return this.ack(channel)(msg);
|
|
231
231
|
}
|
|
232
|
-
|
|
232
|
+
try {
|
|
233
|
+
yield callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
yield this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
|
|
237
|
+
}
|
|
233
238
|
})),
|
|
234
239
|
]);
|
|
235
240
|
}));
|
|
@@ -251,7 +256,7 @@ class RabbitMq {
|
|
|
251
256
|
c.bindQueue(queue, exchange, ''),
|
|
252
257
|
c.consume(queue, (msg) => __awaiter(this, void 0, void 0, function* () {
|
|
253
258
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
254
|
-
|
|
259
|
+
// newTrace(traceTypes.RABBIT);
|
|
255
260
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
256
261
|
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
257
262
|
if (!shouldConsume) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@types/amqp-connection-manager": "^2.0.10",
|
|
20
20
|
"@types/amqplib": "^0.5.16",
|
|
21
21
|
"@types/uuid": "^8.3.3",
|
|
22
|
-
"amqp-connection-manager": "^3.
|
|
22
|
+
"amqp-connection-manager": "^3.7.0",
|
|
23
23
|
"amqplib": "^0.6.0",
|
|
24
24
|
"bluebird": "^3.7.2",
|
|
25
25
|
"moment": "^2.29.1",
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import moment from 'moment';
|
|
|
5
5
|
import { ConfirmChannel, Options } from 'amqplib';
|
|
6
6
|
import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-manager';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
|
-
import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
8
|
+
// import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
9
9
|
import logger from './logger';
|
|
10
10
|
import RabbitError from './rabbitError';
|
|
11
11
|
import getRedisInstance, { RedisConfig } from './redis';
|
|
@@ -159,7 +159,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
159
159
|
async getConnection() {
|
|
160
160
|
return new Promise<AmqpConnectionManager>(async (resolve) => {
|
|
161
161
|
if (this.creatingConnection) {
|
|
162
|
-
this.em.
|
|
162
|
+
this.em.once(connectionCreatedConst, resolve);
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
165
|
if (this.connection !== null) {
|
|
@@ -197,9 +197,8 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
197
197
|
return resolve(this.channel);
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
const connection: AmqpConnectionManager = await this.getConnection();
|
|
201
|
-
|
|
202
200
|
try {
|
|
201
|
+
const connection: AmqpConnectionManager = await this.getConnection();
|
|
203
202
|
if (this.channel === null) {
|
|
204
203
|
this.channel = connection.createChannel({});
|
|
205
204
|
}
|
|
@@ -254,13 +253,21 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
254
253
|
queue,
|
|
255
254
|
async (msg: any) => {
|
|
256
255
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
257
|
-
newTrace(traceTypes.RABBIT);
|
|
256
|
+
// newTrace(traceTypes.RABBIT);
|
|
258
257
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
259
258
|
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
260
259
|
if (!shouldConsume) {
|
|
261
260
|
return this.ack(channel)(msg);
|
|
262
261
|
}
|
|
263
|
-
|
|
262
|
+
try {
|
|
263
|
+
await callback(
|
|
264
|
+
parsedMessage,
|
|
265
|
+
this.ack(channel, true),
|
|
266
|
+
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
|
|
267
|
+
);
|
|
268
|
+
} catch (e) {
|
|
269
|
+
await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
|
|
270
|
+
}
|
|
264
271
|
},
|
|
265
272
|
),
|
|
266
273
|
]);
|
|
@@ -285,7 +292,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
285
292
|
queue,
|
|
286
293
|
async (msg: any) => {
|
|
287
294
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
288
|
-
newTrace(traceTypes.RABBIT);
|
|
295
|
+
// newTrace(traceTypes.RABBIT);
|
|
289
296
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
290
297
|
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
291
298
|
if (!shouldConsume) {
|