Skip to content

Commit

Permalink
Error handling for publishing message to error exchange/queue
Browse files Browse the repository at this point in the history
asserted the topic exchange for the publish channel as well
  • Loading branch information
Vikas Agarwal committed Apr 14, 2017
1 parent ebe0935 commit 5a1222d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 12 additions & 5 deletions consumer/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function initHandlers(handlers) {
*/
export async function consume(channel, exchangeName, queue, publishChannel) {
channel.assertExchange(exchangeName, 'topic', { durable: true });
publishChannel.assertExchange(exchangeName, 'topic', { durable: true });
channel.assertQueue(queue, { durable: true });
const bindings = _.keys(EVENT_HANDLERS);
const bindingPromises = _.map(bindings, rk =>
Expand Down Expand Up @@ -78,11 +79,17 @@ export async function consume(channel, exchangeName, queue, publishChannel) {
// we can use cloudamqp console to check the messages and may be manually create SF lead
// nacking here was causing flood of messages to the worker and it keep on consuming high resources
channel.ack(msg);
publishChannel.publish(
exchangeName,
EVENT.ROUTING_KEY.CONNECT_TO_SF_FAILED,
new Buffer(msg.content.toString())
);
try {
publishChannel.publish(
exchangeName,
EVENT.ROUTING_KEY.CONNECT_TO_SF_FAILED,
new Buffer(msg.content.toString())
);
} catch(e) {
// TODO decide if we want nack the original msg here
// for now just ignoring the error in requeue
logger.logFullError(e, `Error in publising Exchange to ${exchangeName}`);
}
}
}
});
Expand Down
3 changes: 2 additions & 1 deletion consumer/test/worker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('worker', () => {
},
}, exchangeName, queueName,
{
publish: channelPublishSpy
publish: channelPublishSpy,
assertExchange
});
}

Expand Down

0 comments on commit 5a1222d

Please sign in to comment.