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