Currently I am working on an application that consumes a message from the RabbitMq broker, after consumption of the message my application should write the content into a text file for future usage.
Below are my code snippets :
const fs = require ('fs');
const config = require('../config.json');
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost' , function(error1 , connection){
if(error1){
throw error1;
}
connection.createChannel(function(error2 , channel){
if(error2){
throw error2;
}
channel.assertQueue(config.mode.queue,{
durable : false
});
channel.consume(config.mode.queue, function(msg){
let hours = new Date().getHours().toString();
let mins = new Date().getMinutes().toString();
if (mins.length != 2){
mins = "0" + mins
console.log(mins)
}
let timestamp = hours + mins
fs.writeFile(`./DataStorage/${timestamp}.txt` , msg.content.toString() , err => {
if(err){
console.log(err)
return;
}
})
},{
noAck: true
})
})
})
I am facing issues of writing the protobuf message into a txt file, could anyone provide some kind of guidance on how I could work around this issue.