解决数据处理模块无法启动问题,优化

dev.data.processing.dataTreating
面包骑士 2024-09-27 14:57:11 +08:00
parent 8332507e79
commit 16cf9b5603
13 changed files with 130 additions and 32 deletions

View File

@ -14,8 +14,8 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit; /**
/**
* @Author:
* @Name: CaffeineUtils
* @Description:
@ -37,7 +37,7 @@ public class CaffeineCacheUtils {
public void addCarCache(String vin) {
ArrayList<CaffeineCache> caches = new ArrayList<>();
// 从Redis中获取缓存信息
Map<String,Object> cacheMap = redisService.getCacheMap(CaffeineContent.CAR_VIN+vin);
Map<String,Object> cacheMap = redisService.getCacheMap(CaffeineContent.CAR_VIN_KEY +vin);
cacheMap.forEach((key, value) -> {
Cache<Object , Object> cache = Caffeine.newBuilder().build();
cache.put(key, value);

View File

@ -1,17 +1,10 @@
package com.muyu.common.caffeine.bean;
import com.github.benmanes.caffeine.cache.Cache;
import com.muyu.common.redis.service.RedisService;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
/**
* @Author:

View File

@ -10,7 +10,7 @@ package com.muyu.common.caffeine.constents;
public class CaffeineContent {
public static final String CAR_VIN = "car:Vin";
public static final String CAR_VIN_KEY = "car:Vin";
public static final String VIN = "vin";
}

View File

@ -21,6 +21,7 @@
<artifactId>mybatis-plus-join-boot-starter</artifactId>
<version>1.4.11</version>
</dependency>
<!-- SpringCloud Openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@ -0,0 +1,20 @@
package com.muyu.common.kafka.constents;
import org.springframework.beans.factory.annotation.Value;
/**
* @Author:
* @Name: CaffeineContent
* @Description: Kafka
* @CreatedDate: 2024/9/26 12:06
* @FilePath: com.muyu.common.caffeine.constents
*/
public class KafkaContent {
@Value("${spring.kafka.consumer.group-id}")
public static String GROUP;
@Value("${spring.kafka.template.default-topic}")
public static String TOPIC;
}

View File

@ -18,11 +18,21 @@
</properties>
<dependencies>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-kafka</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-caffeine</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
@ -76,22 +86,13 @@
<groupId>com.muyu</groupId>
<artifactId>cloud-common-api-doc</artifactId>
</dependency>
<!-- XllJob定时任务 -->
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-security</artifactId>
<artifactId>cloud-common-xxl</artifactId>
</dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId>
</dependency>
<!-- &lt;!&ndash; XllJob定时任务 &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.muyu</groupId>-->
<!-- <artifactId>cloud-common-xxl</artifactId>-->
<!-- </dependency>-->
</dependencies>
<build>
@ -110,4 +111,5 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -2,9 +2,9 @@ package com.muyu.data.processing;
import com.muyu.common.security.annotation.EnableCustomConfig;
import com.muyu.common.security.annotation.EnableMyFeignClients;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* @Author:
@ -17,11 +17,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableCustomConfig
//@EnableCustomSwagger2
@EnableMyFeignClients
@EnableRabbit
@SpringBootApplication
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class MyDataApplication {
public static void main(String[] args) {
SpringApplication.run(MyDataApplication.class, args);
System.out.println("MyData 模块启动成功!");
}
}

View File

@ -0,0 +1,28 @@
package com.muyu.data.processing.controller;
import com.muyu.data.processing.kafka.KafkaProducerTestService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
/**
* @Author:
* @Name: Test
* @Description:
* @CreatedDate: 2024/9/27 10:54
* @FilePath: com.muyu.data.processing.controller
*/
@Slf4j
@RestController
@RequestMapping("/Test")
public class TestController {
@GetMapping("/testKafka")
public void sendMsg(String msg) {
new KafkaProducerTestService().sendMessage(msg);
}
}

View File

@ -0,0 +1,24 @@
package com.muyu.data.processing.kafka;
import io.swagger.v3.oas.annotations.servers.Server;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
/**
* @Author:
* @Name: KafkaConsumerService
* @Description: kafka
* @CreatedDate: 2024/9/27 9:27
* @FilePath: com.muyu.data.processing.kafka
*/
@Slf4j
@Server
public class KafkaConsumerService {
@KafkaListener(topics = "iov-car-topic", groupId = "iov-car-group")
private void listen(String msg) {
log.info("kafka 消费消息:{}", msg);
}
}

View File

@ -0,0 +1,30 @@
package com.muyu.data.processing.kafka;
import io.swagger.v3.oas.annotations.servers.Server;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.support.SendResult;
import java.util.concurrent.CompletableFuture;
/**
* @Author:
* @Name: KafkaProducerTestService
* @Description: kafka
* @CreatedDate: 2024/9/27 9:27
* @FilePath: com.muyu.data.processing.kafka
*/
@Slf4j
@Server
public class KafkaProducerTestService {
@Resource
private KafkaTemplate<String,String> kafkaTemplate;
public void sendMessage(String msg) {
CompletableFuture<SendResult<String, String>> send = kafkaTemplate.send("iov-car-topic", msg);
log.info("kafka 发送消息:{}",msg);
}
}

View File

@ -3,13 +3,13 @@ package com.muyu.data.processing.rebbit;
import com.muyu.common.caffeine.CaffeineCacheUtils;
import com.rabbitmq.client.Channel;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashSet;
@ -23,8 +23,7 @@ import java.util.HashSet;
@Slf4j
@Component
public class DownlineRabbit {
@Resource
private CaffeineCacheUtils caffeineCacheUtils;
private CaffeineCacheUtils caffeineCacheUtils = new CaffeineCacheUtils();
private static final HashSet<String> DOWNLINE_SET = new HashSet<>();

View File

@ -24,8 +24,7 @@ import java.util.HashSet;
@Component
public class GoOnlineRabbit {
@Resource
private CaffeineCacheUtils caffeineCacheUtils;
private CaffeineCacheUtils caffeineCacheUtils = new CaffeineCacheUtils();
private static final HashSet<String> DATA_SET = new HashSet<>();

View File

@ -1,6 +1,6 @@
# Tomcat
server:
port: 9701
port: 9711
# nacos线上地址
nacos:
@ -55,6 +55,8 @@ spring:
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# rabbit 配置文件
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# kafka 配置文件
- application-kafka-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
logging:
level: