package com.qiuguo.iot.user.api.listener;

import com.qiuguo.iot.data.constants.YunxiRabbitConst;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author simon
 * @date 2023/9/26
 * @description
 **/
@Component
@Slf4j
public class YunxiListener {
   @RabbitListener(queues = YunxiRabbitConst.QUEUE_YUNXI, containerFactory = "simpleRabbitListenerContainerFactory")
   public void processYunxiQueue(Channel channel, Message message) throws IOException {
      String messageContent = new String(message.getBody(), "UTF-8");
      System.out.println("YunxiListener msg " +  messageContent);
      //TODO 消费者处理程序

      //处理完毕 手动消息确认 配置需开启 acknowledge-mode: manual
      channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
   }
}
