29 lines
813 B
JavaScript
29 lines
813 B
JavaScript
const amqp = require("amqplib");
|
|
|
|
const QUEUE_HOST = "amqp://appointment:ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu@appointment.lpaconsulting.fr:5672"
|
|
const REQUEST_DATA_QUEUE_FR = 'REQUEST_DATA';
|
|
const REQUEST_DATA_QUEUE_DE = 'REQUEST_DATA_DE';
|
|
|
|
class Sender {
|
|
channel;
|
|
connection;
|
|
|
|
async initConnection() {
|
|
this.connection = await amqp.connect(QUEUE_HOST);
|
|
this.channel = await this.connection.createChannel();
|
|
await this.channel.assertQueue(REQUEST_DATA_QUEUE_FR, {persistent: true});
|
|
}
|
|
|
|
sendMessage(msg, queue_name = REQUEST_DATA_QUEUE_FR) {
|
|
this.channel.sendToQueue(queue_name, Buffer.from(msg))
|
|
}
|
|
}
|
|
|
|
module.exports = Sender
|
|
|
|
// let sender = new Sender()
|
|
// sender.initConnection().then((r) => {
|
|
// console.log(r)
|
|
// sender.sendMessage("test")
|
|
// })
|