//package com.fjhx.listener;
//
//import com.alibaba.fastjson.JSONObject;
//import com.fjhx.service.WebSocketServer;
//import com.rabbitmq.client.Channel;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
//import org.springframework.retry.annotation.Backoff;
//import org.springframework.retry.annotation.EnableRetry;
//import org.springframework.retry.annotation.Retryable;
//import org.springframework.stereotype.Component;
//
//import java.nio.charset.StandardCharsets;
//
///**
// * rabbitmq队列监听工具
// */
//
//@Slf4j
//@EnableRetry
//@Component
//public class RfidDataListener implements ChannelAwareMessageListener {
//
//    /**
//     * 监听rfid数据队列
//     */
//    @RabbitHandler
//    @RabbitListener(
//            queues = {
//                    "rfid_data_queue"
//            }
//    )
//    @Retryable(value = {Exception.class}, backoff = @Backoff(delay = 3000, multiplier = 1))
//    @Override
//    public void onMessage(Message message, Channel channel) throws Exception {
//        try {
//            String msg = new String(message.getBody(), StandardCharsets.UTF_8);
//            JSONObject jsonObject = JSONObject.parseObject(msg);
//
//            log.info(msg);
//
//            String userId = jsonObject.getString("userId");
//            WebSocketServer.sendInfo(userId, jsonObject.toJSONString());
//
//            // 手动签收消息,通知mq服务器端删除该消息
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            e.printStackTrace();
//            // 丢弃该消息
//            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, false);
//            throw e;
//        }
//    }
//
//}
