package com.ruoyi.cai.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AmqpConsumer {

    public final static String CALCULATE_SALES_QUEUE = "calculateSalesQueue";
    public final static String CALCULATE_SALES_EXCHANGE = "calculateSalesExchange";
    public final static String CALCULATE_SALES_KEY = "calculateSalesKey";


    /**
     * queuesToDeclare：支持多个队列，将队列绑定到默认交换机上，routeKey为队列名称。
     * @param msg 接收到的消息
     */
    /**@RabbitListener(queuesToDeclare = @Queue(value = "testQueue"),containerFactory = "customContainerFactory")
    public void listener(String msg) {
        System.out.println(msg);
    }*/

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = CALCULATE_SALES_QUEUE, durable = "false", autoDelete = "false"),
            exchange = @Exchange(value = CALCULATE_SALES_EXCHANGE),
            key = CALCULATE_SALES_KEY)
            ,containerFactory = "customContainerFactory")
    public void calculateSalesQueue(String message) {
        log.info("calculateSalesQueue: " + message);
    }

    @RabbitListener(queues = CheckTimeOutMqConfig.QUEUE_NAME
            ,containerFactory = "customContainerFactory")
    public void checkTimeOutMq(String message) {
        log.info("checkTimeOutMq: " + message);
    }


}
