测试Rabbit上下线监听器

dev.data.processing.dataTreating
面包骑士 2024-09-30 11:14:56 +08:00
parent 441e362f09
commit 479b55ec18
4 changed files with 22 additions and 5 deletions

View File

@ -43,6 +43,7 @@ public class CaffeineCacheUtils {
cache.put(key, value);
// 全部存储到 CaffeineCache集合
caches.add(new CaffeineCache(vin, cache));
log.info("存储缓存,vin:{}, key:{}, value:{}", vin, key, value);
});
simpleCacheManager.setCaches(caches);
log.info("车辆编码:{},本地缓存完成...",vin);
@ -52,7 +53,7 @@ public class CaffeineCacheUtils {
* 线 -
*/
public void deleteCarCache(String vin) {
if (hasCarVinCache(vin)) {
if (!hasCarVinCache(vin)) {
log.warn("车辆编码:{},本地缓存不存在该车辆信息...", vin);
return;
}
@ -64,7 +65,7 @@ public class CaffeineCacheUtils {
*
*/
public Object getCarCache(String vin, String key) {
if (hasCarVinKeyCache(vin, key)){
if (!hasCarVinKeyCache(vin, key)){
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",vin);
return null;
}
@ -75,7 +76,7 @@ public class CaffeineCacheUtils {
*
*/
public <T> T getCarCache(String vin, String key, Class<T> type) {
if (hasCarVinKeyCache(vin,key)){
if (!hasCarVinKeyCache(vin,key)){
log.warn("车辆编码:{},本地缓存不存在该车辆信息...",vin);
return null;
}

View File

@ -1,2 +1,2 @@
com.muyu.common.caffeine.CaffeineCacheUtils
com.muyu.common.caffeine.bean.CaffeineManagerBean

View File

@ -1,6 +1,7 @@
package com.muyu.data.processing.controller;
import com.muyu.common.caffeine.CaffeineCacheUtils;
import com.muyu.common.core.utils.uuid.UUID;
import com.muyu.common.iotdb.config.IotDBConfig;
import com.muyu.common.kafka.constants.KafkaConstants;
@ -9,6 +10,7 @@ import jakarta.annotation.Resource;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
@ -30,6 +32,10 @@ public class TestController {
private RabbitTemplate rabbitTemplate;
@Resource
private IotDBConfig iotDBConfig;
@Resource
private CaffeineCacheUtils caffeineCacheUtils;
@Resource
private RedisTemplate<String,String> redisTemplate;
@GetMapping("/testKafka")
public void sendMsg(@RequestParam("msg") String msg) {
@ -87,4 +93,14 @@ public class TestController {
String sql = String.format("insert into root.one.%s(timestamp, temperature) values (%d, %f)", deviceId, time, value);
iotDBConfig.iotSession().executeNonQueryStatement(sql);
}
@GetMapping("/testSetRedis")
public void testSetRedis(@RequestParam("key") String key,@RequestParam("value") String value) {
redisTemplate.opsForValue().set(key,value);
}
@GetMapping("/testGetCache")
public void testGetCache(@RequestParam("vin") String vin,@RequestParam("key") String key) {
System.out.println(caffeineCacheUtils.getCarCache(vin,key));
}
}

View File

@ -35,7 +35,7 @@ public class GoOnlineRabbitConsumer {
try {
// 重复性校验
if (DATA_SET.add(message.getMessageProperties().getMessageId())) {
// caffeineCacheUtils.addCarCache(vin);
caffeineCacheUtils.addCarCache(vin);
log.info("车辆 {} 上线, 消息已确认。。。",vin);
} else {
log.info("车辆 {} 上线, 消息重复消费,已确认。。。",vin);