@webda/amqp 4.0.0-beta.6 → 4.0.0-beta.8
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/README.md +5 -6
- package/lib/pubsub.service.d.ts +12 -5
- package/lib/pubsub.service.d.ts.map +1 -1
- package/lib/pubsub.service.js +19 -9
- package/lib/pubsub.service.js.map +1 -1
- package/lib/queue.service.d.ts +11 -4
- package/lib/queue.service.d.ts.map +1 -1
- package/lib/queue.service.js +18 -8
- package/lib/queue.service.js.map +1 -1
- package/package.json +5 -5
- package/webda.module.json +8 -6
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This module is part of Webda Application Framework that allows you to quickly develop applications with all modern prerequisites: Security, Extensibility, GraphQL, REST, CloudNative [https://webda.io](https://webda.io)
|
|
4
4
|
|
|
5
|
-
<img src="https://webda.io/
|
|
5
|
+
<img src="https://webda.io/img/webda.svg" width="128" />
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
@@ -13,8 +13,6 @@ This module is part of Webda Application Framework that allows you to quickly de
|
|
|
13
13
|
|
|
14
14
|
<!-- README_HEADER -->
|
|
15
15
|
|
|
16
|
-
# @webda/amqp
|
|
17
|
-
|
|
18
16
|
> RabbitMQ-backed Queue and Pub/Sub services for Webda — drop-in replacements for in-memory transports when you need durable, cross-process messaging.
|
|
19
17
|
|
|
20
18
|
## When to use it
|
|
@@ -104,6 +102,7 @@ export class OrderService extends Service {
|
|
|
104
102
|
- Related: [`@webda/core`](../core) for the `Queue` and `PubSubService` base classes, [`@webda/async`](../async) for job orchestration on top of a queue.
|
|
105
103
|
|
|
106
104
|
<!-- README_FOOTER -->
|
|
105
|
+
|
|
107
106
|
## Sponsors
|
|
108
107
|
|
|
109
108
|
<!--
|
|
@@ -112,12 +111,12 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
112
111
|
|
|
113
112
|
Arize AI is a machine learning observability and model monitoring platform. It helps you visualize, monitor, and explain your machine learning models. [Learn more](https://arize.com)
|
|
114
113
|
|
|
115
|
-
[<img src="https://
|
|
114
|
+
[<img src="https://webda.io/img/sponsors/arize.svg" width="200">](https://arize.com)
|
|
116
115
|
|
|
117
116
|
Loopingz is a software development company that provides consulting and development services. [Learn more](https://loopingz.com)
|
|
118
117
|
|
|
119
|
-
[<img src="https://
|
|
118
|
+
[<img src="https://webda.io/img/sponsors/loopingz.png" width="200">](https://loopingz.com)
|
|
120
119
|
|
|
121
120
|
Tellae is an innovative consulting firm specialized in cities transportation issues. We provide our clients, both public and private, with solutions to support your strategic and operational decisions. [Learn more](https://tellae.fr)
|
|
122
121
|
|
|
123
|
-
[<img src="https://tellae.
|
|
122
|
+
[<img src="https://webda.io/img/sponsors/tellae.svg" width="200">](https://tellae.fr)
|
package/lib/pubsub.service.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PubSubService, ServiceParameters } from "@webda/core";
|
|
1
|
+
import { PubSubService, ServiceParameters, SecretString } from "@webda/core";
|
|
2
2
|
import { CancelablePromise } from "@webda/utils";
|
|
3
3
|
import * as amqplib from "amqplib";
|
|
4
4
|
/**
|
|
@@ -7,9 +7,11 @@ import * as amqplib from "amqplib";
|
|
|
7
7
|
export declare class AMQPPubSubParameters extends ServiceParameters {
|
|
8
8
|
/**
|
|
9
9
|
* AMQP connection url
|
|
10
|
+
*
|
|
11
|
+
* Can be encrypted with `webda config encrypt`
|
|
10
12
|
* @example "amqp://localhost:5672"
|
|
11
13
|
*/
|
|
12
|
-
url: string;
|
|
14
|
+
url: string | SecretString;
|
|
13
15
|
/**
|
|
14
16
|
* Exchange name to publish to and consume from
|
|
15
17
|
*/
|
|
@@ -18,7 +20,7 @@ export declare class AMQPPubSubParameters extends ServiceParameters {
|
|
|
18
20
|
* Queue name used to subscribe, empty to let the broker generate one
|
|
19
21
|
* @default ""
|
|
20
22
|
*/
|
|
21
|
-
subscription
|
|
23
|
+
subscription: string;
|
|
22
24
|
exchange?: {
|
|
23
25
|
/**
|
|
24
26
|
* @default fanout
|
|
@@ -65,9 +67,14 @@ export declare class AMQPPubSubParameters extends ServiceParameters {
|
|
|
65
67
|
* @WebdaModda AMQPPubSub
|
|
66
68
|
*/
|
|
67
69
|
export default class AMQPPubSubService<T = any, K extends AMQPPubSubParameters = AMQPPubSubParameters> extends PubSubService<T, K> {
|
|
68
|
-
channel
|
|
69
|
-
conn
|
|
70
|
+
channel?: amqplib.Channel;
|
|
71
|
+
conn?: amqplib.ChannelModel;
|
|
70
72
|
exchange: amqplib.Replies.AssertExchange;
|
|
73
|
+
/**
|
|
74
|
+
* @returns the active AMQP channel
|
|
75
|
+
* @throws CodeError when the service is not connected
|
|
76
|
+
*/
|
|
77
|
+
protected getChannel(): amqplib.Channel;
|
|
71
78
|
/**
|
|
72
79
|
* @override
|
|
73
80
|
* @param event - the event to publish
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsub.service.d.ts","sourceRoot":"","sources":["../src/pubsub.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"pubsub.service.d.ts","sourceRoot":"","sources":["../src/pubsub.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAa,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB;IACzD;;;;;OAKG;IACH,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;IAC3B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE;QACT;;WAEG;QACH,IAAI,CAAC,EAAE,M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ClB,iBAAiB,CAqCnB;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/pubsub.service.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PubSubService, ServiceParameters } from "@webda/core";
|
|
1
|
+
import { PubSubService, ServiceParameters, SecretString, WebdaError } from "@webda/core";
|
|
2
2
|
import { CancelablePromise, JSONUtils } from "@webda/utils";
|
|
3
3
|
import * as amqplib from "amqplib";
|
|
4
4
|
/**
|
|
@@ -26,6 +26,16 @@ export class AMQPPubSubParameters extends ServiceParameters {
|
|
|
26
26
|
* @WebdaModda AMQPPubSub
|
|
27
27
|
*/
|
|
28
28
|
export default class AMQPPubSubService extends PubSubService {
|
|
29
|
+
/**
|
|
30
|
+
* @returns the active AMQP channel
|
|
31
|
+
* @throws CodeError when the service is not connected
|
|
32
|
+
*/
|
|
33
|
+
getChannel() {
|
|
34
|
+
if (!this.channel) {
|
|
35
|
+
throw new WebdaError.CodeError("AMQP_NOT_CONNECTED", "AMQP service is not connected");
|
|
36
|
+
}
|
|
37
|
+
return this.channel;
|
|
38
|
+
}
|
|
29
39
|
/**
|
|
30
40
|
* @override
|
|
31
41
|
* @param event - the event to publish
|
|
@@ -33,7 +43,7 @@ export default class AMQPPubSubService extends PubSubService {
|
|
|
33
43
|
*/
|
|
34
44
|
async sendMessage(event, routingKey = "") {
|
|
35
45
|
this.metrics.messages_sent.inc();
|
|
36
|
-
this.
|
|
46
|
+
this.getChannel().publish(this.parameters.channel, routingKey, Buffer.from(JSONUtils.stringify(event)));
|
|
37
47
|
}
|
|
38
48
|
/**
|
|
39
49
|
* @override
|
|
@@ -41,11 +51,11 @@ export default class AMQPPubSubService extends PubSubService {
|
|
|
41
51
|
*/
|
|
42
52
|
async init() {
|
|
43
53
|
await super.init();
|
|
44
|
-
this.conn = await amqplib.connect(this.parameters.url);
|
|
54
|
+
this.conn = await amqplib.connect(SecretString.unwrap(this.parameters.url));
|
|
45
55
|
this.channel = await this.conn.createChannel();
|
|
46
56
|
const params = { ...this.parameters.exchange };
|
|
47
57
|
delete params.type;
|
|
48
|
-
this.exchange = await this.
|
|
58
|
+
this.exchange = await this.getChannel().assertExchange(this.parameters.channel, this.parameters.exchange?.type || "fanout", params);
|
|
49
59
|
return this;
|
|
50
60
|
}
|
|
51
61
|
/**
|
|
@@ -68,7 +78,7 @@ export default class AMQPPubSubService extends PubSubService {
|
|
|
68
78
|
* @returns the number of messages in the subscription queue
|
|
69
79
|
*/
|
|
70
80
|
async size() {
|
|
71
|
-
return (await this.
|
|
81
|
+
return (await this.getChannel().assertQueue(this.parameters.subscription)).messageCount;
|
|
72
82
|
}
|
|
73
83
|
/**
|
|
74
84
|
* Work a queue calling the callback with every Event received
|
|
@@ -81,13 +91,13 @@ export default class AMQPPubSubService extends PubSubService {
|
|
|
81
91
|
consume(callback, eventPrototype, onBind) {
|
|
82
92
|
let consumerTag;
|
|
83
93
|
return new CancelablePromise(async (_resolve, reject) => {
|
|
84
|
-
const queue = await this.
|
|
94
|
+
const queue = await this.getChannel().assertQueue(this.parameters.subscription, {
|
|
85
95
|
exclusive: true,
|
|
86
96
|
durable: false,
|
|
87
97
|
autoDelete: true
|
|
88
98
|
});
|
|
89
|
-
await this.
|
|
90
|
-
consumerTag = (await this.
|
|
99
|
+
await this.getChannel().bindQueue(queue.queue, this.parameters.channel, "*");
|
|
100
|
+
consumerTag = (await this.getChannel().consume(queue.queue, async (msg) => {
|
|
91
101
|
if (msg === null) {
|
|
92
102
|
reject("Cancelled by server");
|
|
93
103
|
return;
|
|
@@ -96,7 +106,7 @@ export default class AMQPPubSubService extends PubSubService {
|
|
|
96
106
|
const end = this.metrics.processing_duration.startTimer();
|
|
97
107
|
try {
|
|
98
108
|
await callback(this.unserialize(msg?.content.toString() || "", eventPrototype));
|
|
99
|
-
this.
|
|
109
|
+
this.getChannel().ack(msg);
|
|
100
110
|
}
|
|
101
111
|
catch (err) {
|
|
102
112
|
this.metrics.errors.inc();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsub.service.js","sourceRoot":"","sources":["../src/pubsub.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"pubsub.service.js","sourceRoot":"","sources":["../src/pubsub.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,iBAAiB;IAkDzD;;;;OAIG;IACH,IAAI,CAAC,MAAM,GAAQ,EAAE;;QACnB,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnB,IAAI,CAAC,QAAQ,KAAb,IAAI,CAAC,QAAQ,GAAK,EAAE,EAAC;QACrB,MAAA,IAAI,CAAC,QAAQ,EAAC,IAAI,QAAJ,IAAI,GAAK,QAAQ,EAAC;QAChC,IAAI,CAAC,YAAY,KAAjB,IAAI,CAAC,YAAY,GAAK,EAAE,EAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,iBAGnB,SAAQ,aAAmB;IAK3B;;;OAGG;IACO,UAAU;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,UAAU,CAAC,SAAS,CAAC,oBAAoB,EAAE,+BAA+B,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,KAAQ,EAAE,UAAU,GAAW,EAAE;QACjD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,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C,GAAG,CAAC,GAAG,CAAC,CAAC;gBAC7B,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;oBAC1B,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,GAAG,CAAC,CAAC;gBAClE,CAAC;wBAAS,CAAC;oBACT,GAAG,EAAE,CAAC;gBACR,CAAC;YACH,CAAC,CAAC,CACH,CAAC,WAAW,CAAC;YACd,MAAM,EAAE,EAAE,CAAC;QACb,CAAC,EACD,KAAK,IAAI,EAAE;YACT,IAAI,WAAW,EAAE,CAAC;gBAChB,MAAM,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/queue.service.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageReceipt, Queue, QueueParameters } from "@webda/core";
|
|
1
|
+
import { MessageReceipt, Queue, QueueParameters, SecretString } from "@webda/core";
|
|
2
2
|
import * as amqplib from "amqplib";
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for {@link AMQPQueue}
|
|
@@ -6,9 +6,11 @@ import * as amqplib from "amqplib";
|
|
|
6
6
|
export declare class AMQPQueueParameters extends QueueParameters {
|
|
7
7
|
/**
|
|
8
8
|
* AMQP connection url
|
|
9
|
+
*
|
|
10
|
+
* Can be encrypted with `webda config encrypt`
|
|
9
11
|
* @example "amqp://localhost:5672"
|
|
10
12
|
*/
|
|
11
|
-
url: string;
|
|
13
|
+
url: string | SecretString;
|
|
12
14
|
/**
|
|
13
15
|
* Queue name
|
|
14
16
|
*/
|
|
@@ -24,8 +26,13 @@ export declare class AMQPQueueParameters extends QueueParameters {
|
|
|
24
26
|
* @WebdaModda
|
|
25
27
|
*/
|
|
26
28
|
export default class AMQPQueue<T = any, K extends AMQPQueueParameters = AMQPQueueParameters> extends Queue<T, K> {
|
|
27
|
-
channel
|
|
28
|
-
conn
|
|
29
|
+
channel?: amqplib.Channel;
|
|
30
|
+
conn?: amqplib.ChannelModel;
|
|
31
|
+
/**
|
|
32
|
+
* @returns the active AMQP channel
|
|
33
|
+
* @throws CodeError when the service is not connected
|
|
34
|
+
*/
|
|
35
|
+
protected getChannel(): amqplib.Channel;
|
|
29
36
|
/**
|
|
30
37
|
* @override
|
|
31
38
|
* @returns this service
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.service.d.ts","sourceRoot":"","sources":["../src/queue.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"queue.service.d.ts","sourceRoot":"","sources":["../src/queue.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,eAAe,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAE/F,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,eAAe;IACtD;;;;;OAKG;IACH,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;IAC3B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CAAE,SAAQ,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9G,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC;IAE5B;;;OAGG;IACH,SAAS,CAAC,UAAU,IAAI,OAAO,CAAC,OAAO,CAKtC;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAM1B;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAU1B;IAED;;;OAGG;IACG,WAAW,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAGzC;IAED;;;;OAIG;IACG,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAWzE;IAED;;;OAGG;IACG,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7C;IAED;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAE5B;IAED;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7B;CACF;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/lib/queue.service.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Queue, QueueParameters } from "@webda/core";
|
|
1
|
+
import { Queue, QueueParameters, SecretString, WebdaError } from "@webda/core";
|
|
2
2
|
import { JSONUtils } from "@webda/utils";
|
|
3
3
|
import * as amqplib from "amqplib";
|
|
4
4
|
/**
|
|
@@ -12,15 +12,25 @@ export class AMQPQueueParameters extends QueueParameters {
|
|
|
12
12
|
* @WebdaModda
|
|
13
13
|
*/
|
|
14
14
|
export default class AMQPQueue extends Queue {
|
|
15
|
+
/**
|
|
16
|
+
* @returns the active AMQP channel
|
|
17
|
+
* @throws CodeError when the service is not connected
|
|
18
|
+
*/
|
|
19
|
+
getChannel() {
|
|
20
|
+
if (!this.channel) {
|
|
21
|
+
throw new WebdaError.CodeError("AMQP_NOT_CONNECTED", "AMQP service is not connected");
|
|
22
|
+
}
|
|
23
|
+
return this.channel;
|
|
24
|
+
}
|
|
15
25
|
/**
|
|
16
26
|
* @override
|
|
17
27
|
* @returns this service
|
|
18
28
|
*/
|
|
19
29
|
async init() {
|
|
20
30
|
await super.init();
|
|
21
|
-
this.conn = await amqplib.connect(this.parameters.url);
|
|
31
|
+
this.conn = await amqplib.connect(SecretString.unwrap(this.parameters.url));
|
|
22
32
|
this.channel = await this.conn.createChannel();
|
|
23
|
-
await this.
|
|
33
|
+
await this.getChannel().assertQueue(this.parameters.queue, this.parameters.queueOptions);
|
|
24
34
|
return this;
|
|
25
35
|
}
|
|
26
36
|
/**
|
|
@@ -44,7 +54,7 @@ export default class AMQPQueue extends Queue {
|
|
|
44
54
|
*/
|
|
45
55
|
async sendMessage(event) {
|
|
46
56
|
this.metrics.messages_sent.inc();
|
|
47
|
-
this.
|
|
57
|
+
this.getChannel().sendToQueue(this.parameters.queue, Buffer.from(JSONUtils.stringify(event)));
|
|
48
58
|
}
|
|
49
59
|
/**
|
|
50
60
|
* @override
|
|
@@ -52,7 +62,7 @@ export default class AMQPQueue extends Queue {
|
|
|
52
62
|
* @returns the received message if any
|
|
53
63
|
*/
|
|
54
64
|
async receiveMessage(proto) {
|
|
55
|
-
const msg = await this.
|
|
65
|
+
const msg = await this.getChannel().get(this.parameters.queue);
|
|
56
66
|
if (msg === false) {
|
|
57
67
|
return [];
|
|
58
68
|
}
|
|
@@ -68,20 +78,20 @@ export default class AMQPQueue extends Queue {
|
|
|
68
78
|
* @param id - the receipt handle returned by {@link receiveMessage}
|
|
69
79
|
*/
|
|
70
80
|
async deleteMessage(id) {
|
|
71
|
-
this.
|
|
81
|
+
this.getChannel().ack(id);
|
|
72
82
|
}
|
|
73
83
|
/**
|
|
74
84
|
* @override
|
|
75
85
|
* @returns the number of messages ready in the queue
|
|
76
86
|
*/
|
|
77
87
|
async size() {
|
|
78
|
-
return (await this.
|
|
88
|
+
return (await this.getChannel().assertQueue(this.parameters.queue)).messageCount;
|
|
79
89
|
}
|
|
80
90
|
/**
|
|
81
91
|
* Purge the queue, used by tests
|
|
82
92
|
*/
|
|
83
93
|
async __clean() {
|
|
84
|
-
await this.
|
|
94
|
+
await this.getChannel().purgeQueue(this.parameters.queue);
|
|
85
95
|
}
|
|
86
96
|
}
|
|
87
97
|
export { AMQPQueue };
|
package/lib/queue.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.service.js","sourceRoot":"","sources":["../src/queue.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"queue.service.js","sourceRoot":"","sources":["../src/queue.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,eAAe;CAgBvD;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,SAAwE,SAAQ,KAAW;IAI9G;;;OAGG;IACO,UAAU;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,UAAU,CAAC,SAAS,CAAC,oBAAoB,EAAE,+BAA+B,CAAC,CAAC;QACxF,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAW,CAAC,CAAC;QACtF,IAAI,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAC/C,MAAM,IAAI,CAAC,U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H,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAI,CAAC,UAAU,EAAE,CAAC,GAAG,CAAM,EAAE,CAAC,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI;QACR,OAAO,CAAC,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;IACnF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;CACF;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webda/amqp",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"description": "Implements AMQP on webda",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"activemq",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"typings": "lib/index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"amqplib": "^0.10.9",
|
|
19
|
-
"@webda/core": "4.0.0-beta.
|
|
20
|
-
"@webda/utils": "4.0.0-beta.
|
|
19
|
+
"@webda/core": "4.0.0-beta.8",
|
|
20
|
+
"@webda/utils": "4.0.0-beta.8"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"lib",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"typescript": "7.1.0-dev.20260929.1",
|
|
41
41
|
"vite": "^6.0.0",
|
|
42
42
|
"vitest": "^4.1.2",
|
|
43
|
-
"@webda/compiler": "^4.0.0-beta.
|
|
44
|
-
"@webda/test": "4.0.0-beta.
|
|
43
|
+
"@webda/compiler": "^4.0.0-beta.8",
|
|
44
|
+
"@webda/test": "4.0.0-beta.7"
|
|
45
45
|
},
|
|
46
46
|
"nx": {
|
|
47
47
|
"implicitDependencies": [
|
package/webda.module.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
10
10
|
"additionalProperties": false,
|
|
11
11
|
"definitions": {
|
|
12
|
-
"exchange": {
|
|
12
|
+
"exchange#2": {
|
|
13
13
|
"additionalProperties": false,
|
|
14
14
|
"properties": {
|
|
15
15
|
"alternateExchange": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"type": "string"
|
|
50
50
|
},
|
|
51
51
|
"exchange": {
|
|
52
|
-
"$ref": "#/definitions/exchange"
|
|
52
|
+
"$ref": "#/definitions/exchange%232"
|
|
53
53
|
},
|
|
54
54
|
"subscription": {
|
|
55
55
|
"default": "",
|
|
@@ -61,9 +61,10 @@
|
|
|
61
61
|
"type": "string"
|
|
62
62
|
},
|
|
63
63
|
"url": {
|
|
64
|
-
"description": "AMQP connection url",
|
|
64
|
+
"description": "AMQP connection url\n\nCan be encrypted with `webda config encrypt`",
|
|
65
65
|
"example": "amqp://localhost:5672",
|
|
66
|
-
"type": "string"
|
|
66
|
+
"type": "string",
|
|
67
|
+
"x-webda-secret": true
|
|
67
68
|
},
|
|
68
69
|
"openapi": {
|
|
69
70
|
"type": "object",
|
|
@@ -125,9 +126,10 @@
|
|
|
125
126
|
"type": "string"
|
|
126
127
|
},
|
|
127
128
|
"url": {
|
|
128
|
-
"description": "AMQP connection url",
|
|
129
|
+
"description": "AMQP connection url\n\nCan be encrypted with `webda config encrypt`",
|
|
129
130
|
"example": "amqp://localhost:5672",
|
|
130
|
-
"type": "string"
|
|
131
|
+
"type": "string",
|
|
132
|
+
"x-webda-secret": true
|
|
131
133
|
},
|
|
132
134
|
"workerDelayer": {
|
|
133
135
|
"$ref": "#/definitions/WaitDelayerDefinition",
|