Compare commits

...

6 Commits

Author SHA1 Message Date
ffr 395b4cc5a5 commit upd 2024-04-09 15:23:44 +08:00
lijiayao f2463c9753 refactor: 修改框架 2024-04-09 15:17:37 +08:00
ffr 2734077121 Merge branch 'server_five' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five_fufanrui 2024-04-09 14:07:53 +08:00
lijiayao 33978cf155 Merge branch 'server_five_dongxiaodong' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five
# Conflicts:
#	couplet-modules/couplet-analyze/couplet-analyze-msg/src/main/java/com/couplet/analyze/msg/model/ModelsKafkaMessage.java
#	couplet-modules/couplet-modules-mq/src/main/java/com/couplet/mq/controller/KafkaTest.java
2024-04-09 10:49:27 +08:00
lijiayao a8fff6ef70 feat: 优化代码 2024-04-09 10:47:42 +08:00
dongxiaodong 54a091e3b6 优化判断语句 2024-04-09 09:57:28 +08:00
17 changed files with 124 additions and 144 deletions

View File

@ -17,11 +17,9 @@ spring:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置

View File

@ -1,2 +1,5 @@
com.couplet.remote.factory.RemoteVehicleFallbackFactory com.couplet.remote.factory.RemoteVehicleFallbackFactory
<<<<<<< HEAD
com.couplet.remote.factory.RemoteTroubleFallbackFactory com.couplet.remote.factory.RemoteTroubleFallbackFactory
=======
>>>>>>> f07dc73 (远程调用 加自动配置扫描)

View File

@ -10,21 +10,12 @@ import org.springframework.stereotype.Component;
*/ */
public interface AnalyzeEventContents { public interface AnalyzeEventContents {
/** //故障
*
*/
static final String BREAKDOWN = "breakdown"; static final String BREAKDOWN = "breakdown";
/** //电子围栏
*
*/
static final String ELECTRONIC_FENCE = "electronic_fence"; static final String ELECTRONIC_FENCE = "electronic_fence";
/** //实时数据
*
*/
static final String REAL_TIME_DATA = "real_time_data"; static final String REAL_TIME_DATA = "real_time_data";
//存储
/**
*
*/
static final String STORED_EVENT = "stored_event"; static final String STORED_EVENT = "stored_event";
} }

View File

