const amqp = require("amqplib");

const QUEUE_HOST = "amqp://appointment:ZyuhJZ2xEYWhElhpJjy7YEpZGZwNYJz2fHIu@appointment.lpaconsulting.fr:5672"
const REQUEST_DATA_QUEUE = 'REQUEST_DATA';

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, {persistent: true});
    }

    sendMessage(msg) {
        this.channel.sendToQueue(REQUEST_DATA_QUEUE, Buffer.from(msg))
    }
}

module.exports = Sender

// let sender = new Sender()
// sender.initConnection().then((r) => {
//     console.log(r)
//     sender.sendMessage("test")
// })
