我正在尝试向RabbitMQ发送一个从MySQL获得的“实体”。
我能够连接到数据库并返回数据。示例:
dbConnection.query("SELECT * FROM customer WHERE Id = ?", customerId, (err, rows, fields) => {
...
res.status(200).json(rows)
...
}之后,我可以在Postman中查看"JSON result",因此,我想将这个"JSON result“作为字符串发送到RabbitMQ。
我可以毫不费力地向RabbitMq发送一个假数据对象:
const fakeData = {
name: "Elon Musk",
company: "SpaceX",
};
channel.sendToQueue("message-queue", Buffer.from(JSON.stringify(fakeData)));那么,我必须如何转换从MySQL返回的“行”对象才能将其发送到队列呢?
提前谢谢你!
发布于 2021-09-08 18:46:11
我的问题的解决方案如下:
rows.forEach(function (row) {
channel.sendToQueue("message-queue", Buffer.from(JSON.stringify(row)));
});https://stackoverflow.com/questions/69103199
复制相似问题