Merge branch 'server_five' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five_fufanrui
commit
2734077121
|
@ -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
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -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";
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -50,9 +50,6 @@ public class ModelsKafkaMessage {
|
||||||
private AnalyzeEventCache analyzeEventCache;
|
private AnalyzeEventCache analyzeEventCache;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//kafka消费者初始化
|
//kafka消费者初始化
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initKafkaConsumer() {
|
public void initKafkaConsumer() {
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -16,11 +16,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
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -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
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -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
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -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();
|
||||||
}
|
//// }
|
||||||
}
|
//// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
|
|
|
@ -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
|
||||||
# 共享配置
|
# 共享配置
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class MqttMonitor {
|
||||||
|
|
||||||
|
|
||||||
//Kafka生产者配置
|
//Kafka生产者配置
|
||||||
private static final String TOPIC_NAME = "online";
|
private static final String TOPIC_NAME = "xiaoYao";
|
||||||
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
|
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
|
||||||
|
|
||||||
//线程池,用于异步处理消息到来时的业务逻辑
|
//线程池,用于异步处理消息到来时的业务逻辑
|
||||||
|
|
Loading…
Reference in New Issue