@autofleet/rabbit 1.5.0-2 → 1.5.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/example.js +5 -5
- package/dist/index.js +6 -6
- package/package.json +2 -2
- package/src/example.ts +5 -5
- package/src/index.ts +7 -6
package/dist/example.js
CHANGED
|
@@ -10,22 +10,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const index_1 = require("./index");
|
|
13
|
-
// process.env.RABBITMQ_SERVICE_HOST=
|
|
13
|
+
// process.env.RABBITMQ_SERVICE_HOST = '34.76.123.137:5672';
|
|
14
14
|
const init = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
15
|
const rabbit = new index_1.default();
|
|
16
16
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
17
|
yield rabbit.consumeFromExchange('test-q2', 'test-e', (msg, ack) => {
|
|
18
|
-
console.log('msg2', msg.content);
|
|
19
|
-
|
|
18
|
+
console.log('consumeFromExchange: msg2', msg.content);
|
|
19
|
+
ack(msg);
|
|
20
20
|
});
|
|
21
21
|
yield rabbit.consumeFromExchange('test-q', 'test-e', (msg, ack) => {
|
|
22
|
-
console.log('msg', msg.content);
|
|
22
|
+
console.log('consumeFromExchange: msg', msg.content);
|
|
23
23
|
ack(msg);
|
|
24
24
|
});
|
|
25
25
|
yield rabbit.publish('test-e', 'hey');
|
|
26
26
|
yield rabbit.publish('test-e', 'hey1');
|
|
27
27
|
yield rabbit.consume('test-q-2', (msg, ack) => {
|
|
28
|
-
console.log('msg-q', msg.content);
|
|
28
|
+
console.log('consume: msg-q', msg.content);
|
|
29
29
|
ack(msg);
|
|
30
30
|
});
|
|
31
31
|
yield rabbit.sendToQueue('test-q-2', 'hey-q');
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,7 @@ const bluebird = require("bluebird");
|
|
|
14
14
|
const amqp_connection_manager_1 = require("amqp-connection-manager");
|
|
15
15
|
const events_1 = require("events");
|
|
16
16
|
const rabbitError_1 = require("./rabbitError");
|
|
17
|
+
const assertExchangeFanout = (c, exchangeName) => c.assertExchange(exchangeName, 'fanout');
|
|
17
18
|
const connectionCreatedConst = 'connectionCreated';
|
|
18
19
|
class RabbitMq {
|
|
19
20
|
constructor() {
|
|
@@ -111,7 +112,7 @@ class RabbitMq {
|
|
|
111
112
|
return this.exchanges[exchangeName];
|
|
112
113
|
}
|
|
113
114
|
return channel.addSetup((c) => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
const exchange = yield c
|
|
115
|
+
const exchange = yield assertExchangeFanout(c, exchangeName);
|
|
115
116
|
this.exchanges[exchangeName] = exchange;
|
|
116
117
|
return exchange;
|
|
117
118
|
}));
|
|
@@ -131,8 +132,8 @@ class RabbitMq {
|
|
|
131
132
|
RabbitMq.validateName('queue', queue);
|
|
132
133
|
const { limit } = (options && options.limit) ? options : { limit: 1 };
|
|
133
134
|
const channel = yield this.assertChannel();
|
|
134
|
-
yield this.assertQueue(queue);
|
|
135
135
|
return channel.addSetup((c) => __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
yield c.assertQueue(queue);
|
|
136
137
|
yield c.prefetch(limit, true);
|
|
137
138
|
return Promise.all([
|
|
138
139
|
c.consume(queue, (msg) => callback(RabbitMq.parseMsg(msg), this.ack, this.nack(queue))),
|
|
@@ -147,11 +148,10 @@ class RabbitMq {
|
|
|
147
148
|
RabbitMq.validateName('exchange', exchange);
|
|
148
149
|
const { limit } = (options && options.limit) ? options : { limit: 1 };
|
|
149
150
|
const channel = yield this.assertChannel();
|
|
150
|
-
yield Promise.all([
|
|
151
|
-
this.assertExchange(exchange),
|
|
152
|
-
this.assertQueue(queue),
|
|
153
|
-
]);
|
|
154
151
|
return channel.addSetup((c) => __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const assertExchange = yield assertExchangeFanout(c, exchange);
|
|
153
|
+
yield c.assertQueue(queue);
|
|
154
|
+
this.exchanges[exchange] = assertExchange;
|
|
155
155
|
yield c.prefetch(limit, true);
|
|
156
156
|
return Promise.all([
|
|
157
157
|
c.bindQueue(queue, exchange, ''),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"prepublish": "tsc",
|
|
10
10
|
"linter": "./node_modules/.bin/eslint .",
|
|
11
11
|
"test": "jest --forceExit",
|
|
12
|
-
"test-local": "RABBITMQ_SERVICE_HOST=34.76.
|
|
12
|
+
"test-local": "RABBITMQ_SERVICE_HOST=34.76.123.137:5672 jest --forceExit",
|
|
13
13
|
"coverage": "jest --coverage --forceExit --runInBand && rm -rf ./coverage",
|
|
14
14
|
"dev": "nodemon"
|
|
15
15
|
},
|
package/src/example.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import RabbitMq from './index';
|
|
2
2
|
|
|
3
|
-
// process.env.RABBITMQ_SERVICE_HOST=
|
|
3
|
+
// process.env.RABBITMQ_SERVICE_HOST = '34.76.123.137:5672';
|
|
4
4
|
|
|
5
5
|
const init = async () => {
|
|
6
6
|
const rabbit = new RabbitMq();
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
8
|
await rabbit.consumeFromExchange('test-q2', 'test-e', (msg, ack) => {
|
|
9
|
-
console.log('msg2', msg.content);
|
|
10
|
-
|
|
9
|
+
console.log('consumeFromExchange: msg2', msg.content);
|
|
10
|
+
ack(msg);
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
await rabbit.consumeFromExchange('test-q', 'test-e', (msg, ack) => {
|
|
14
|
-
console.log('msg', msg.content);
|
|
14
|
+
console.log('consumeFromExchange: msg', msg.content);
|
|
15
15
|
ack(msg);
|
|
16
16
|
});
|
|
17
17
|
await rabbit.publish('test-e', 'hey');
|
|
18
18
|
await rabbit.publish('test-e', 'hey1');
|
|
19
19
|
|
|
20
20
|
await rabbit.consume('test-q-2', (msg, ack) => {
|
|
21
|
-
console.log('msg-q', msg.content);
|
|
21
|
+
console.log('consume: msg-q', msg.content);
|
|
22
22
|
ack(msg);
|
|
23
23
|
});
|
|
24
24
|
await rabbit.sendToQueue('test-q-2', 'hey-q');
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,8 @@ interface ExchangesCache {
|
|
|
9
9
|
[key: string]: any
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
const assertExchangeFanout = (c: any, exchangeName: string) => c.assertExchange(exchangeName, 'fanout');
|
|
13
|
+
|
|
12
14
|
const connectionCreatedConst = 'connectionCreated';
|
|
13
15
|
class RabbitMq {
|
|
14
16
|
static parseMsg(msg: any) {
|
|
@@ -126,7 +128,7 @@ class RabbitMq {
|
|
|
126
128
|
return this.exchanges[exchangeName];
|
|
127
129
|
}
|
|
128
130
|
return channel.addSetup(async (c: ConfirmChannel) => {
|
|
129
|
-
const exchange = await c
|
|
131
|
+
const exchange = await assertExchangeFanout(c, exchangeName);
|
|
130
132
|
this.exchanges[exchangeName] = exchange;
|
|
131
133
|
return exchange;
|
|
132
134
|
});
|
|
@@ -144,8 +146,8 @@ class RabbitMq {
|
|
|
144
146
|
RabbitMq.validateName('queue', queue);
|
|
145
147
|
const { limit } = (options && options.limit) ? options : { limit: 1 };
|
|
146
148
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
147
|
-
await this.assertQueue(queue);
|
|
148
149
|
return channel.addSetup(async (c: ConfirmChannel) => {
|
|
150
|
+
await c.assertQueue(queue);
|
|
149
151
|
await c.prefetch(limit, true);
|
|
150
152
|
return Promise.all([
|
|
151
153
|
c.consume(queue, (msg: any) => callback(RabbitMq.parseMsg(msg), this.ack, this.nack(queue))),
|
|
@@ -159,12 +161,11 @@ class RabbitMq {
|
|
|
159
161
|
RabbitMq.validateName('exchange', exchange);
|
|
160
162
|
const { limit } = (options && options.limit) ? options : { limit: 1 };
|
|
161
163
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
162
|
-
await Promise.all([
|
|
163
|
-
this.assertExchange(exchange),
|
|
164
|
-
this.assertQueue(queue),
|
|
165
|
-
]);
|
|
166
164
|
|
|
167
165
|
return channel.addSetup(async (c: ConfirmChannel) => {
|
|
166
|
+
const assertExchange = await assertExchangeFanout(c, exchange);
|
|
167
|
+
await c.assertQueue(queue);
|
|
168
|
+
this.exchanges[exchange] = assertExchange;
|
|
168
169
|
await c.prefetch(limit, true);
|
|
169
170
|
return Promise.all([
|
|
170
171
|
c.bindQueue(queue, exchange, ''),
|