File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -30,28 +30,37 @@ module.exports = (config) => {
3030 queue ,
3131 ( message ) => {
3232 if ( message !== null ) {
33- debug ( `Got ${ key } event from APMQ channel` )
33+ debug ( `Got ${ key } event from AMQP channel` )
3434 app . emit ( 'sync-in' , message . content )
3535 }
3636 } ,
3737 { noAck : true }
3838 )
39- // Publish the received message to the queue
40- app . on ( 'sync-out' , ( data ) => {
41- try {
39+
40+ function publishToQueue ( data ) {
41+ try {
4242 const publishResponse = channel . publish (
4343 key ,
4444 queue ,
4545 Buffer . from ( data )
4646 )
47- debug ( `Publish success: |${ publishResponse } | APMQ channel` )
47+ debug ( `Publish success: |${ publishResponse } | AMQP channel` )
4848 } catch ( error ) {
49- debug ( `Publish fail: |${ error . message } | APMQ channel` )
49+ debug ( `Publish fail: |${ error . message } | AMQP channel` )
5050 }
51+ }
52+
53+ // Publish the received message to the queue
54+ app . on ( 'sync-out' , publishToQueue )
55+
56+ channel . on ( 'close' , ( ) => {
57+ debug ( 'Channel closed' )
58+ app . off ( 'sync-out' , publishToQueue )
5159 } )
60+
5261 return channel
5362 } catch ( error ) {
54- debug ( `Publish fail: |${ error . message } | APMQ channel` )
63+ debug ( `Publish fail: |${ error . message } | AMQP channel` )
5564 }
5665 }
5766 } )
You can’t perform that action at this time.
0 commit comments