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