feat:() 新增下线监听和修改上线监听
parent
0a2fc7a9ce
commit
eade0c66ea
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.processing.consumer;
|
||||
|
||||
import com.muyu.processing.utils.CacheUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
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 {
|
||||
|
||||
@Resource
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
/**
|
||||
* 接收消息
|
||||
* @param vin 车辆vin
|
||||
*/
|
||||
@RabbitListener(queuesToDeclare = @Queue("offline_monitoring"))
|
||||
public void receive(String vin){
|
||||
log.info("清除缓存中的数据,车辆vin: {}", vin);
|
||||
// 清除缓存
|
||||
cacheUtil.remove(vin);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.processing.consumer;
|
||||
|
||||
import com.muyu.processing.utils.CacheUtil;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.Message;
|
||||
|
@ -7,8 +8,10 @@ import org.springframework.amqp.rabbit.annotation.Queue;
|
|||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* MQ消费者
|
||||
* 上线监听
|
||||
* @Author:杨鹏
|
||||
* @Package:com.muyu.processing.consumer
|
||||
* @Project:car-cloud-server
|
||||
|
@ -17,15 +20,20 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class MQConsumer {
|
||||
|
||||
public class OnLineMonitoringConsumer {
|
||||
|
||||
@Resource
|
||||
private CacheUtil cacheUtil;
|
||||
|
||||
/**
|
||||
* 上线监听车辆网关中车辆上线时
|
||||
*/
|
||||
@RabbitListener(queuesToDeclare = @Queue("long_time_no_see"))
|
||||
public void receive(String haha, Message message, Channel channel){
|
||||
public void receive(String vin, Message message, Channel channel){
|
||||
|
||||
try {
|
||||
log.info("MQ消费的消息的内容为{}",haha);
|
||||
log.info("添加本地缓存,车辆vin: {}", vin);
|
||||
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
|
||||
|
||||
} catch (Exception e) {
|
Loading…
Reference in New Issue