const amqp = require('amqplib');
const amqplib_config = require('../../etc/config.json').amqplib_config
// 连接配置
const config = amqplib_config;
//消费消息
async function consumerDirectMsg(exchange="exchange_system",call_back) {
    // 创建连接
    const connection = await amqp.connect(config);
    // 创建通道
    const channel = await connection.createChannel();
    // const exchange = 'order_system';
    
    await channel.assertExchange(exchange, 'direct', { durable: true });
    const { queue } = await channel.assertQueue('inventory_queue');
    await channel.bindQueue(queue, exchange, 'new.order');
    
    channel.consume(queue, async (msg) => {
        const msg = JSON.parse(msg.content.toString());
        call_back(msg)
        channel.ack(msg);
    });
}