Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Add logger inside publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
avdkishore committed Sep 25, 2018
1 parent b40235a commit dfe2bcb
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {
heartbeatInterval = 5,
reconnectTime = 10,
options = {},
defaultQueueFeatures = {}
defaultQueueFeatures = { durable: true }
} = config.rabbitMQ;

// Handle an incomming message.
Expand Down Expand Up @@ -113,7 +113,6 @@ const consume = (params = {}, handler) => {
* @param {object} [data] - data to be published.
*/
const publish = (queueName, data) => {
console.log(queueName, data);
const channelWrapper = connection.createChannel({
json: true,
setup(channel) {
Expand All @@ -127,16 +126,11 @@ const publish = (queueName, data) => {
channelWrapper
.sendToQueue(queueName, data, { persistent: true })
.then(() => {
console.log('Message sent');
// return wait(1000);
logger.log('data', { note: `Message sent to queue ${queueName}` });
return null;
})
.then(() =>
// return sendMessage();
Promise.resolve()
)
.catch(err => {
console.log('Message was rejected:', err.stack);
logger.log('error', { note: 'Message was rejected', error: err, custom: { data }});
channelWrapper.close();
connection.close();
});
Expand All @@ -152,7 +146,7 @@ const purgeQueue = queueName => {
setup(channel) {
// `channel` here is a regular amqplib `ConfirmChannel`.
return Promise.all([
channel.assertQueue(queueName, { durable: true }),
channel.assertQueue(queueName, defaultQueueFeatures),
channel.purgeQueue(queueName)
]);
}
Expand Down

0 comments on commit dfe2bcb

Please sign in to comment.