@autofleet/rabbit 2.0.0 → 2.0.1
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 +12 -1
- package/dist/index.js +8 -3
- package/dist/mock.d.ts +11 -10
- package/package.json +2 -2
- package/src/index.ts +20 -4
- package/src/mock.ts +11 -10
package/dist/index.d.ts
CHANGED
|
@@ -2,13 +2,24 @@
|
|
|
2
2
|
import { Options } from 'amqplib';
|
|
3
3
|
import { AmqpConnectionManager, ChannelWrapper } from 'amqp-connection-manager';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
|
+
export interface IAfRabbitMq {
|
|
6
|
+
ack: any;
|
|
7
|
+
nack: any;
|
|
8
|
+
assertChannel: any;
|
|
9
|
+
assertExchange: any;
|
|
10
|
+
assertQueue: any;
|
|
11
|
+
consume: any;
|
|
12
|
+
consumeFromExchange: any;
|
|
13
|
+
publish: any;
|
|
14
|
+
sendToQueue: any;
|
|
15
|
+
}
|
|
5
16
|
interface ExchangesCache {
|
|
6
17
|
[key: string]: any;
|
|
7
18
|
}
|
|
8
19
|
export interface AfRabbitOptions {
|
|
9
20
|
reconnect: boolean;
|
|
10
21
|
}
|
|
11
|
-
declare class RabbitMq {
|
|
22
|
+
declare class RabbitMq implements IAfRabbitMq {
|
|
12
23
|
static parseMsg(msg: any): any;
|
|
13
24
|
static validateName(type: string, name: string): void;
|
|
14
25
|
PUBLISH_TIMEOUT: number;
|
package/dist/index.js
CHANGED
|
@@ -227,9 +227,14 @@ class RabbitMq {
|
|
|
227
227
|
RabbitMq.validateName('exchange', exchange);
|
|
228
228
|
const channel = yield this.assertChannel();
|
|
229
229
|
yield this.assertExchange(exchange);
|
|
230
|
-
return new bluebird.Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
return new bluebird.Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
try {
|
|
232
|
+
yield channel.publish(exchange, '', Buffer.from(JSON.stringify(content)));
|
|
233
|
+
return resolve();
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
reject(e);
|
|
237
|
+
}
|
|
233
238
|
})).timeout(this.PUBLISH_TIMEOUT, `${this.PUBLISH_ERROR_MSG}${exchange}`);
|
|
234
239
|
});
|
|
235
240
|
}
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import 'jest';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
import { IAfRabbitMq } from './index';
|
|
3
|
+
declare class RabbitMq implements IAfRabbitMq {
|
|
4
|
+
ack: any;
|
|
5
|
+
nack: any;
|
|
6
|
+
assertChannel: any;
|
|
7
|
+
assertExchange: any;
|
|
8
|
+
assertQueue: any;
|
|
9
|
+
consume: any;
|
|
10
|
+
consumeFromExchange: any;
|
|
11
|
+
publish: any;
|
|
12
|
+
sendToQueue: any;
|
|
12
13
|
}
|
|
13
14
|
export default RabbitMq;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"linter": "./node_modules/.bin/eslint .",
|
|
11
11
|
"test": "jest --forceExit",
|
|
12
12
|
"test-local": "RABBITMQ_SERVICE_HOST=10.132.0.98:5672 jest --forceExit",
|
|
13
|
-
"coverage": "jest --coverage --forceExit
|
|
13
|
+
"coverage": "jest --coverage --forceExit && rm -rf ./coverage",
|
|
14
14
|
"dev": "nodemon"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,18 @@ import { EventEmitter } from 'events';
|
|
|
7
7
|
import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
8
8
|
import RabbitError from './rabbitError';
|
|
9
9
|
|
|
10
|
+
export interface IAfRabbitMq {
|
|
11
|
+
ack: any;
|
|
12
|
+
nack: any;
|
|
13
|
+
assertChannel: any;
|
|
14
|
+
assertExchange: any;
|
|
15
|
+
assertQueue: any;
|
|
16
|
+
consume: any;
|
|
17
|
+
consumeFromExchange: any;
|
|
18
|
+
publish: any;
|
|
19
|
+
sendToQueue: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
interface ExchangesCache {
|
|
11
23
|
[key: string]: any
|
|
12
24
|
}
|
|
@@ -26,7 +38,7 @@ const defaultOptions = {
|
|
|
26
38
|
const assertExchangeFanout = (c: any, exchangeName: string) => c.assertExchange(exchangeName, 'fanout');
|
|
27
39
|
|
|
28
40
|
const connectionCreatedConst = 'connectionCreated';
|
|
29
|
-
class RabbitMq {
|
|
41
|
+
class RabbitMq implements IAfRabbitMq {
|
|
30
42
|
static parseMsg(msg: any) {
|
|
31
43
|
let { content } = msg;
|
|
32
44
|
content = content.toString();
|
|
@@ -240,9 +252,13 @@ class RabbitMq {
|
|
|
240
252
|
RabbitMq.validateName('exchange', exchange);
|
|
241
253
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
242
254
|
await this.assertExchange(exchange);
|
|
243
|
-
return new bluebird.Promise(async (resolve) => {
|
|
244
|
-
|
|
245
|
-
|
|
255
|
+
return new bluebird.Promise(async (resolve, reject) => {
|
|
256
|
+
try {
|
|
257
|
+
await channel.publish(exchange, '', Buffer.from(JSON.stringify(content)));
|
|
258
|
+
return resolve();
|
|
259
|
+
} catch (e) {
|
|
260
|
+
reject(e);
|
|
261
|
+
}
|
|
246
262
|
}).timeout(this.PUBLISH_TIMEOUT, `${this.PUBLISH_ERROR_MSG}${exchange}`);
|
|
247
263
|
}
|
|
248
264
|
|
package/src/mock.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
2
|
import 'jest';
|
|
3
|
+
import { IAfRabbitMq } from './index';
|
|
3
4
|
|
|
4
|
-
class RabbitMq {
|
|
5
|
-
|
|
5
|
+
class RabbitMq implements IAfRabbitMq {
|
|
6
|
+
ack: any = jest.fn();
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
nack: any = jest.fn();
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
assertChannel: any = jest.fn();
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
assertExchange: any = jest.fn();
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
assertQueue: any = jest.fn();
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
consume: any = jest.fn();
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
consumeFromExchange: any = jest.fn();
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
publish: any = jest.fn();
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
sendToQueue: any = jest.fn();
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export default RabbitMq;
|