@autofleet/rabbit 1.0.15 → 1.0.17
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 +2 -2
- package/dist/index.js +15 -25
- package/package.json +1 -1
- package/src/index.ts +16 -25
package/dist/index.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ declare class RabbitMq {
|
|
|
12
12
|
assertChannel(): Promise<ChannelWrapper>;
|
|
13
13
|
assertExchange(exchange: string, options?: any): Promise<void>;
|
|
14
14
|
assertQueue(queue: string, options?: any): Promise<void>;
|
|
15
|
-
consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any
|
|
16
|
-
consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any
|
|
15
|
+
consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
16
|
+
consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
17
17
|
publish(exchange: string, content: any): Promise<void>;
|
|
18
18
|
sendToQueue(queue: string, content: any): Promise<void>;
|
|
19
19
|
}
|
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) {
|
|
@@ -70,35 +64,31 @@ class RabbitMq {
|
|
|
70
64
|
const channel = await this.assertChannel();
|
|
71
65
|
return channel.addSetup((c) => c.assertQueue(queue));
|
|
72
66
|
}
|
|
73
|
-
async consume(queue, callback, options
|
|
67
|
+
async consume(queue, callback, options) {
|
|
74
68
|
const { limit } = options ? options : 1;
|
|
75
69
|
const channel = await this.assertChannel();
|
|
76
70
|
await this.assertQueue(queue);
|
|
77
|
-
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
}
|
|
71
|
+
return channel.addSetup((c) => {
|
|
72
|
+
return Promise.all([
|
|
73
|
+
c.prefetch(limit, false),
|
|
74
|
+
c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
|
|
75
|
+
]);
|
|
76
|
+
});
|
|
85
77
|
}
|
|
86
|
-
async consumeFromExchange(queue, exchange, callback, options
|
|
78
|
+
async consumeFromExchange(queue, exchange, callback, options) {
|
|
87
79
|
const { limit } = options ? options : 1;
|
|
88
80
|
const channel = await this.assertChannel();
|
|
89
81
|
await Promise.all([
|
|
90
82
|
this.assertExchange(exchange),
|
|
91
83
|
this.assertQueue(queue),
|
|
92
84
|
]);
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
}
|
|
85
|
+
return channel.addSetup((c) => {
|
|
86
|
+
return Promise.all([
|
|
87
|
+
c.prefetch(limit, false),
|
|
88
|
+
c.bindQueue(queue, exchange, ''),
|
|
89
|
+
c.consume(queue, (msg) => callback(msg, this.ack, this.nack(queue))),
|
|
90
|
+
]);
|
|
91
|
+
});
|
|
102
92
|
}
|
|
103
93
|
async publish(exchange, content) {
|
|
104
94
|
const channel = await this.assertChannel();
|
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) => {
|
|
@@ -82,36 +76,33 @@ class RabbitMq {
|
|
|
82
76
|
return channel.addSetup((c: ConfirmChannel) => c.assertQueue(queue));
|
|
83
77
|
}
|
|
84
78
|
|
|
85
|
-
async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any
|
|
79
|
+
async consume(queue: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
|
|
86
80
|
const { limit } = options ? options : 1;
|
|
87
81
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
88
82
|
await this.assertQueue(queue);
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
}
|
|
83
|
+
return channel.addSetup((c: ConfirmChannel) => {
|
|
84
|
+
return Promise.all([
|
|
85
|
+
c.prefetch(limit, false),
|
|
86
|
+
c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
97
89
|
}
|
|
98
90
|
|
|
99
|
-
async consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any
|
|
91
|
+
async consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any) {
|
|
100
92
|
const { limit } = options ? options : 1;
|
|
101
93
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
102
94
|
await Promise.all([
|
|
103
95
|
this.assertExchange(exchange),
|
|
104
96
|
this.assertQueue(queue),
|
|
105
97
|
]);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
98
|
+
|
|
99
|
+
return channel.addSetup((c: ConfirmChannel) => {
|
|
100
|
+
return Promise.all([
|
|
101
|
+
c.prefetch(limit, false),
|
|
102
|
+
c.bindQueue(queue, exchange, ''),
|
|
103
|
+
c.consume(queue, (msg : any) => callback(msg, this.ack, this.nack(queue))),
|
|
104
|
+
])
|
|
105
|
+
})
|
|
115
106
|
}
|
|
116
107
|
|
|
117
108
|
async publish(exchange: string, content: any) {
|