@ -296,13 +296,13 @@ public class RedisService {
* *
* @return * @return
*/ */
public Collection<String> keys (final String pattern) { public Collection<String> keys (final String pattern) {
return redisTemplate.keys(pattern); return redisTemplate.keys(pattern);
} }
public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) { public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) {
String key = "vin:"+realTimeDataRequest.getVin(); String key = "vin:" + realTimeDataRequest.getVin();
redisTemplate.opsForValue().set(key, realTimeDataRequest); redisTemplate.opsForSet().add(key,realTimeDataRequest);
} }
public void stopViewingData(String vin) { public void stopViewingData(String vin) {

View File

@ -15,11 +15,9 @@ spring:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置

View File

@ -13,7 +13,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
*/ */
@SpringBootApplication(scanBasePackages = "com.couplet") @SpringBootApplication(scanBasePackages = "com.couplet")
@EnableScheduling @EnableScheduling
@EnableFeignClients(basePackages = "com.couplet.**") @EnableFeignClients(basePackages = "com.couplet")
public class CoupletMsgApplication { public class CoupletMsgApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(CoupletMsgApplication.class); SpringApplication.run(CoupletMsgApplication.class);

View File

@ -36,7 +36,7 @@ import static java.lang.Thread.sleep;
@Component @Component
@Slf4j @Slf4j
public class ModelsKafkaMessage { public class ModelsKafkaMessage {
private static final String TOPIC_NAME = "online"; private static final String TOPIC_NAME = "fufanrui";
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092"; private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
@ -50,9 +50,6 @@ public class ModelsKafkaMessage {
private AnalyzeEventCache analyzeEventCache; private AnalyzeEventCache analyzeEventCache;
//kafka消费者初始化 //kafka消费者初始化
@PostConstruct @PostConstruct
public void initKafkaConsumer() { public void initKafkaConsumer() {

View File

@ -46,10 +46,10 @@ public class ElectronicFenceServiceImpl implements IncidentService {
if (redisService.hasKey(fenceKey)) { if (redisService.hasKey(fenceKey)) {
Set<Fence> cacheSet = redisService.getCacheSet(fenceKey); Set<Fence> cacheSet = redisService.getCacheSet(fenceKey);
log.info("电子围栏事件redis存在......."); log.info("电子围栏事件redis存在.......");
// jingdu; //jingdu;
// longitude; //longitude;
// weidu; //weidu;
// latitude; //latitude;
for (Fence fence : cacheSet) { for (Fence fence : cacheSet) {
String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude(); String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude();
/** /**

View File

@ -42,8 +42,12 @@ public class RealTimeDataServiceImpl implements IncidentService {
log.info("实时数据事件开始....."); log.info("实时数据事件开始.....");
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin()); RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
//判断是否有缓存数据 //判断是否有缓存数据
if (RealTimeJudge.isJudge(coupletMsgData.getVin())) { if (redisService.hasKey("vin:query:" + cacheObject.getVin())){
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin()); redisService.deleteObject("vin:query:" + cacheObject.getVin());
}
// if (RealTimeJudge.isJudge(coupletMsgData.getVin())) {
if (coupletMsgData.getVin().equals(cacheObject.getVin())){
// log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
//判断数据是否一致, //判断数据是否一致,
// if (RealTimeJudge.addRealTime(cacheObject)) { // if (RealTimeJudge.addRealTime(cacheObject)) {
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject); log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);

View File

@ -15,11 +15,9 @@ spring:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置
@ -52,8 +50,3 @@ mybatis-plus:
configuration: configuration:
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
# RabbitMQ配置
mq:
queueName: queue
exchangeName: exchange
routingKey: routingKey

View File

@ -21,8 +21,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json; import springfox.documentation.spring.web.json.Json;
import java.lang.reflect.Array;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -53,10 +56,9 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
public List<CoupletMsgData> monitorinDataList(String vin) { public List<CoupletMsgData> monitorinDataList(String vin) {
String key = "vin:query:" + vin; String key = "vin:query:" + vin;
log.info("key为:"+key); log.info("key为:"+key);
CoupletMsgData coupletMsgData = redisService.getCacheObject(key); Set<CoupletMsgData> cacheSet = redisService.getCacheSet(key);
ArrayList<CoupletMsgData> coupletMsgDataArrayList = new ArrayList<>(); ArrayList<CoupletMsgData> coupletMsgData = new ArrayList<>(cacheSet);
coupletMsgDataArrayList.add(coupletMsgData); return coupletMsgData;
return coupletMsgDataArrayList;
} }
@Override @Override

View File

@ -15,11 +15,9 @@ spring:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置

View File

@ -17,11 +17,9 @@ spring:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置

View File

@ -1,93 +1,93 @@
package com.couplet.mq.controller; //package com.couplet.mq.controller;
//
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerConfig; //import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecords; //import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer; //import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer; //import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig; //import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord; //import org.apache.kafka.clients.producer.ProducerRecord;
//
import javax.annotation.PostConstruct; //import javax.annotation.PostConstruct;
import java.time.Duration; //import java.time.Duration;
import java.util.Collections; //import java.util.Collections;
import java.util.Properties; //import java.util.Properties;
//
/** ///**
* @ProjectName: five-groups-couplet // * @ProjectName: five-groups-couplet
* @Author: LiuYunHu // * @Author: LiuYunHu
* @CreateTime: 2024/4/4 // * @CreateTime: 2024/4/4
* @Description: kafka // * @Description: kafka测试类
*/ // */
//
@Slf4j //@Slf4j
public class KafkaTest { //public class KafkaTest {
private static final String TOPIC_NAME = "online"; // private static final String TOPIC_NAME = "online";
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092"; // private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
//
public static void main(String[] args) { // public static void main(String[] args) {
//生产者示例 // //生产者示例
produceMessage(); //// produceMessage();
//
//消费者示例 // //消费者示例
consumerMessages(); //// consumerMessages();
//
} // }
//
//生产者 // //生产者
@PostConstruct // @PostConstruct
private static void produceMessage() { // private static void produceMessage() {
Properties props = new Properties(); // Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS); // props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer"); // props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer"); // props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer");
//
KafkaProducer<String, String> producer = new KafkaProducer<>(props); // KafkaProducer<String, String> producer = new KafkaProducer<>(props);
//创建生产者 // //创建生产者
try { // try {
//
//发送消息 // //发送消息
for (int i = 0; i < 10000; i++) { // for (int i = 0; i < 10000; i++) {
String message = "佳佳来喽" + (i + 1); // String message = "佳佳来喽" + (i + 1);
producer.send(new ProducerRecord<>(TOPIC_NAME, message)); // producer.send(new ProducerRecord<>(TOPIC_NAME, message));
//
System.out.println("发送消息:" + message); // System.out.println("发送消息:" + message);
} // }
} catch (Exception e) { // } catch (Exception e) {
e.printStackTrace(); // e.printStackTrace();
} finally { // } finally {
producer.close(); // producer.close();
} // }
} // }
//
//消费者 // //消费者
private static void consumerMessages() { //// private static void consumerMessages() {
Properties props = new Properties(); //// Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS); //// props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group"); //// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); //// props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer"); //// props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
////
//创建消费者 //// //创建消费者
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props); //// KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
////
try { //// try {
////
//订阅主题 //// //订阅主题
consumer.subscribe(Collections.singletonList(TOPIC_NAME)); //// consumer.subscribe(Collections.singletonList(TOPIC_NAME));
////
//持续消费消息 //// //持续消费消息
while (true) { //// while (true) {
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100)); //// ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
records.forEach(record -> { //// records.forEach(record -> {
System.out.println("消费者接受到的消息值:" + record.value()); //// System.out.println("消费者接受到的消息值:" + record.value());
}); //// });
} //// }
} catch (Exception e) { //// } catch (Exception e) {
e.printStackTrace(); //// e.printStackTrace();
} finally { //// } finally {
consumer.close(); //// consumer.close();
} //// }
} //// }
//
} //}

View File

@ -15,11 +15,9 @@ spring:
discovery: discovery:
# 服务注册地址 # 服务注册地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
config: config:
# 配置中心地址 # 配置中心地址
server-addr: 121.89.211.230:8848 server-addr: 121.89.211.230:8848
namespace: 968741d4-299d-483c-8d30-ede2aff8cfd4
# 配置文件格式 # 配置文件格式
file-extension: yml file-extension: yml
# 共享配置 # 共享配置

View File

@ -76,7 +76,7 @@ public class MqttMonitor {
//Kafka生产者配置 //Kafka生产者配置
private static final String TOPIC_NAME = "online"; private static final String TOPIC_NAME = "fufanrui";
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092"; private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
//线程池,用于异步处理消息到来时的业务逻辑 //线程池,用于异步处理消息到来时的业务逻辑

View File

@ -36,7 +36,7 @@ mqtt:
# broker: mqtt://115.159.47.13:1883 # broker: mqtt://115.159.47.13:1883
username: username:
password: password:
clientId: xiaoYao clientId: fufanrui44
qos: 0 qos: 0
topic: xiaoYao topic: test898