gcf-common-lib 0.23.28 → 0.23.30
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/package.json +1 -1
- package/src/index.js +6 -1
- package/src/index.ts +7 -1
- package/src/utils.js +1 -1
- package/src/utils.ts +3 -3
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -103,7 +103,12 @@ class GcfCommon {
|
|
|
103
103
|
return (0, utils_1.withAmqpCh)((ch) => __awaiter(this, void 0, void 0, function* () {
|
|
104
104
|
const payload = Buffer.from(JSON.stringify(json !== null && json !== void 0 ? json : {}));
|
|
105
105
|
yield ch.assertQueue(queue, this.amqpOptions.assertOptions);
|
|
106
|
-
ch.sendToQueue(queue, payload, this.amqpOptions.publishOptions)
|
|
106
|
+
yield new Promise((resolve, reject) => ch.sendToQueue(queue, payload, this.amqpOptions.publishOptions, (err, ok) => {
|
|
107
|
+
if (err)
|
|
108
|
+
reject(err);
|
|
109
|
+
else
|
|
110
|
+
resolve(ok);
|
|
111
|
+
}));
|
|
107
112
|
}), this.amqpOptions.url);
|
|
108
113
|
}
|
|
109
114
|
});
|
package/src/index.ts
CHANGED
|
@@ -87,7 +87,13 @@ export class GcfCommon {
|
|
|
87
87
|
return withAmqpCh(async ch => {
|
|
88
88
|
const payload = Buffer.from(JSON.stringify(json ?? {}));
|
|
89
89
|
await ch.assertQueue(queue, this.amqpOptions.assertOptions);
|
|
90
|
-
|
|
90
|
+
|
|
91
|
+
await new Promise((resolve, reject) =>
|
|
92
|
+
ch.sendToQueue(queue, payload, this.amqpOptions.publishOptions, (err, ok) => {
|
|
93
|
+
if (err) reject(err); else resolve(ok);
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
|
|
91
97
|
}, this.amqpOptions.url as string);
|
|
92
98
|
}
|
|
93
99
|
}
|
package/src/utils.js
CHANGED
|
@@ -96,7 +96,7 @@ function withAmqpCh(fn, url) {
|
|
|
96
96
|
return withAmqpConn((conn) => __awaiter(this, void 0, void 0, function* () {
|
|
97
97
|
function withDisposer() {
|
|
98
98
|
return bluebird_1.default.method(() => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
return conn.
|
|
99
|
+
return conn.createConfirmChannel();
|
|
100
100
|
}))().disposer((ch, promise) => delay(1000).then(() => ch.close()));
|
|
101
101
|
}
|
|
102
102
|
return bluebird_1.default.using(withDisposer(), (ch) => fn(ch));
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Channel, connect, Connection, Options } from 'amqplib';
|
|
1
|
+
import { Channel, ConfirmChannel, connect, Connection, Options } from 'amqplib';
|
|
2
2
|
import Bluebird from 'bluebird';
|
|
3
3
|
import { Dictionary } from 'lodash';
|
|
4
4
|
|
|
@@ -79,11 +79,11 @@ export async function withAmqpConn(fn: (conn: Connection) => Promise<any>, url:
|
|
|
79
79
|
return Bluebird.using(withDisposer(), (conn) => fn(conn));
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
export async function withAmqpCh(fn: (ch:
|
|
82
|
+
export async function withAmqpCh(fn: (ch: ConfirmChannel) => Promise<any>, url: string) {
|
|
83
83
|
return withAmqpConn(async conn => {
|
|
84
84
|
function withDisposer() {
|
|
85
85
|
return Bluebird.method(async () => {
|
|
86
|
-
return conn.
|
|
86
|
+
return conn.createConfirmChannel();
|
|
87
87
|
})().disposer((ch, promise) => delay(1000).then(() => ch.close()));
|
|
88
88
|
}
|
|
89
89
|
|