@@ -35,8 +35,9 @@ export function initHandlers(handlers) {
3535 * @param {String } exchangeName the exchange name
3636 * @param {String } queue the queue name
3737 */
38- export async function consume ( channel , exchangeName , queue ) {
38+ 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 =>
@@ -73,8 +74,22 @@ export async function consume(channel, exchangeName, queue) {
7374 if ( e . shouldAck ) {
7475 channel . ack ( msg ) ;
7576 } else {
76- // acking for debugging issue on production. this would prevent log pile up
77+ // ack the message but copy it to other queue where no consumer is listening
78+ // we can listen to that queue on adhoc basis when we see error case like lead not created in SF
79+ // we can use cloudamqp console to check the messages and may be manually create SF lead
80+ // nacking here was causing flood of messages to the worker and it keep on consuming high resources
7781 channel . ack ( msg ) ;
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+ }
7893 }
7994 }
8095 } ) ;
@@ -91,7 +106,13 @@ async function start() {
91106 debug ( 'created connection successfully with URL: ' + config . rabbitmqURL ) ;
92107 const channel = await connection . createConfirmChannel ( ) ;
93108 debug ( 'Channel confirmed...' ) ;
94- consume ( channel , config . rabbitmq . projectsExchange , config . rabbitmq . queues . project ) ;
109+ const publishChannel = await connection . createConfirmChannel ( ) ;
110+ consume (
111+ channel ,
112+ config . rabbitmq . projectsExchange ,
113+ config . rabbitmq . queues . project ,
114+ publishChannel
115+ ) ;
95116 } catch ( e ) {
96117 debug ( 'Unable to connect to RabbitMQ' ) ;
97118 }
0 commit comments