@autofleet/rabbit 1.0.16 → 1.0.18
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.js +5 -13
- package/package.json +1 -1
- package/src/index.ts +5 -13
package/dist/index.js
CHANGED
|
@@ -26,12 +26,6 @@ class RabbitMq {
|
|
|
26
26
|
this.em = new events_1.EventEmitter;
|
|
27
27
|
this.channel = null;
|
|
28
28
|
this.connection = null;
|
|
29
|
-
process.once('SIGINT', () => {
|
|
30
|
-
console.log('Removing channel');
|
|
31
|
-
if (this.channel) {
|
|
32
|
-
this.channel.close();
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
29
|
}
|
|
36
30
|
async getConnection() {
|
|
37
31
|
if (this.connection !== null) {
|
|
@@ -51,9 +45,7 @@ class RabbitMq {
|
|
|
51
45
|
try {
|
|
52
46
|
connection = await this.getConnection();
|
|
53
47
|
if (this.channel === null) {
|
|
54
|
-
this.channel = connection.createChannel({
|
|
55
|
-
json: true,
|
|
56
|
-
});
|
|
48
|
+
this.channel = connection.createChannel({});
|
|
57
49
|
}
|
|
58
50
|
resolve(this.channel);
|
|
59
51
|
}
|
|
@@ -77,7 +69,7 @@ class RabbitMq {
|
|
|
77
69
|
return channel.addSetup((c) => {
|
|
78
70
|
return Promise.all([
|
|
79
71
|
c.prefetch(limit, false),
|
|
80
|
-
c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
|
|
72
|
+
c.consume(queue, (msg) => callback(JSON.parse(msg), this.ack, this.nack(queue))),
|
|
81
73
|
]);
|
|
82
74
|
});
|
|
83
75
|
}
|
|
@@ -92,19 +84,19 @@ class RabbitMq {
|
|
|
92
84
|
return Promise.all([
|
|
93
85
|
c.prefetch(limit, false),
|
|
94
86
|
c.bindQueue(queue, exchange, ''),
|
|
95
|
-
c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
|
|
87
|
+
c.consume(queue, (msg) => callback(JSON.parse(msg), this.ack, this.nack(queue))),
|
|
96
88
|
]);
|
|
97
89
|
});
|
|
98
90
|
}
|
|
99
91
|
async publish(exchange, content) {
|
|
100
92
|
const channel = await this.assertChannel();
|
|
101
93
|
await this.assertExchange(exchange);
|
|
102
|
-
return channel.publish(exchange, '', Buffer.from(content));
|
|
94
|
+
return channel.publish(exchange, '', Buffer.from(JSON.stringify(content)));
|
|
103
95
|
}
|
|
104
96
|
async sendToQueue(queue, content) {
|
|
105
97
|
const channel = await this.assertChannel();
|
|
106
98
|
await this.assertQueue(queue);
|
|
107
|
-
return channel.sendToQueue(queue, Buffer.from(content));
|
|
99
|
+
return channel.sendToQueue(queue, Buffer.from(JSON.stringify(content)));
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
102
|
exports.default = RabbitMq;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -11,12 +11,6 @@ class RabbitMq {
|
|
|
11
11
|
this.em = new EventEmitter;
|
|
12
12
|
this.channel = null;
|
|
13
13
|
this.connection = null;
|
|
14
|
-
process.once('SIGINT', () => {
|
|
15
|
-
console.log('Removing channel');
|
|
16
|
-
if(this.channel) {
|
|
17
|
-
this.channel.close();
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
14
|
}
|
|
21
15
|
|
|
22
16
|
public ack = async (msg: any) => {
|
|
@@ -61,9 +55,7 @@ class RabbitMq {
|
|
|
61
55
|
try {
|
|
62
56
|
connection = await this.getConnection();
|
|
63
57
|
if (this.channel === null) {
|
|
64
|
-
this.channel = connection.createChannel({
|
|
65
|
-
json: true,
|
|
66
|
-
});
|
|
58
|
+
this.channel = connection.createChannel({});
|
|
67
59
|
}
|
|
68
60
|
resolve(this.channel);
|
|
69
61
|
} catch (e) {
|
|
@@ -89,7 +81,7 @@ class RabbitMq {
|
|
|
89
81
|
return channel.addSetup((c: ConfirmChannel) => {
|
|
90
82
|
return Promise.all([
|
|
91
83
|
c.prefetch(limit, false),
|
|
92
|
-
c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
|
|
84
|
+
c.consume(queue, (msg : any) => callback(JSON.parse(msg), this.ack, this.nack(queue))),
|
|
93
85
|
]);
|
|
94
86
|
});
|
|
95
87
|
}
|
|
@@ -106,7 +98,7 @@ class RabbitMq {
|
|
|
106
98
|
return Promise.all([
|
|
107
99
|
c.prefetch(limit, false),
|
|
108
100
|
c.bindQueue(queue, exchange, ''),
|
|
109
|
-
c.consume(queue, (msg
|
|
101
|
+
c.consume(queue, (msg: any) => callback(JSON.parse(msg), this.ack, this.nack(queue))),
|
|
110
102
|
])
|
|
111
103
|
})
|
|
112
104
|
}
|
|
@@ -114,13 +106,13 @@ class RabbitMq {
|
|
|
114
106
|
async publish(exchange: string, content: any) {
|
|
115
107
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
116
108
|
await this.assertExchange(exchange);
|
|
117
|
-
return channel.publish(exchange, '', Buffer.from(content));
|
|
109
|
+
return channel.publish(exchange, '', Buffer.from(JSON.stringify(content)));
|
|
118
110
|
}
|
|
119
111
|
|
|
120
112
|
async sendToQueue(queue: string, content: any) {
|
|
121
113
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
122
114
|
await this.assertQueue(queue);
|
|
123
|
-
return channel.sendToQueue(queue, Buffer.from(content));
|
|
115
|
+
return channel.sendToQueue(queue, Buffer.from(JSON.stringify(content)));
|
|
124
116
|
}
|
|
125
117
|
}
|
|
126
118
|
|