解决数据处理模块无法启动问题,优化
parent
09353cd0e9
commit
aaff10bc40
|
@ -14,8 +14,8 @@ import org.springframework.stereotype.Component;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.TimeUnit; /**
|
/**
|
||||||
* @Author: 胡杨
|
* @Author: 胡杨
|
||||||
* @Name: CaffeineUtils
|
* @Name: CaffeineUtils
|
||||||
* @Description: 缓存工具类
|
* @Description: 缓存工具类
|
||||||
|
@ -37,7 +37,7 @@ public class CaffeineCacheUtils {
|
||||||
public void addCarCache(String vin) {
|
public void addCarCache(String vin) {
|
||||||
ArrayList<CaffeineCache> caches = new ArrayList<>();
|
ArrayList<CaffeineCache> caches = new ArrayList<>();
|
||||||
// 从Redis中获取缓存信息
|
// 从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) -> {
|
cacheMap.forEach((key, value) -> {
|
||||||
Cache<Object , Object> cache = Caffeine.newBuilder().build();
|
Cache<Object , Object> cache = Caffeine.newBuilder().build();
|
||||||
cache.put(key, value);
|
cache.put(key, value);
|
||||||
|
|
|
@ -1,17 +1,10 @@
|
||||||
package com.muyu.common.caffeine.bean;
|
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.cache.support.SimpleCacheManager;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 胡杨
|
* @Author: 胡杨
|
||||||
|
|
|
@ -10,7 +10,7 @@ package com.muyu.common.caffeine.constents;
|
||||||
|
|
||||||
public class CaffeineContent {
|
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";
|
public static final String VIN = "vin";
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||||
<version>1.4.11</version>
|
<version>1.4.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Openfeign -->
|
<!-- SpringCloud Openfeign -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -18,11 +18,21 @@
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-kafka</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-caffeine</artifactId>
|
<artifactId>cloud-common-caffeine</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-common-rabbit</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
@ -76,22 +86,13 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- XllJob定时任务 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-security</artifactId>
|
<artifactId>cloud-common-xxl</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.muyu</groupId>
|
|
||||||
<artifactId>cloud-common-rabbit</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- <!– XllJob定时任务 –>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>com.muyu</groupId>-->
|
|
||||||
<!-- <artifactId>cloud-common-xxl</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -110,4 +111,5 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -2,9 +2,9 @@ package com.muyu.data.processing;
|
||||||
|
|
||||||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: 胡杨
|
* @Author: 胡杨
|
||||||
|
@ -17,11 +17,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
//@EnableCustomSwagger2
|
//@EnableCustomSwagger2
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
@EnableRabbit
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
@SpringBootApplication
|
|
||||||
public class MyDataApplication {
|
public class MyDataApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(MyDataApplication.class, args);
|
SpringApplication.run(MyDataApplication.class, args);
|
||||||
System.out.println("MyData 模块启动成功!");
|
System.out.println("MyData 模块启动成功!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,13 +3,13 @@ package com.muyu.data.processing.rebbit;
|
||||||
|
|
||||||
import com.muyu.common.caffeine.CaffeineCacheUtils;
|
import com.muyu.common.caffeine.CaffeineCacheUtils;
|
||||||
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Channel;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.amqp.core.Message;
|
import org.springframework.amqp.core.Message;
|
||||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ import java.util.HashSet;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class DownlineRabbit {
|
public class DownlineRabbit {
|
||||||
@Resource
|
private CaffeineCacheUtils caffeineCacheUtils = new CaffeineCacheUtils();
|
||||||
private CaffeineCacheUtils caffeineCacheUtils;
|
|
||||||
|
|
||||||
private static final HashSet<String> DOWNLINE_SET = new HashSet<>();
|
private static final HashSet<String> DOWNLINE_SET = new HashSet<>();
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,7 @@ import java.util.HashSet;
|
||||||
@Component
|
@Component
|
||||||
public class GoOnlineRabbit {
|
public class GoOnlineRabbit {
|
||||||
|
|
||||||
@Resource
|
private CaffeineCacheUtils caffeineCacheUtils = new CaffeineCacheUtils();
|
||||||
private CaffeineCacheUtils caffeineCacheUtils;
|
|
||||||
|
|
||||||
private static final HashSet<String> DATA_SET = new HashSet<>();
|
private static final HashSet<String> DATA_SET = new HashSet<>();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Tomcat
|
# Tomcat
|
||||||
server:
|
server:
|
||||||
port: 9701
|
port: 9711
|
||||||
|
|
||||||
# nacos线上地址
|
# nacos线上地址
|
||||||
nacos:
|
nacos:
|
||||||
|
@ -55,6 +55,8 @@ spring:
|
||||||
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||||
# rabbit 配置文件
|
# rabbit 配置文件
|
||||||
- application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
- 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:
|
logging:
|
||||||
level:
|
level:
|
||||||
|
|
Loading…
Reference in New Issue