package com.muyu.processing.consumer;


import com.muyu.processing.utils.CacheUtil;
import lombok.extern.log4j.Log4j2;
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;

import javax.annotation.Resource;

/**
 * 下线监听
 * @Author：杨鹏
 * @Package：com.muyu.processing.consumer
 * @Project：cloud-vehicle
 * @name：OfflineMonitoringConsumer
 * @Date：2024/10/4 14:48
 */
@Log4j2
@Component
public class OfflineMonitoringConsumer {

    /**
     * 下线监听队列名称
     */
    private static final String OFFLINE_MONITORING = "MQ_OFFLINE_MONITORING";
    /**
     * 下线监听交换机名称
     */
    private static final String OFFLINE_EXCHANGE = "OFFLINE_EXCHANGE";

    @Resource
    private CacheUtil cacheUtil;

    /**
     * 接收消息
     * @param vin 车辆vin
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = OFFLINE_MONITORING, declare = "true"),
            exchange = @Exchange(value = OFFLINE_EXCHANGE, type = "fanout")))
    public void online(String vin){
        log.info("清除缓存中的数据,车辆vin: {}", vin);
        // 清除缓存
        cacheUtil.remove(vin);
        log.info("vin码为: {}de本地缓存清除成功",vin);
    }

}
