@autofleet/rabbit 1.0.4 → 1.0.5

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 CHANGED
@@ -1,30 +1,22 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  const index_1 = require("./index");
12
- const init = () => __awaiter(this, void 0, void 0, function* () {
4
+ const init = async () => {
13
5
  const rabbit = new index_1.default();
14
- yield rabbit.consumeFromExchange('test-q2', 'test-e', (msg, ack) => {
6
+ await rabbit.consumeFromExchange('test-q2', 'test-e', (msg, ack) => {
15
7
  console.log('msg2', msg.content);
16
8
  // ack(msg);
17
9
  });
18
- yield rabbit.consumeFromExchange('test-q', 'test-e', (msg, ack) => {
10
+ await rabbit.consumeFromExchange('test-q', 'test-e', (msg, ack) => {
19
11
  console.log('msg', msg.content);
20
12
  ack(msg);
21
13
  });
22
- yield rabbit.publish('test-e', 'hey');
23
- yield rabbit.publish('test-e', 'hey1');
24
- yield rabbit.consume('test-q-2', (msg, ack) => {
14
+ await rabbit.publish('test-e', 'hey');
15
+ await rabbit.publish('test-e', 'hey1');
16
+ await rabbit.consume('test-q-2', (msg, ack) => {
25
17
  console.log('msg-q', msg.content);
26
18
  ack(msg);
27
19
  });
28
- yield rabbit.sendToQueue('test-q-2', 'hey-q');
29
- });
20
+ await rabbit.sendToQueue('test-q-2', 'hey-q');
21
+ };
30
22
  init();
package/dist/index.js CHANGED
@@ -1,12 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
2
  Object.defineProperty(exports, "__esModule", { value: true });
11
3
  const amqplib_1 = require("amqplib");
12
4
  const events_1 = require("events");
@@ -37,73 +29,59 @@ class RabbitMq {
37
29
  catch (e) { }
38
30
  return Object.assign({}, msg, { content });
39
31
  }
40
- assertChannel() {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
43
- if (this.channel) {
44
- return resolve(this.channel);
45
- }
46
- if (this.creatingChannel) {
47
- return this.em.on(channelCreatedConst, resolve);
48
- }
49
- this.creatingChannel = true;
50
- let connection, channel;
51
- let host = process.env.RABBITMQ_SERVICE_HOST || '35.240.13.28';
52
- try {
53
- connection = yield amqplib_1.connect(`amqp://${host}`);
54
- channel = yield connection.createChannel();
55
- this.channel = channel;
56
- this.creatingChannel = false;
57
- this.em.emit(channelCreatedConst, channel);
58
- resolve(channel);
59
- }
60
- catch (e) {
61
- reject(e);
62
- }
63
- }));
32
+ async assertChannel() {
33
+ return new Promise(async (resolve, reject) => {
34
+ if (this.channel) {
35
+ return resolve(this.channel);
36
+ }
37
+ if (this.creatingChannel) {
38
+ return this.em.on(channelCreatedConst, resolve);
39
+ }
40
+ this.creatingChannel = true;
41
+ let connection, channel;
42
+ let host = process.env.RABBITMQ_SERVICE_HOST || '35.240.13.28';
43
+ try {
44
+ connection = await amqplib_1.connect(`amqp://${host}`);
45
+ channel = await connection.createChannel();
46
+ this.channel = channel;
47
+ this.creatingChannel = false;
48
+ this.em.emit(channelCreatedConst, channel);
49
+ resolve(channel);
50
+ }
51
+ catch (e) {
52
+ reject(e);
53
+ }
64
54
  });
65
55
  }
66
- assertExchange(exchange, options) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const channel = yield this.assertChannel();
69
- return channel.assertExchange(exchange, 'fanout');
70
- });
56
+ async assertExchange(exchange, options) {
57
+ const channel = await this.assertChannel();
58
+ return channel.assertExchange(exchange, 'fanout');
71
59
  }
72
- assertQueue(queue, options) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const channel = yield this.assertChannel();
75
- return channel.assertQueue(queue);
76
- });
60
+ async assertQueue(queue, options) {
61
+ const channel = await this.assertChannel();
62
+ return channel.assertQueue(queue);
77
63
  }
78
- consume(queue, callback) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const channel = yield this.assertChannel();
81
- yield this.assertQueue(queue);
82
- return channel.consume(queue, (msg) => callback(RabbitMq.parseMsg(msg), this.ack));
83
- });
64
+ async consume(queue, callback) {
65
+ const channel = await this.assertChannel();
66
+ await this.assertQueue(queue);
67
+ return channel.consume(queue, (msg) => callback(RabbitMq.parseMsg(msg), this.ack));
84
68
  }
85
- consumeFromExchange(queue, exchange, callback) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- const channel = yield this.assertChannel();
88
- yield Promise.all([
89
- this.assertExchange(exchange),
90
- this.assertQueue(queue),
91
- ]);
92
- yield channel.bindQueue(queue, exchange, '');
93
- return channel.consume(queue, (msg) => callback(RabbitMq.parseMsg(msg), this.ack));
94
- });
69
+ async consumeFromExchange(queue, exchange, callback) {
70
+ const channel = await this.assertChannel();
71
+ await Promise.all([
72
+ this.assertExchange(exchange),
73
+ this.assertQueue(queue),
74
+ ]);
75
+ await channel.bindQueue(queue, exchange, '');
76
+ return channel.consume(queue, (msg) => callback(RabbitMq.parseMsg(msg), this.ack));
95
77
  }
96
- publish(exchange, content) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const channel = yield this.assertChannel();
99
- return channel.publish(exchange, '', Buffer.from(content));
100
- });
78
+ async publish(exchange, content) {
79
+ const channel = await this.assertChannel();
80
+ return channel.publish(exchange, '', Buffer.from(content));
101
81
  }
102
- sendToQueue(queue, content) {
103
- return __awaiter(this, void 0, void 0, function* () {
104
- const channel = yield this.assertChannel();
105
- return channel.sendToQueue(queue, Buffer.from(content));
106
- });
82
+ async sendToQueue(queue, content) {
83
+ const channel = await this.assertChannel();
84
+ return channel.sendToQueue(queue, Buffer.from(content));
107
85
  }
108
86
  }
109
87
  exports.default = RabbitMq;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/tsconfig.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es6",
3
+ "target": "es2017",
4
4
  "module": "commonjs",
5
+ "lib": [
6
+ "es2017"
7
+ ],
5
8
  "declaration": true,
6
9
  "outDir": "./dist",
7
10
  "strict": true