@motiadev/adapter-rabbitmq-events 0.9.3-beta.148 → 0.9.4-beta.150
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbitmq-event-adapter.d.ts","sourceRoot":"","sources":["../src/rabbitmq-event-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAG1F,OAAO,KAAK,EAAE,0BAA0B,EAA4B,MAAM,SAAS,CAAA;AAEnF,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,iBAAiB,CAAQ;gBAErB,MAAM,EAAE,0BAA0B;
|
|
1
|
+
{"version":3,"file":"rabbitmq-event-adapter.d.ts","sourceRoot":"","sources":["../src/rabbitmq-event-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAG1F,OAAO,KAAK,EAAE,0BAA0B,EAA4B,MAAM,SAAS,CAAA;AAEnF,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,OAAO,CAAuB;IACtC,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,iBAAiB,CAAQ;gBAErB,MAAM,EAAE,0BAA0B;YAahC,gBAAgB;YAUhB,OAAO;YA4CP,qBAAqB;IAuB7B,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB/C,SAAS,CAAC,KAAK,EACnB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EACtD,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,kBAAkB,CAAC;IAuGxB,WAAW,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBzB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIpD,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAGtC"}
|
|
@@ -18,6 +18,8 @@ class RabbitMQEventAdapter {
|
|
|
18
18
|
connectionTimeout: 10000,
|
|
19
19
|
reconnectDelay: 5000,
|
|
20
20
|
prefetch: 1,
|
|
21
|
+
deadLetterExchange: `${config.exchangeName}.dlq`,
|
|
22
|
+
deadLetterRoutingKey: 'dlq',
|
|
21
23
|
...config,
|
|
22
24
|
};
|
|
23
25
|
}
|
|
@@ -122,6 +124,21 @@ class RabbitMQEventAdapter {
|
|
|
122
124
|
if (options?.type === 'fifo') {
|
|
123
125
|
queueArgs['x-single-active-consumer'] = true;
|
|
124
126
|
}
|
|
127
|
+
const dlqExchange = this.config.deadLetterExchange;
|
|
128
|
+
const dlqQueueName = `${queueName}.dlq`;
|
|
129
|
+
const dlqRoutingKey = `${queueName}.${this.config.deadLetterRoutingKey}`;
|
|
130
|
+
await channel.assertExchange(dlqExchange, 'direct', {
|
|
131
|
+
durable: this.config.durable,
|
|
132
|
+
autoDelete: this.config.autoDelete,
|
|
133
|
+
});
|
|
134
|
+
await channel.assertQueue(dlqQueueName, {
|
|
135
|
+
durable: this.config.durable,
|
|
136
|
+
exclusive: false,
|
|
137
|
+
autoDelete: !this.config.durable,
|
|
138
|
+
});
|
|
139
|
+
await channel.bindQueue(dlqQueueName, dlqExchange, dlqRoutingKey);
|
|
140
|
+
queueArgs['x-dead-letter-exchange'] = dlqExchange;
|
|
141
|
+
queueArgs['x-dead-letter-routing-key'] = dlqRoutingKey;
|
|
125
142
|
const queue = await channel.assertQueue(queueName, {
|
|
126
143
|
durable: subscribeOptions.durable ?? true,
|
|
127
144
|
exclusive: subscribeOptions.exclusive ?? false,
|
|
@@ -135,26 +152,32 @@ class RabbitMQEventAdapter {
|
|
|
135
152
|
const consumerTag = await channel.consume(queue.queue, async (msg) => {
|
|
136
153
|
if (!msg)
|
|
137
154
|
return;
|
|
155
|
+
const retryCount = msg.properties.headers?.['x-retry-count'] || 0;
|
|
156
|
+
if (options?.maxRetries && retryCount >= options.maxRetries) {
|
|
157
|
+
console.warn(`[RabbitMQ] Message exceeded max retries (${options.maxRetries}), sending to DLQ`);
|
|
158
|
+
channel.nack(msg, false, false);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
138
161
|
try {
|
|
139
|
-
const retryCount = msg.properties.headers?.['x-retry-count'] || 0;
|
|
140
|
-
if (options?.maxRetries && retryCount >= options.maxRetries) {
|
|
141
|
-
console.warn(`[RabbitMQ] Message exceeded max retries (${options.maxRetries})`);
|
|
142
|
-
channel.nack(msg, false, false);
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
162
|
const content = JSON.parse(msg.content.toString());
|
|
146
163
|
await handler(content);
|
|
147
164
|
channel.ack(msg);
|
|
148
165
|
}
|
|
149
166
|
catch (error) {
|
|
150
167
|
console.error('[RabbitMQ] Error processing message:', error);
|
|
151
|
-
if (options?.maxRetries) {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
168
|
+
if (options?.maxRetries && retryCount < options.maxRetries) {
|
|
169
|
+
const headers = msg.properties.headers || {};
|
|
170
|
+
headers['x-retry-count'] = retryCount + 1;
|
|
171
|
+
const republishOptions = {
|
|
172
|
+
...msg.properties,
|
|
173
|
+
headers,
|
|
174
|
+
persistent: this.config.durable,
|
|
175
|
+
};
|
|
176
|
+
channel.sendToQueue(queue.queue, msg.content, republishOptions);
|
|
177
|
+
channel.ack(msg);
|
|
178
|
+
return;
|
|
157
179
|
}
|
|
180
|
+
console.warn('[RabbitMQ] Sending failed message to DLQ');
|
|
158
181
|
channel.nack(msg, false, false);
|
|
159
182
|
}
|
|
160
183
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export interface RabbitMQEventAdapterConfig {
|
|
2
2
|
url: string;
|
|
3
|
-
exchangeName: string;
|
|
4
3
|
exchangeType: 'direct' | 'topic' | 'fanout' | 'headers';
|
|
4
|
+
exchangeName: string;
|
|
5
5
|
durable?: boolean;
|
|
6
6
|
autoDelete?: boolean;
|
|
7
7
|
connectionTimeout?: number;
|
|
8
8
|
reconnectDelay?: number;
|
|
9
9
|
prefetch?: number;
|
|
10
|
+
deadLetterExchange?: string;
|
|
11
|
+
deadLetterRoutingKey?: string;
|
|
10
12
|
}
|
|
11
13
|
export interface RabbitMQSubscribeOptions {
|
|
12
14
|
queue?: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,0BAA0B;IACzC,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IACvD,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
|
package/package.json
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"description": "RabbitMQ event adapter for Motia framework, enabling distributed event handling across multiple instances.",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
-
"version": "0.9.
|
|
6
|
+
"version": "0.9.4-beta.150",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"amqplib": "^0.10.4",
|
|
9
9
|
"uuid": "^11.1.0",
|
|
10
|
-
"@motiadev/core": "0.9.
|
|
10
|
+
"@motiadev/core": "0.9.4-beta.150"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@types/amqplib": "^0.10.5",
|