Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/adapters/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,37 @@ module.exports = (config) => {
queue,
(message) => {
if (message !== null) {
debug(`Got ${key} event from APMQ channel`)
debug(`Got ${key} event from AMQP channel`)
app.emit('sync-in', message.content)
}
},
{ noAck: true }
)
// Publish the received message to the queue
app.on('sync-out', (data) => {
try {

function publishToQueue(data) {
try {
const publishResponse = channel.publish(
key,
queue,
Buffer.from(data)
)
debug(`Publish success: |${publishResponse}| APMQ channel`)
debug(`Publish success: |${publishResponse}| AMQP channel`)
} catch (error) {
debug(`Publish fail: |${error.message}| APMQ channel`)
debug(`Publish fail: |${error.message}| AMQP channel`)
}
}

// Publish the received message to the queue
app.on('sync-out', publishToQueue)

channel.on('close', () => {
debug('Channel closed')
app.off('sync-out', publishToQueue)
})

return channel
} catch (error) {
debug(`Publish fail: |${error.message}| APMQ channel`)
debug(`Publish fail: |${error.message}| AMQP channel`)
}
}
})
Expand Down