Skip to content

Commit 5a1222d

Browse files
author
Vikas Agarwal
committed
Error handling for publishing message to error exchange/queue
asserted the topic exchange for the publish channel as well
1 parent ebe0935 commit 5a1222d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

consumer/src/worker.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function initHandlers(handlers) {
3737
*/
3838
export async function consume(channel, exchangeName, queue, publishChannel) {
3939
channel.assertExchange(exchangeName, 'topic', { durable: true });
40+
publishChannel.assertExchange(exchangeName, 'topic', { durable: true });
4041
channel.assertQueue(queue, { durable: true });
4142
const bindings = _.keys(EVENT_HANDLERS);
4243
const bindingPromises = _.map(bindings, rk =>
@@ -78,11 +79,17 @@ export async function consume(channel, exchangeName, queue, publishChannel) {
7879
// we can use cloudamqp console to check the messages and may be manually create SF lead
7980
// nacking here was causing flood of messages to the worker and it keep on consuming high resources
8081
channel.ack(msg);
81-
publishChannel.publish(
82-
exchangeName,
83-
EVENT.ROUTING_KEY.CONNECT_TO_SF_FAILED,
84-
new Buffer(msg.content.toString())
85-
);
82+
try {
83+
publishChannel.publish(
84+
exchangeName,
85+
EVENT.ROUTING_KEY.CONNECT_TO_SF_FAILED,
86+
new Buffer(msg.content.toString())
87+
);
88+
} catch(e) {
89+
// TODO decide if we want nack the original msg here
90+
// for now just ignoring the error in requeue
91+
logger.logFullError(e, `Error in publising Exchange to ${exchangeName}`);
92+
}
8693
}
8794
}
8895
});

consumer/test/worker.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ describe('worker', () => {
6161
},
6262
}, exchangeName, queueName,
6363
{
64-
publish: channelPublishSpy
64+
publish: channelPublishSpy,
65+
assertExchange
6566
});
6667
}
6768

0 commit comments

Comments
 (0)