@btffamily/chekaam 1.0.6 → 1.0.7
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.
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Channel, ConsumeMessage } from 'amqplib';
|
|
1
|
+
import { Channel, ConsumeMessage, Options } from 'amqplib';
|
|
2
2
|
interface IConsumer {
|
|
3
3
|
channel: Channel | null;
|
|
4
4
|
exchange: string;
|
|
5
5
|
queueName: string;
|
|
6
6
|
router: string;
|
|
7
|
+
queueOptions: Options.AssertQueue;
|
|
7
8
|
listen(): Promise<any>;
|
|
8
9
|
}
|
|
9
10
|
declare class Consumer implements IConsumer {
|
|
@@ -11,6 +12,7 @@ declare class Consumer implements IConsumer {
|
|
|
11
12
|
exchange: any;
|
|
12
13
|
queueName: any;
|
|
13
14
|
router: any;
|
|
15
|
+
queueOptions: Options.AssertQueue;
|
|
14
16
|
constructor(channel: Channel | null);
|
|
15
17
|
/**
|
|
16
18
|
* @name listen
|
|
@@ -18,7 +20,7 @@ declare class Consumer implements IConsumer {
|
|
|
18
20
|
* @param log
|
|
19
21
|
* @returns
|
|
20
22
|
*/
|
|
21
|
-
listen(log?: boolean): Promise<
|
|
23
|
+
listen(log?: boolean): Promise<void>;
|
|
22
24
|
/**
|
|
23
25
|
* @name parseMessage
|
|
24
26
|
* @param message
|
|
@@ -6,6 +6,10 @@ class Consumer {
|
|
|
6
6
|
exchange;
|
|
7
7
|
queueName;
|
|
8
8
|
router;
|
|
9
|
+
queueOptions = {
|
|
10
|
+
durable: true,
|
|
11
|
+
autoDelete: false,
|
|
12
|
+
};
|
|
9
13
|
constructor(channel) {
|
|
10
14
|
this.channel = channel;
|
|
11
15
|
}
|
|
@@ -24,15 +28,12 @@ class Consumer {
|
|
|
24
28
|
durable: true, // The queue will survive a broker restart,
|
|
25
29
|
});
|
|
26
30
|
// Assert a queue to ensure it exists.
|
|
27
|
-
const conQueue = await this.channel.assertQueue(this.queueName,
|
|
28
|
-
durable: true,
|
|
29
|
-
autoDelete: false
|
|
30
|
-
});
|
|
31
|
+
const conQueue = await this.channel.assertQueue(this.queueName, this.queueOptions);
|
|
31
32
|
// bind the queue to the exchange
|
|
32
33
|
await this.channel.bindQueue(conQueue.queue, this.exchange, this.router);
|
|
33
34
|
// consume message
|
|
34
35
|
// noAck means you want to acknowledge manually
|
|
35
|
-
this.channel.consume(conQueue.queue, (message) => {
|
|
36
|
+
await this.channel.consume(conQueue.queue, (message) => {
|
|
36
37
|
if (message) {
|
|
37
38
|
if (log === true) {
|
|
38
39
|
console.log(`Message recieved from ${this.exchange}/${this.queueName}`);
|