@palmetto/pubsub 3.0.2 → 3.1.0
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/bullmq/publisher.js +11 -10
- package/dist/bullmq/subscriber.d.ts +3 -0
- package/dist/bullmq/subscriber.js +35 -7
- package/dist/interfaces.d.ts +5 -4
- package/dist/rabbitmq/config.d.ts +4 -2
- package/dist/rabbitmq/subscriber.d.ts +1 -1
- package/dist/rabbitmq/subscriber.js +61 -28
- package/dist/subscriber.js +22 -12
- package/package.json +5 -1
package/dist/bullmq/publisher.js
CHANGED
|
@@ -41,18 +41,19 @@ class BullMqPublisher {
|
|
|
41
41
|
var _a, _b;
|
|
42
42
|
const queue = yield this.getQueue(config);
|
|
43
43
|
(_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `Publishing ${messages.length} messages to ${queue.name}`);
|
|
44
|
+
const opts = {
|
|
45
|
+
delay: (options === null || options === void 0 ? void 0 : options.scheduledAt)
|
|
46
|
+
? Math.max(0, options.scheduledAt.getTime() - Date.now())
|
|
47
|
+
: undefined,
|
|
48
|
+
attempts: config.retries !== undefined ? config.retries + 1 : undefined,
|
|
49
|
+
backoff: {
|
|
50
|
+
type: "fixed",
|
|
51
|
+
delay: config.retryDelay || 30000,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
44
54
|
const job = {
|
|
45
55
|
name: config.job || connection_js_1.BULLMQ_DEFAULTJOB,
|
|
46
|
-
opts
|
|
47
|
-
delay: (options === null || options === void 0 ? void 0 : options.scheduledAt)
|
|
48
|
-
? Math.max(0, options.scheduledAt.getTime() - Date.now())
|
|
49
|
-
: undefined,
|
|
50
|
-
attempts: config.retries,
|
|
51
|
-
backoff: {
|
|
52
|
-
type: "fixed",
|
|
53
|
-
delay: config.retryDelay || 30000,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
+
opts,
|
|
56
57
|
};
|
|
57
58
|
const jobs = messages.map((data) => {
|
|
58
59
|
return Object.assign(Object.assign({}, job), { data });
|
|
@@ -9,9 +9,11 @@ declare class SubscribedMessage {
|
|
|
9
9
|
stopSubscribe(): Promise<void>;
|
|
10
10
|
}
|
|
11
11
|
export declare class MessageFailError extends Error {
|
|
12
|
+
static readonly failedReason = "Handler asked to fail this job";
|
|
12
13
|
constructor();
|
|
13
14
|
}
|
|
14
15
|
export declare class MessageRetryError extends Error {
|
|
16
|
+
static readonly failedReason = "Handler asked to retry this job";
|
|
15
17
|
constructor();
|
|
16
18
|
}
|
|
17
19
|
export declare class BullMqSubscriber implements SubscriberProvider {
|
|
@@ -24,5 +26,6 @@ export declare class BullMqSubscriber implements SubscriberProvider {
|
|
|
24
26
|
startSubscribe(config: BullMqQueueConfiguration, onMessage: (s: string, context: BullMqMessageContext) => Promise<MessageResult> | MessageResult): Promise<StopSubscribe>;
|
|
25
27
|
close(): Promise<void>;
|
|
26
28
|
enrichHandledMesssageLog(config: BullMqQueueConfiguration): Record<string, unknown>;
|
|
29
|
+
willRetryJobOnFailure(job: bullmq.Job<string>): boolean;
|
|
27
30
|
}
|
|
28
31
|
export {};
|
|
@@ -32,16 +32,18 @@ class SubscribedMessage {
|
|
|
32
32
|
}
|
|
33
33
|
class MessageFailError extends Error {
|
|
34
34
|
constructor() {
|
|
35
|
-
super(
|
|
35
|
+
super(MessageFailError.failedReason);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
exports.MessageFailError = MessageFailError;
|
|
39
|
+
MessageFailError.failedReason = "Handler asked to fail this job";
|
|
39
40
|
class MessageRetryError extends Error {
|
|
40
41
|
constructor() {
|
|
41
|
-
super(
|
|
42
|
+
super(MessageRetryError.failedReason);
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
exports.MessageRetryError = MessageRetryError;
|
|
46
|
+
MessageRetryError.failedReason = "Handler asked to retry this job";
|
|
45
47
|
class BullMqSubscriber {
|
|
46
48
|
constructor(connection, logger) {
|
|
47
49
|
this.connection = connection;
|
|
@@ -70,9 +72,10 @@ class BullMqSubscriber {
|
|
|
70
72
|
}, () => __awaiter(this, void 0, void 0, function* () {
|
|
71
73
|
const context = {
|
|
72
74
|
job: job.name,
|
|
73
|
-
|
|
75
|
+
attemptsMade: job.attemptsMade,
|
|
74
76
|
firstSent: new Date(job.timestamp),
|
|
75
|
-
|
|
77
|
+
lastSent: undefined,
|
|
78
|
+
willRetryOnFailure: this.willRetryJobOnFailure(job),
|
|
76
79
|
};
|
|
77
80
|
const result = yield onMessage(job.data, context);
|
|
78
81
|
if (result === interfaces_js_1.MessageResult.Ok) {
|
|
@@ -81,7 +84,8 @@ class BullMqSubscriber {
|
|
|
81
84
|
if (result === interfaces_js_1.MessageResult.Retry) {
|
|
82
85
|
throw new MessageRetryError();
|
|
83
86
|
}
|
|
84
|
-
|
|
87
|
+
// result === MessageResult.Fail
|
|
88
|
+
throw new BullMqPackage.UnrecoverableError(MessageFailError.failedReason);
|
|
85
89
|
}));
|
|
86
90
|
}), {
|
|
87
91
|
connection: this.connection,
|
|
@@ -91,10 +95,30 @@ class BullMqSubscriber {
|
|
|
91
95
|
if (!job) {
|
|
92
96
|
return;
|
|
93
97
|
}
|
|
94
|
-
|
|
98
|
+
if (job.failedReason !== MessageRetryError.failedReason &&
|
|
99
|
+
job.failedReason !== MessageFailError.failedReason) {
|
|
100
|
+
const log = {
|
|
101
|
+
message: "BullMq PubSub job failed",
|
|
102
|
+
error: (0, create_log_error_payload_js_1.createLogErrorPayload)(err),
|
|
103
|
+
extra: {
|
|
104
|
+
job: config.name,
|
|
105
|
+
message: job.data,
|
|
106
|
+
attemptsMade: job.attemptsMade,
|
|
107
|
+
failedReason: job.failedReason,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
this.logger.error(log);
|
|
111
|
+
}
|
|
95
112
|
});
|
|
96
113
|
worker.on("error", (err) => {
|
|
97
|
-
|
|
114
|
+
const log = {
|
|
115
|
+
message: "BullMq PubSub handler exception",
|
|
116
|
+
error: (0, create_log_error_payload_js_1.createLogErrorPayload)(err),
|
|
117
|
+
extra: {
|
|
118
|
+
job: config.name,
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
this.logger.error(log);
|
|
98
122
|
});
|
|
99
123
|
(_b = (_a = this.logger).debug) === null || _b === void 0 ? void 0 : _b.call(_a, `BullMq PubSub subscriber starting for ${worker.name}`);
|
|
100
124
|
worker
|
|
@@ -128,5 +152,9 @@ class BullMqSubscriber {
|
|
|
128
152
|
job: config.job,
|
|
129
153
|
};
|
|
130
154
|
}
|
|
155
|
+
willRetryJobOnFailure(job) {
|
|
156
|
+
var _a;
|
|
157
|
+
return job.attemptsMade + 1 < ((_a = job.opts.attempts) !== null && _a !== void 0 ? _a : 1);
|
|
158
|
+
}
|
|
131
159
|
}
|
|
132
160
|
exports.BullMqSubscriber = BullMqSubscriber;
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface PubSubConfiguration {
|
|
|
52
52
|
*/
|
|
53
53
|
transport: string;
|
|
54
54
|
/**
|
|
55
|
-
* Maximum number of times to retry a message
|
|
55
|
+
* Maximum number of times to retry a message (default: 0, no retries)
|
|
56
56
|
*/
|
|
57
57
|
retries?: number;
|
|
58
58
|
/**
|
|
@@ -129,7 +129,8 @@ export type PubSubProvider = PublisherProvider & SubscriberProvider;
|
|
|
129
129
|
*/
|
|
130
130
|
export type PubOrSubProvider = PubSubProvider | PublisherProvider | SubscriberProvider;
|
|
131
131
|
export interface MessageContext {
|
|
132
|
-
firstSent
|
|
133
|
-
lastSent
|
|
134
|
-
|
|
132
|
+
firstSent: Date | undefined;
|
|
133
|
+
lastSent: Date | undefined;
|
|
134
|
+
attemptsMade: number | undefined;
|
|
135
|
+
willRetryOnFailure: boolean;
|
|
135
136
|
}
|
|
@@ -84,8 +84,10 @@ export interface RabbitQueueExchangeCustomConfiguration {
|
|
|
84
84
|
retryQueueExchangeName?: string;
|
|
85
85
|
}
|
|
86
86
|
export interface RabbitMqMessageContext extends MessageContext {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
queueName: string;
|
|
88
|
+
exchangeName: string;
|
|
89
|
+
routingKey: string;
|
|
90
|
+
retryExchangeName: string;
|
|
89
91
|
}
|
|
90
92
|
/**
|
|
91
93
|
* Returns the queue name based on the configuration
|
|
@@ -25,7 +25,7 @@ export declare class RabbitMqSubscriber implements SubscriberProvider {
|
|
|
25
25
|
startSubscribe(config: RabbitQueueExchangeConfiguration, onMessage: (s: string, context: RabbitMqMessageContext) => Promise<MessageResult> | MessageResult): StopSubscribe;
|
|
26
26
|
close(): Promise<void>;
|
|
27
27
|
enrichHandledMesssageLog(config: RabbitQueueExchangeConfiguration): Record<string, unknown>;
|
|
28
|
-
static
|
|
28
|
+
static getAttemptsMade(msg: ConsumeMessage): number;
|
|
29
29
|
static getSentDates(msg: ConsumeMessage): {
|
|
30
30
|
firstSent: Date | undefined;
|
|
31
31
|
lastSent: Date | undefined;
|
|
@@ -52,7 +52,7 @@ class SubscribedMessage {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
const RETRIES_HEADER = "x-retries";
|
|
55
|
-
const
|
|
55
|
+
const RETRY_SENT_HEADER = "x-retry-sent";
|
|
56
56
|
class RabbitMqSubscriber {
|
|
57
57
|
constructor(connection, logger) {
|
|
58
58
|
this.connection = connection;
|
|
@@ -94,9 +94,10 @@ class RabbitMqSubscriber {
|
|
|
94
94
|
enrichHandledMesssageLog(config) {
|
|
95
95
|
return {
|
|
96
96
|
queueName: (0, config_js_1.getQueueName)(config),
|
|
97
|
+
exchangeName: (0, config_js_1.getExchangeName)(config),
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
|
-
static
|
|
100
|
+
static getAttemptsMade(msg) {
|
|
100
101
|
var _a;
|
|
101
102
|
return typeof ((_a = msg.properties.headers) === null || _a === void 0 ? void 0 : _a[RETRIES_HEADER]) === "number"
|
|
102
103
|
? msg.properties.headers[RETRIES_HEADER]
|
|
@@ -109,8 +110,8 @@ class RabbitMqSubscriber {
|
|
|
109
110
|
const firstSent = typeof msg.properties.timestamp === "number"
|
|
110
111
|
? new Date(msg.properties.timestamp)
|
|
111
112
|
: undefined;
|
|
112
|
-
const lastSent = typeof ((_a = msg.properties.headers) === null || _a === void 0 ? void 0 : _a[
|
|
113
|
-
? new Date(msg.properties.headers[
|
|
113
|
+
const lastSent = typeof ((_a = msg.properties.headers) === null || _a === void 0 ? void 0 : _a[RETRY_SENT_HEADER]) === "number"
|
|
114
|
+
? new Date(msg.properties.headers[RETRY_SENT_HEADER])
|
|
114
115
|
: firstSent;
|
|
115
116
|
return { firstSent, lastSent };
|
|
116
117
|
}
|
|
@@ -129,22 +130,39 @@ class RabbitMqSubscriber {
|
|
|
129
130
|
}, (span) => __awaiter(this, void 0, void 0, function* () {
|
|
130
131
|
try {
|
|
131
132
|
subscribedMessage.busy++;
|
|
132
|
-
yield this.consumeMessage(
|
|
133
|
+
yield this.consumeMessage({
|
|
134
|
+
msg,
|
|
135
|
+
channel,
|
|
136
|
+
subscribedMessage,
|
|
137
|
+
retryExchangeName: setupResult.retryExchangeName,
|
|
138
|
+
retryDelay,
|
|
139
|
+
queueName,
|
|
140
|
+
});
|
|
133
141
|
}
|
|
134
142
|
catch (err) {
|
|
135
|
-
|
|
143
|
+
const logPayload = {
|
|
136
144
|
message: "Unexpected error handling RabbitMq message",
|
|
137
145
|
error: (0, create_log_error_payload_js_1.createLogErrorPayload)(err),
|
|
138
|
-
|
|
146
|
+
extra: {
|
|
147
|
+
queueName,
|
|
148
|
+
message: msg.content.toString("utf8"),
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
this.logger.error(logPayload);
|
|
139
152
|
span === null || span === void 0 ? void 0 : span.setTag("error", err);
|
|
140
153
|
try {
|
|
141
154
|
channel.nack(msg, undefined, true);
|
|
142
155
|
}
|
|
143
156
|
catch (err2) {
|
|
144
|
-
|
|
157
|
+
const logPayload2 = {
|
|
145
158
|
message: "Unexpected error handling RabbitMq message during NACK attempt",
|
|
146
159
|
error: (0, create_log_error_payload_js_1.createLogErrorPayload)(err2),
|
|
147
|
-
|
|
160
|
+
extra: {
|
|
161
|
+
queueName,
|
|
162
|
+
message: msg.content.toString("utf8"),
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
this.logger.error(logPayload2);
|
|
148
166
|
}
|
|
149
167
|
}
|
|
150
168
|
finally {
|
|
@@ -171,53 +189,68 @@ class RabbitMqSubscriber {
|
|
|
171
189
|
});
|
|
172
190
|
});
|
|
173
191
|
}
|
|
174
|
-
consumeMessage(
|
|
175
|
-
return __awaiter(this,
|
|
176
|
-
var
|
|
192
|
+
consumeMessage(_a) {
|
|
193
|
+
return __awaiter(this, arguments, void 0, function* ({ msg, channel, subscribedMessage, retryExchangeName, retryDelay, queueName, }) {
|
|
194
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
177
195
|
const json = msg.content.toString("utf8");
|
|
178
|
-
const
|
|
196
|
+
const attemptsMade = RabbitMqSubscriber.getAttemptsMade(msg);
|
|
179
197
|
const sentDates = RabbitMqSubscriber.getSentDates(msg);
|
|
180
|
-
const
|
|
198
|
+
const willRetryOnFailure = attemptsMade < ((_b = subscribedMessage.config.retries) !== null && _b !== void 0 ? _b : 0);
|
|
199
|
+
const context = Object.assign(Object.assign({ attemptsMade }, sentDates), { queueName, exchangeName: msg.fields.exchange, retryExchangeName, routingKey: msg.fields.routingKey, willRetryOnFailure });
|
|
181
200
|
let messageResult;
|
|
201
|
+
let logPayload;
|
|
182
202
|
try {
|
|
183
203
|
messageResult = yield subscribedMessage.onMessage(json, context);
|
|
204
|
+
logPayload = {
|
|
205
|
+
message: `RabbitMq consumer handled message.`,
|
|
206
|
+
extra: Object.assign({}, context),
|
|
207
|
+
};
|
|
184
208
|
}
|
|
185
209
|
catch (err) {
|
|
186
210
|
messageResult = interfaces_js_1.MessageResult.Retry;
|
|
187
|
-
|
|
188
|
-
message: `RabbitMq consumer unhandled exception
|
|
211
|
+
logPayload = {
|
|
212
|
+
message: `RabbitMq consumer unhandled exception.`,
|
|
189
213
|
error: (0, create_log_error_payload_js_1.createLogErrorPayload)(err),
|
|
190
|
-
|
|
214
|
+
extra: Object.assign({}, context),
|
|
215
|
+
};
|
|
191
216
|
}
|
|
192
217
|
if (messageResult === interfaces_js_1.MessageResult.Ok) {
|
|
218
|
+
(_d = (_c = this.logger).debug) === null || _d === void 0 ? void 0 : _d.call(_c, logPayload);
|
|
193
219
|
channel.ack(msg);
|
|
194
220
|
return;
|
|
195
221
|
}
|
|
196
|
-
if (messageResult === interfaces_js_1.MessageResult.Retry
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
222
|
+
if (messageResult === interfaces_js_1.MessageResult.Retry) {
|
|
223
|
+
if (willRetryOnFailure) {
|
|
224
|
+
logPayload.message += " Retrying message.";
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
messageResult = interfaces_js_1.MessageResult.Fail;
|
|
228
|
+
logPayload.message += " No more retries.";
|
|
229
|
+
}
|
|
200
230
|
}
|
|
201
231
|
if (messageResult === interfaces_js_1.MessageResult.Fail) {
|
|
202
|
-
(
|
|
232
|
+
(_f = (_e = this.logger).debug) === null || _f === void 0 ? void 0 : _f.call(_e, logPayload);
|
|
203
233
|
channel.nack(msg, undefined, false);
|
|
204
234
|
return;
|
|
205
235
|
}
|
|
206
|
-
const ok = yield ((
|
|
236
|
+
const ok = yield ((_g = subscribedMessage.channel) === null || _g === void 0 ? void 0 : _g.publish(retryExchangeName, msg.fields.routingKey, msg.content, {
|
|
207
237
|
contentType: msg.properties.contentType,
|
|
208
238
|
expiration: retryDelay,
|
|
209
|
-
timestamp: (
|
|
239
|
+
timestamp: (_h = sentDates.firstSent) === null || _h === void 0 ? void 0 : _h.valueOf(),
|
|
210
240
|
headers: {
|
|
211
|
-
[RETRIES_HEADER]:
|
|
212
|
-
[
|
|
241
|
+
[RETRIES_HEADER]: attemptsMade + 1,
|
|
242
|
+
[RETRY_SENT_HEADER]: Date.now(),
|
|
213
243
|
},
|
|
214
244
|
}));
|
|
215
245
|
if (ok) {
|
|
216
|
-
(
|
|
246
|
+
(_k = (_j = this.logger).debug) === null || _k === void 0 ? void 0 : _k.call(_j, `RabbitMq retry queue success`);
|
|
247
|
+
(_m = (_l = this.logger).debug) === null || _m === void 0 ? void 0 : _m.call(_l, logPayload);
|
|
217
248
|
channel.ack(msg);
|
|
218
249
|
}
|
|
219
250
|
else {
|
|
220
|
-
(
|
|
251
|
+
(_p = (_o = this.logger).debug) === null || _p === void 0 ? void 0 : _p.call(_o, `RabbitMq retry queue failure - nack-ing message instead`);
|
|
252
|
+
logPayload.message += " Retry publish failed.";
|
|
253
|
+
this.logger.error(logPayload);
|
|
221
254
|
channel.nack(msg, undefined, true);
|
|
222
255
|
}
|
|
223
256
|
});
|
package/dist/subscriber.js
CHANGED
|
@@ -55,18 +55,20 @@ class Subscriber {
|
|
|
55
55
|
if (!provider) {
|
|
56
56
|
throw new errors_js_1.MissingPubSubProviderError(`No provider configured for ${config.transport}`);
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const enrichedConfig = provider.enrichHandledMesssageLog(config);
|
|
59
|
+
const handleMessage = (jsonStr, context) => __awaiter(this, void 0, void 0, function* () {
|
|
59
60
|
const start = (0, message_logger_js_1.startTiming)();
|
|
60
61
|
const jsonObject = JSON.parse(jsonStr);
|
|
61
|
-
const
|
|
62
|
-
if (!
|
|
62
|
+
const decodeResult = schema.safeDecode(jsonObject);
|
|
63
|
+
if (!decodeResult.success) {
|
|
63
64
|
const durationMs = (0, message_logger_js_1.getDuration)(start);
|
|
64
65
|
(0, message_logger_js_1.logMessage)({
|
|
65
66
|
note: "Subscribed message failed schema validation",
|
|
66
67
|
message: jsonObject,
|
|
67
68
|
level: "error",
|
|
68
69
|
logger: this.logger,
|
|
69
|
-
extra: Object.assign({ transport: provider.transport, name: config.name, durationMs
|
|
70
|
+
extra: Object.assign({ transport: provider.transport, name: config.name, durationMs,
|
|
71
|
+
context }, enrichedConfig),
|
|
70
72
|
});
|
|
71
73
|
const handledEventContext = {
|
|
72
74
|
message: jsonStr,
|
|
@@ -80,7 +82,7 @@ class Subscriber {
|
|
|
80
82
|
return interfaces_js_1.MessageResult.Fail;
|
|
81
83
|
}
|
|
82
84
|
try {
|
|
83
|
-
const result = yield onMessage(
|
|
85
|
+
const result = yield onMessage(decodeResult.data, context);
|
|
84
86
|
const durationMs = (0, message_logger_js_1.getDuration)(start);
|
|
85
87
|
const eventContext = {
|
|
86
88
|
message: jsonStr,
|
|
@@ -91,11 +93,12 @@ class Subscriber {
|
|
|
91
93
|
};
|
|
92
94
|
(0, message_logger_js_1.logMessage)({
|
|
93
95
|
note: "Subscriber processed message",
|
|
94
|
-
message:
|
|
96
|
+
message: decodeResult.data,
|
|
95
97
|
level: config.messageLogLevel,
|
|
96
98
|
logger: this.logger,
|
|
97
99
|
extra: Object.assign({ transport: provider.transport, name: config.name, durationMs,
|
|
98
|
-
result
|
|
100
|
+
result,
|
|
101
|
+
context }, enrichedConfig),
|
|
99
102
|
});
|
|
100
103
|
this.events.emit("messageHandled", eventContext);
|
|
101
104
|
return result;
|
|
@@ -104,24 +107,31 @@ class Subscriber {
|
|
|
104
107
|
const durationMs = (0, message_logger_js_1.getDuration)(start);
|
|
105
108
|
(0, message_logger_js_1.logMessage)({
|
|
106
109
|
note: "Subscriber error when processing message",
|
|
107
|
-
message:
|
|
108
|
-
level: "error",
|
|
110
|
+
message: decodeResult.data,
|
|
111
|
+
level: context.willRetryOnFailure ? "warn" : "error",
|
|
109
112
|
logger: this.logger,
|
|
110
|
-
extra: Object.assign(Object.assign({ transport: provider.transport, name: config.name, durationMs
|
|
113
|
+
extra: Object.assign(Object.assign({ transport: provider.transport, name: config.name, durationMs,
|
|
114
|
+
context }, enrichedConfig), { error: (0, create_log_error_payload_js_1.createLogErrorPayload)(err) }),
|
|
111
115
|
});
|
|
116
|
+
// in the messageHandled event, we always log as retry or fail based on willRetryOnFailure
|
|
117
|
+
const result = context.willRetryOnFailure
|
|
118
|
+
? interfaces_js_1.MessageResult.Retry
|
|
119
|
+
: interfaces_js_1.MessageResult.Fail;
|
|
112
120
|
const eventContext = {
|
|
113
121
|
message: jsonStr,
|
|
122
|
+
result,
|
|
114
123
|
context,
|
|
115
124
|
config,
|
|
116
125
|
durationMs,
|
|
117
126
|
err,
|
|
118
127
|
};
|
|
119
128
|
this.events.emit("messageHandled", eventContext);
|
|
120
|
-
|
|
129
|
+
// but, always return Retry on exception to allow for retry logic to work in the providers
|
|
130
|
+
return interfaces_js_1.MessageResult.Retry;
|
|
121
131
|
}
|
|
122
132
|
});
|
|
123
133
|
this.logger.log(`Starting subscriber for ${config.transport}:${config.name}`);
|
|
124
|
-
subscribedMessage = new SubscribedMessage(yield provider.startSubscribe(config,
|
|
134
|
+
subscribedMessage = new SubscribedMessage(yield provider.startSubscribe(config, handleMessage));
|
|
125
135
|
this.subscribedMessages.set(config, subscribedMessage);
|
|
126
136
|
this.logger.log(`Started subscriber for ${config.transport}:${config.name}`);
|
|
127
137
|
return () => __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED