@avtechno/sfr 1.0.6 → 1.0.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/dist/mq.mjs +38 -26
- package/dist/sfr-pipeline.mjs +3 -5
- package/dist/types/mq.d.mts +11 -7
- package/package.json +2 -2
- package/src/mq.mts +52 -43
- package/src/sfr-pipeline.mts +3 -5
- package/src/types/index.d.ts +8 -10
package/dist/mq.mjs
CHANGED
|
@@ -63,15 +63,18 @@ export class BaseMQ {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* BroadcastMQ class to handle different types of broadcast communication patterns:
|
|
66
|
+
* BroadcastMQ class to handle different types of broadcast communication patterns: Fanout, Direct, and Topic.
|
|
67
67
|
*/
|
|
68
68
|
export class BroadcastMQ extends BaseMQ {
|
|
69
69
|
channel;
|
|
70
70
|
type;
|
|
71
|
-
|
|
71
|
+
exchange_options;
|
|
72
|
+
constructor(channel, type, exchange_options) {
|
|
72
73
|
super(channel, type);
|
|
73
74
|
this.channel = channel;
|
|
74
75
|
this.type = type;
|
|
76
|
+
this.exchange_options = exchange_options;
|
|
77
|
+
this.exchange_options = exchange_options || { durable: false };
|
|
75
78
|
}
|
|
76
79
|
/**
|
|
77
80
|
* Publishes a message to the specified exchange based on the communication pattern.
|
|
@@ -82,23 +85,23 @@ export class BroadcastMQ extends BaseMQ {
|
|
|
82
85
|
* @param options - Additional publishing options.
|
|
83
86
|
* @example
|
|
84
87
|
* // Publish a message to a 'logsExchange' with a routing key 'error' for a routing pattern.
|
|
85
|
-
* const mq = new BroadcastMQ(channel, "
|
|
88
|
+
* const mq = new BroadcastMQ(channel, "Direct");
|
|
86
89
|
* mq.publish("logsExchange", "error", { level: "error", message: "Something went wrong" });
|
|
87
90
|
*/
|
|
88
91
|
async publish(exchange, key = "", payload, options) {
|
|
89
92
|
switch (this.type) {
|
|
90
|
-
case "
|
|
91
|
-
await this.channel.assertExchange(exchange, "fanout",
|
|
93
|
+
case "Fanout": {
|
|
94
|
+
await this.channel.assertExchange(exchange, "fanout", this.exchange_options);
|
|
92
95
|
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
93
96
|
break;
|
|
94
97
|
}
|
|
95
|
-
case "
|
|
96
|
-
await this.channel.assertExchange(exchange, "direct",
|
|
98
|
+
case "Direct": {
|
|
99
|
+
await this.channel.assertExchange(exchange, "direct", this.exchange_options);
|
|
97
100
|
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
98
101
|
break;
|
|
99
102
|
}
|
|
100
103
|
case "Topic": {
|
|
101
|
-
await this.channel.assertExchange(exchange, "topic",
|
|
104
|
+
await this.channel.assertExchange(exchange, "topic", this.exchange_options);
|
|
102
105
|
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
103
106
|
break;
|
|
104
107
|
}
|
|
@@ -112,36 +115,39 @@ export class BroadcastMQ extends BaseMQ {
|
|
|
112
115
|
* @param cfg - Configuration options for the consumer, including the callback function.
|
|
113
116
|
* @param options - Additional consumption options.
|
|
114
117
|
* @example
|
|
115
|
-
* // Subscribe to the 'logsExchange' for all 'error' messages in the
|
|
116
|
-
* const mq = new BroadcastMQ(channel, "
|
|
118
|
+
* // Subscribe to the 'logsExchange' for all 'error' messages in the Direct pattern.
|
|
119
|
+
* const mq = new BroadcastMQ(channel, "Direct");
|
|
117
120
|
* mq.subscribe("logsExchange", "error", { fn: handleErrorLogs, options: { noAck: true } });
|
|
118
121
|
*/
|
|
119
|
-
async subscribe(exchange, key, cfg
|
|
122
|
+
async subscribe(exchange, key, cfg) {
|
|
120
123
|
let fn = cfg.fn.bind({ channel: this.channel, type: this.type });
|
|
121
124
|
switch (this.type) {
|
|
122
|
-
case "
|
|
123
|
-
await this.channel.assertExchange(exchange, "fanout",
|
|
125
|
+
case "Fanout": {
|
|
126
|
+
await this.channel.assertExchange(exchange, "fanout", this.exchange_options);
|
|
124
127
|
const { queue } = await this.channel.assertQueue("", { exclusive: true });
|
|
125
128
|
this.channel.bindQueue(queue, exchange, "");
|
|
126
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.
|
|
129
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
127
130
|
break;
|
|
128
131
|
}
|
|
129
|
-
case "
|
|
130
|
-
await this.channel.assertExchange(exchange, "direct",
|
|
132
|
+
case "Direct": {
|
|
133
|
+
await this.channel.assertExchange(exchange, "direct", this.exchange_options);
|
|
131
134
|
const { queue } = await this.channel.assertQueue("", { exclusive: true });
|
|
132
135
|
await this.channel.bindQueue(queue, exchange, key);
|
|
133
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), options);
|
|
136
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
134
137
|
break;
|
|
135
138
|
}
|
|
136
139
|
case "Topic": {
|
|
137
|
-
await this.channel.assertExchange(exchange, "topic",
|
|
140
|
+
await this.channel.assertExchange(exchange, "topic", this.exchange_options);
|
|
138
141
|
const { queue } = await this.channel.assertQueue("", { exclusive: true });
|
|
139
142
|
this.channel.bindQueue(queue, exchange, key);
|
|
140
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), options);
|
|
143
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
141
144
|
break;
|
|
142
145
|
}
|
|
143
146
|
}
|
|
144
147
|
}
|
|
148
|
+
set_options(options) {
|
|
149
|
+
this.exchange_options = options;
|
|
150
|
+
}
|
|
145
151
|
}
|
|
146
152
|
/**
|
|
147
153
|
* TargetedMQ class to handle Point-to-Point and Request-Reply communication patterns.
|
|
@@ -149,10 +155,13 @@ export class BroadcastMQ extends BaseMQ {
|
|
|
149
155
|
export class TargetedMQ extends BaseMQ {
|
|
150
156
|
channel;
|
|
151
157
|
type;
|
|
152
|
-
|
|
158
|
+
queue_options;
|
|
159
|
+
constructor(channel, type, queue_options) {
|
|
153
160
|
super(channel, type);
|
|
154
161
|
this.channel = channel;
|
|
155
162
|
this.type = type;
|
|
163
|
+
this.queue_options = queue_options;
|
|
164
|
+
this.queue_options = queue_options || { durable: true };
|
|
156
165
|
}
|
|
157
166
|
/**
|
|
158
167
|
* Sends a message to the specified queue depending on the communication pattern.
|
|
@@ -169,11 +178,11 @@ export class TargetedMQ extends BaseMQ {
|
|
|
169
178
|
/* Alter produce strategy depending on the instance's configured comm pattern */
|
|
170
179
|
switch (this.type) {
|
|
171
180
|
case "Point-to-Point": {
|
|
172
|
-
await this.channel.assertQueue(binding);
|
|
181
|
+
await this.channel.assertQueue(binding, this.queue_options);
|
|
173
182
|
return this.channel.sendToQueue(binding, encode_payload(payload), options);
|
|
174
183
|
}
|
|
175
184
|
case "Request-Reply": {
|
|
176
|
-
await this.channel.assertQueue(binding);
|
|
185
|
+
await this.channel.assertQueue(binding, this.queue_options);
|
|
177
186
|
return this.channel.sendToQueue(binding, encode_payload(payload), options);
|
|
178
187
|
}
|
|
179
188
|
}
|
|
@@ -192,17 +201,20 @@ export class TargetedMQ extends BaseMQ {
|
|
|
192
201
|
let fn = cfg.fn.bind({ channel: this.channel, type: this.type });
|
|
193
202
|
switch (this.type) {
|
|
194
203
|
case "Point-to-Point": {
|
|
195
|
-
await this.channel.assertQueue(queue,
|
|
196
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.
|
|
204
|
+
await this.channel.assertQueue(queue, this.queue_options);
|
|
205
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
197
206
|
break;
|
|
198
207
|
}
|
|
199
208
|
case "Request-Reply": {
|
|
200
|
-
await this.channel.assertQueue(queue,
|
|
201
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.
|
|
209
|
+
await this.channel.assertQueue(queue, this.queue_options);
|
|
210
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
202
211
|
break;
|
|
203
212
|
}
|
|
204
213
|
}
|
|
205
214
|
}
|
|
215
|
+
set_options(options) {
|
|
216
|
+
this.queue_options = options;
|
|
217
|
+
}
|
|
206
218
|
}
|
|
207
219
|
/* Helper Functions */
|
|
208
220
|
/**
|
package/dist/sfr-pipeline.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { BroadcastMQ, TargetedMQ } from "./mq.mjs";
|
|
|
5
5
|
import j2s from "joi-to-swagger";
|
|
6
6
|
import { logger } from "./logger.mjs";
|
|
7
7
|
const CWD = process.cwd();
|
|
8
|
-
const PATTERNS = ["Point-to-Point", "Request-Reply", "
|
|
8
|
+
const PATTERNS = ["Point-to-Point", "Request-Reply", "Fanout", "Direct", "Topic"];
|
|
9
9
|
const TARGETED_PATTERN = ["Point-to-Point", "Request-Reply"];
|
|
10
10
|
export class SFRPipeline {
|
|
11
11
|
cfg;
|
|
@@ -219,15 +219,13 @@ export class SFRPipeline {
|
|
|
219
219
|
/* bind validators */
|
|
220
220
|
if (mq instanceof TargetedMQ) {
|
|
221
221
|
mq.consume(dir, {
|
|
222
|
-
|
|
223
|
-
queue_options: handler.queue_options,
|
|
222
|
+
options: handler.options,
|
|
224
223
|
fn: validator_fn
|
|
225
224
|
});
|
|
226
225
|
}
|
|
227
226
|
if (mq instanceof BroadcastMQ) {
|
|
228
227
|
mq.subscribe(dir, handler.key, {
|
|
229
|
-
|
|
230
|
-
consume_options: handler.consume_options,
|
|
228
|
+
options: handler.options,
|
|
231
229
|
fn: validator_fn
|
|
232
230
|
});
|
|
233
231
|
}
|
package/dist/types/mq.d.mts
CHANGED
|
@@ -44,12 +44,13 @@ export declare class BaseMQ {
|
|
|
44
44
|
reply(msg: ConsumeMessage, payload: any): Promise<void>;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* BroadcastMQ class to handle different types of broadcast communication patterns:
|
|
47
|
+
* BroadcastMQ class to handle different types of broadcast communication patterns: Fanout, Direct, and Topic.
|
|
48
48
|
*/
|
|
49
49
|
export declare class BroadcastMQ extends BaseMQ {
|
|
50
50
|
channel: Channel;
|
|
51
51
|
protected type: CommunicationPattern;
|
|
52
|
-
|
|
52
|
+
protected exchange_options?: Options.AssertExchange;
|
|
53
|
+
constructor(channel: Channel, type: CommunicationPattern, exchange_options?: Options.AssertExchange);
|
|
53
54
|
/**
|
|
54
55
|
* Publishes a message to the specified exchange based on the communication pattern.
|
|
55
56
|
*
|
|
@@ -59,7 +60,7 @@ export declare class BroadcastMQ extends BaseMQ {
|
|
|
59
60
|
* @param options - Additional publishing options.
|
|
60
61
|
* @example
|
|
61
62
|
* // Publish a message to a 'logsExchange' with a routing key 'error' for a routing pattern.
|
|
62
|
-
* const mq = new BroadcastMQ(channel, "
|
|
63
|
+
* const mq = new BroadcastMQ(channel, "Direct");
|
|
63
64
|
* mq.publish("logsExchange", "error", { level: "error", message: "Something went wrong" });
|
|
64
65
|
*/
|
|
65
66
|
publish(exchange: string, key: string, payload: any, options?: Options.Publish): Promise<void>;
|
|
@@ -71,11 +72,12 @@ export declare class BroadcastMQ extends BaseMQ {
|
|
|
71
72
|
* @param cfg - Configuration options for the consumer, including the callback function.
|
|
72
73
|
* @param options - Additional consumption options.
|
|
73
74
|
* @example
|
|
74
|
-
* // Subscribe to the 'logsExchange' for all 'error' messages in the
|
|
75
|
-
* const mq = new BroadcastMQ(channel, "
|
|
75
|
+
* // Subscribe to the 'logsExchange' for all 'error' messages in the Direct pattern.
|
|
76
|
+
* const mq = new BroadcastMQ(channel, "Direct");
|
|
76
77
|
* mq.subscribe("logsExchange", "error", { fn: handleErrorLogs, options: { noAck: true } });
|
|
77
78
|
*/
|
|
78
|
-
subscribe(exchange: string, key: string, cfg: ConsumerConfig
|
|
79
|
+
subscribe(exchange: string, key: string, cfg: ConsumerConfig): Promise<void>;
|
|
80
|
+
set_options(options: Options.AssertExchange): void;
|
|
79
81
|
}
|
|
80
82
|
/**
|
|
81
83
|
* TargetedMQ class to handle Point-to-Point and Request-Reply communication patterns.
|
|
@@ -83,7 +85,8 @@ export declare class BroadcastMQ extends BaseMQ {
|
|
|
83
85
|
export declare class TargetedMQ extends BaseMQ {
|
|
84
86
|
channel: Channel;
|
|
85
87
|
protected type: CommunicationPattern;
|
|
86
|
-
|
|
88
|
+
protected queue_options?: Options.AssertQueue;
|
|
89
|
+
constructor(channel: Channel, type: CommunicationPattern, queue_options?: Options.AssertQueue);
|
|
87
90
|
/**
|
|
88
91
|
* Sends a message to the specified queue depending on the communication pattern.
|
|
89
92
|
*
|
|
@@ -107,4 +110,5 @@ export declare class TargetedMQ extends BaseMQ {
|
|
|
107
110
|
* mq.consume("taskQueue", { fn: processTask, options: { noAck: true } });
|
|
108
111
|
*/
|
|
109
112
|
consume(queue: string, cfg: ConsumerConfig): Promise<void>;
|
|
113
|
+
set_options(options: Options.AssertQueue): void;
|
|
110
114
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avtechno/sfr",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "An opinionated way of writing services using ExpressJS.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"winston": "^3.17.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/amqplib": "^0.10.
|
|
40
|
+
"@types/amqplib": "^0.10.3",
|
|
41
41
|
"@types/express": "^4.17.19",
|
|
42
42
|
"@types/express-session": "^1.18.0",
|
|
43
43
|
"@types/js-yaml": "^4.0.7",
|
package/src/mq.mts
CHANGED
|
@@ -64,13 +64,13 @@ export class BaseMQ{
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* BroadcastMQ class to handle different types of broadcast communication patterns:
|
|
67
|
+
* BroadcastMQ class to handle different types of broadcast communication patterns: Fanout, Direct, and Topic.
|
|
68
68
|
*/
|
|
69
69
|
export class BroadcastMQ extends BaseMQ{
|
|
70
|
-
constructor(public channel: Channel, protected type: CommunicationPattern) {
|
|
70
|
+
constructor(public channel: Channel, protected type: CommunicationPattern, protected exchange_options? : Options.AssertExchange) {
|
|
71
71
|
super(channel, type);
|
|
72
|
+
this.exchange_options = exchange_options || { durable : false };
|
|
72
73
|
}
|
|
73
|
-
|
|
74
74
|
/**
|
|
75
75
|
* Publishes a message to the specified exchange based on the communication pattern.
|
|
76
76
|
*
|
|
@@ -80,28 +80,28 @@ export class BroadcastMQ extends BaseMQ{
|
|
|
80
80
|
* @param options - Additional publishing options.
|
|
81
81
|
* @example
|
|
82
82
|
* // Publish a message to a 'logsExchange' with a routing key 'error' for a routing pattern.
|
|
83
|
-
* const mq = new BroadcastMQ(channel, "
|
|
83
|
+
* const mq = new BroadcastMQ(channel, "Direct");
|
|
84
84
|
* mq.publish("logsExchange", "error", { level: "error", message: "Something went wrong" });
|
|
85
85
|
*/
|
|
86
86
|
async publish(exchange: string, key: string = "", payload: any, options?: Options.Publish) {
|
|
87
87
|
switch (this.type) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
case "Fanout": {
|
|
89
|
+
await this.channel.assertExchange(exchange, "fanout", this.exchange_options);
|
|
90
|
+
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
case "Direct": {
|
|
95
|
+
await this.channel.assertExchange(exchange, "direct", this.exchange_options);
|
|
96
|
+
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
case "Topic": {
|
|
101
|
+
await this.channel.assertExchange(exchange, "topic", this.exchange_options);
|
|
102
|
+
this.channel.publish(exchange, key, encode_payload(payload), options);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -113,55 +113,59 @@ export class BroadcastMQ extends BaseMQ{
|
|
|
113
113
|
* @param cfg - Configuration options for the consumer, including the callback function.
|
|
114
114
|
* @param options - Additional consumption options.
|
|
115
115
|
* @example
|
|
116
|
-
* // Subscribe to the 'logsExchange' for all 'error' messages in the
|
|
117
|
-
* const mq = new BroadcastMQ(channel, "
|
|
116
|
+
* // Subscribe to the 'logsExchange' for all 'error' messages in the Direct pattern.
|
|
117
|
+
* const mq = new BroadcastMQ(channel, "Direct");
|
|
118
118
|
* mq.subscribe("logsExchange", "error", { fn: handleErrorLogs, options: { noAck: true } });
|
|
119
119
|
*/
|
|
120
120
|
async subscribe(
|
|
121
121
|
exchange: string,
|
|
122
122
|
key: string,
|
|
123
123
|
cfg: ConsumerConfig,
|
|
124
|
-
options?: Options.Publish
|
|
125
124
|
) {
|
|
126
125
|
let fn = cfg.fn.bind({ channel: this.channel, type: this.type });
|
|
127
126
|
|
|
128
127
|
switch (this.type) {
|
|
129
|
-
case "
|
|
130
|
-
await this.channel.assertExchange(exchange, "fanout",
|
|
128
|
+
case "Fanout": {
|
|
129
|
+
await this.channel.assertExchange(exchange, "fanout", this.exchange_options);
|
|
131
130
|
const { queue } = await this.channel.assertQueue("", { exclusive: true });
|
|
132
131
|
|
|
133
132
|
this.channel.bindQueue(queue, exchange, "");
|
|
134
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.
|
|
133
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
135
134
|
break;
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
case "
|
|
139
|
-
await this.channel.assertExchange(exchange, "direct",
|
|
137
|
+
case "Direct": {
|
|
138
|
+
await this.channel.assertExchange(exchange, "direct", this.exchange_options);
|
|
140
139
|
const { queue } = await this.channel.assertQueue("", { exclusive: true });
|
|
141
140
|
await this.channel.bindQueue(queue, exchange, key);
|
|
142
141
|
|
|
143
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), options);
|
|
142
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
144
143
|
break;
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
case "Topic": {
|
|
148
|
-
await this.channel.assertExchange(exchange, "topic",
|
|
147
|
+
await this.channel.assertExchange(exchange, "topic", this.exchange_options);
|
|
149
148
|
const { queue } = await this.channel.assertQueue("", { exclusive: true });
|
|
150
149
|
|
|
151
150
|
this.channel.bindQueue(queue, exchange, key);
|
|
152
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), options);
|
|
151
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
153
152
|
break;
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
155
|
}
|
|
156
|
+
|
|
157
|
+
set_options(options : Options.AssertExchange){
|
|
158
|
+
this.exchange_options = options;
|
|
159
|
+
}
|
|
157
160
|
}
|
|
158
161
|
|
|
159
162
|
/**
|
|
160
163
|
* TargetedMQ class to handle Point-to-Point and Request-Reply communication patterns.
|
|
161
164
|
*/
|
|
162
165
|
export class TargetedMQ extends BaseMQ{
|
|
163
|
-
constructor(public channel: Channel, protected type: CommunicationPattern) {
|
|
166
|
+
constructor(public channel: Channel, protected type: CommunicationPattern, protected queue_options? : Options.AssertQueue) {
|
|
164
167
|
super(channel, type);
|
|
168
|
+
this.queue_options = queue_options || { durable : true };
|
|
165
169
|
}
|
|
166
170
|
/**
|
|
167
171
|
* Sends a message to the specified queue depending on the communication pattern.
|
|
@@ -177,15 +181,15 @@ export class TargetedMQ extends BaseMQ{
|
|
|
177
181
|
async produce(binding: string, payload: any, options?: Options.Publish) {
|
|
178
182
|
/* Alter produce strategy depending on the instance's configured comm pattern */
|
|
179
183
|
switch (this.type) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
case "Point-to-Point": {
|
|
185
|
+
await this.channel.assertQueue(binding, this.queue_options);
|
|
186
|
+
return this.channel.sendToQueue(binding, encode_payload(payload), options);
|
|
187
|
+
}
|
|
184
188
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
+
case "Request-Reply": {
|
|
190
|
+
await this.channel.assertQueue(binding, this.queue_options);
|
|
191
|
+
return this.channel.sendToQueue(binding, encode_payload(payload), options);
|
|
192
|
+
}
|
|
189
193
|
}
|
|
190
194
|
}
|
|
191
195
|
|
|
@@ -204,18 +208,23 @@ export class TargetedMQ extends BaseMQ{
|
|
|
204
208
|
|
|
205
209
|
switch (this.type) {
|
|
206
210
|
case "Point-to-Point": {
|
|
207
|
-
await this.channel.assertQueue(queue,
|
|
208
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.
|
|
211
|
+
await this.channel.assertQueue(queue, this.queue_options);
|
|
212
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
209
213
|
break;
|
|
210
214
|
}
|
|
211
215
|
|
|
212
216
|
case "Request-Reply": {
|
|
213
|
-
await this.channel.assertQueue(queue,
|
|
214
|
-
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.
|
|
217
|
+
await this.channel.assertQueue(queue, this.queue_options);
|
|
218
|
+
this.channel.consume(queue, (v) => fn(parse_payload(v)), cfg.options);
|
|
215
219
|
break;
|
|
216
220
|
}
|
|
217
221
|
}
|
|
218
222
|
}
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
set_options(options : Options.AssertQueue){
|
|
226
|
+
this.queue_options = options;
|
|
227
|
+
}
|
|
219
228
|
}
|
|
220
229
|
|
|
221
230
|
/* Helper Functions */
|
package/src/sfr-pipeline.mts
CHANGED
|
@@ -8,7 +8,7 @@ import {logger} from "./logger.mjs";
|
|
|
8
8
|
|
|
9
9
|
const CWD = process.cwd();
|
|
10
10
|
|
|
11
|
-
const PATTERNS: CommunicationPattern[] = ["Point-to-Point", "Request-Reply", "
|
|
11
|
+
const PATTERNS: CommunicationPattern[] = ["Point-to-Point", "Request-Reply", "Fanout", "Direct", "Topic"];
|
|
12
12
|
const TARGETED_PATTERN = ["Point-to-Point", "Request-Reply"];
|
|
13
13
|
|
|
14
14
|
export class SFRPipeline {
|
|
@@ -231,16 +231,14 @@ export class SFRPipeline {
|
|
|
231
231
|
/* bind validators */
|
|
232
232
|
if (mq instanceof TargetedMQ) {
|
|
233
233
|
mq.consume(dir, {
|
|
234
|
-
|
|
235
|
-
queue_options : handler.queue_options,
|
|
234
|
+
options : handler.options,
|
|
236
235
|
fn: validator_fn
|
|
237
236
|
})
|
|
238
237
|
}
|
|
239
238
|
|
|
240
239
|
if (mq instanceof BroadcastMQ) {
|
|
241
240
|
mq.subscribe(dir, handler.key, {
|
|
242
|
-
|
|
243
|
-
consume_options: handler.consume_options,
|
|
241
|
+
options : handler.options,
|
|
244
242
|
fn : validator_fn
|
|
245
243
|
});
|
|
246
244
|
}
|
package/src/types/index.d.ts
CHANGED
|
@@ -284,8 +284,7 @@ declare type QueueOptions = import("amqplib").Options.AssertQueue;
|
|
|
284
284
|
declare type ConsumeOptions = import("amqplib").Options.Consume;
|
|
285
285
|
|
|
286
286
|
declare type ConsumerConfig = {
|
|
287
|
-
|
|
288
|
-
consume_options?: ConsumeOptions;
|
|
287
|
+
options?: ConsumeOptions;
|
|
289
288
|
fn: ((msg: ConsumeMessage) => void);
|
|
290
289
|
} & ThisType<ConsumerContext>;
|
|
291
290
|
declare type ConsumerContext = {
|
|
@@ -298,18 +297,18 @@ declare type ConsumerContext = {
|
|
|
298
297
|
/* Commons */
|
|
299
298
|
type CommunicationPattern = (
|
|
300
299
|
"Point-to-Point" |
|
|
301
|
-
"
|
|
300
|
+
"Fanout" |
|
|
302
301
|
"Request-Reply" |
|
|
303
|
-
"
|
|
302
|
+
"Direct" |
|
|
304
303
|
"Topic"
|
|
305
304
|
/* "Scatter-Gather" */
|
|
306
305
|
)
|
|
307
306
|
|
|
308
307
|
declare type PatternMQSet = {
|
|
309
308
|
"Point-to-Point": TargetedMQ;
|
|
310
|
-
"
|
|
309
|
+
"Fanout": BroadcastMQ;
|
|
311
310
|
"Request-Reply": TargetedMQ;
|
|
312
|
-
"
|
|
311
|
+
"Direct": TargetedMQ;
|
|
313
312
|
"Topic": TargetedMQ;
|
|
314
313
|
}
|
|
315
314
|
|
|
@@ -322,9 +321,9 @@ declare type MQHandlerDescriptor<V, H, C> = {
|
|
|
322
321
|
|
|
323
322
|
declare type MQRequestHandlers<C> = {
|
|
324
323
|
"Point-to-Point"?: MQRequestHandlerMap & ThisType<{ mq: Omit<TargetedMQ, "type" | "reply"> } & C>;
|
|
325
|
-
"
|
|
324
|
+
"Fanout"?: MQRequestHandlerMap & ThisType<{ mq: Omit<BroadcastMQ, "type"> } & C>;
|
|
326
325
|
"Request-Reply"?: MQRequestHandlerMap & ThisType<{ mq: Omit<TargetedMQ, "type"> } & C>;
|
|
327
|
-
"
|
|
326
|
+
"Direct"?: RoutingHandlerMap & ThisType<{ mq: Omit<BroadcastMQ, "type"> } & C>;
|
|
328
327
|
"Topic"?: TopicHandlerMap & ThisType<{ mq: Omit<BroadcastMQ, "type"> } & C>;
|
|
329
328
|
};
|
|
330
329
|
|
|
@@ -341,8 +340,7 @@ declare type TopicHandlerMap = {
|
|
|
341
340
|
}
|
|
342
341
|
|
|
343
342
|
declare type MQConsumeOptions = {
|
|
344
|
-
|
|
345
|
-
consume_options?: ConsumeOptions;
|
|
343
|
+
options?: ConsumeOptions;
|
|
346
344
|
key? : string;
|
|
347
345
|
fn: MQRequestHandler;
|
|
348
346
|
}
|