package com.tzy.listener.mq;

import com.rabbitmq.client.Channel;
import com.tzy.app.dto.mq.TestParam;
import com.tzy.common.constant.MqConstans;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Slf4j
@Component
public class TestMqConsumer {


    @RabbitHandler
    @RabbitListener(queuesToDeclare=@Queue(MqConstans.TEST_QUEUE))
    public void testMqConsumer(TestParam data, Channel channel, Message message) throws IOException {
        log.info("test111收到消息:{}",data.toString());
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

    //@RabbitHandler
    //@RabbitListener(queuesToDeclare=@Queue(MqConstans.TEST_QUEUE+2))
    //public void testMqConsumer2(TestParam data, Channel channel, Message message) throws IOException {
    //    log.info("test2222收到消息:{}",data.toString());
    //    channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    //}


    // @RabbitHandler
    // @RabbitListener(queuesToDeclare=@Queue("TestDirectQueueV2"))
    // public void testMqConsumerV2(String data, Channel channel, Message message) throws IOException {
    //     log.info("TestDirectQueueV2收到消息:{}",data);
    //     channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    // }
    //
    // @RabbitHandler
    // @RabbitListener(queuesToDeclare=@Queue("TestDirectQueueV3"))
    // public void testMqConsumerV3(String data, Channel channel, Message message) throws IOException {
    //     log.info("TestDirectQueueV3收到消息:{}",data);
    //     channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    // }

}
