Compare commits
No commits in common. "e52228b3818f2c367e9807d86fbdef3887a8f437" and "db1368379ec2d5a9a0fd1f4e1eedde64f43d4da4" have entirely different histories.
e52228b381
...
db1368379e
|
@ -17,9 +17,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -17,14 +17,14 @@ public interface AnalyzeEventContents {
|
|||
/**
|
||||
* 电子围栏
|
||||
*/
|
||||
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,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.couplet.analyze.msg.model;
|
||||
|
||||
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||
import com.couplet.analyze.common.event.AnalyzeEventCache;
|
||||
import com.couplet.analyze.common.event.AnalyzeEventCache;
|
||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
|
@ -9,18 +11,14 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.*;
|
||||
|
||||
import static com.couplet.analyze.msg.utils.MsgUtils.hexToString;
|
||||
import static com.couplet.analyze.msg.utils.MsgUtils.sendMsg;
|
||||
|
@ -39,38 +37,8 @@ public class ModelsKafkaMessage {
|
|||
private static final String TOPIC_NAME = "online";
|
||||
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
|
||||
|
||||
|
||||
//线程池,用于异步处理消息到来时的业务逻辑
|
||||
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
//kafka消费者实例化为类成员变量
|
||||
KafkaConsumer<String, String> consumer;
|
||||
|
||||
@Autowired
|
||||
private AnalyzeEventCache analyzeEventCache;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//kafka消费者初始化
|
||||
@PostConstruct
|
||||
public void initKafkaConsumer() {
|
||||
Properties props = new Properties();
|
||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
||||
// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
|
||||
props.put(ConsumerConfig.GROUP_ID_CONFIG, "ddd");
|
||||
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");
|
||||
|
||||
//消费者
|
||||
consumer = new KafkaConsumer<>(props);
|
||||
//订阅主题
|
||||
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 消费者配置
|
||||
*
|
||||
|
@ -78,14 +46,17 @@ public class ModelsKafkaMessage {
|
|||
*/
|
||||
@Scheduled(fixedDelay = 50)
|
||||
public void consumerMessages() {
|
||||
executorService.execute(this::consumer);
|
||||
Properties props = new Properties();
|
||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
|
||||
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.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void consumer() {
|
||||
//创建消费者
|
||||
KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
|
||||
try {
|
||||
|
||||
//订阅主题
|
||||
consumer.subscribe(Collections.singletonList(TOPIC_NAME));
|
||||
//持续消费消息
|
||||
while (true) {
|
||||
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
|
||||
|
@ -100,17 +71,24 @@ public class ModelsKafkaMessage {
|
|||
IncidentService incidentService = SpringUtils.getBean(string);
|
||||
incidentService.incident(msgData);
|
||||
}
|
||||
// 发送消息
|
||||
// 发送消息
|
||||
// rabbitTemplate.convertAndSend("couplet-code-queue",msgData,message -> {
|
||||
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
// return message;
|
||||
// });
|
||||
|
||||
try {
|
||||
sleep(100);
|
||||
} catch (Exception e) {
|
||||
throw new VehicleException("睡眠失败" + e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
consumer.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.couplet.analyze.msg.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||
import com.couplet.analyze.msg.contents.StateConstant;
|
||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
|
@ -27,7 +26,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* @Date: 2024/4/2
|
||||
* @Description: 故障事件
|
||||
*/
|
||||
@Service(AnalyzeEventContents.BREAKDOWN)
|
||||
@Service("breakdown")
|
||||
public class BreakdownServiceImpl extends KeyExpirationEventMessageListener implements IncidentService {
|
||||
|
||||
/**
|
||||
|
@ -94,7 +93,7 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl
|
|||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return AnalyzeEventContents.BREAKDOWN;
|
||||
return "breakdown";
|
||||
}
|
||||
|
||||
public void scheduledRedis() {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.couplet.analyze.msg.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
import com.couplet.common.core.text.Convert;
|
||||
|
@ -23,7 +22,7 @@ import java.util.Set;
|
|||
* @Date: 2024/4/2
|
||||
* @Description: 电子围栏事件服务实现类
|
||||
*/
|
||||
@Service(AnalyzeEventContents.ELECTRONIC_FENCE)
|
||||
@Service("electronic_fence")
|
||||
@Log4j2
|
||||
public class ElectronicFenceServiceImpl implements IncidentService {
|
||||
|
||||
|
@ -87,7 +86,7 @@ public class ElectronicFenceServiceImpl implements IncidentService {
|
|||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return AnalyzeEventContents.ELECTRONIC_FENCE;
|
||||
return "electronic-fence";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.couplet.analyze.msg.service.impl;
|
||||
|
||||
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
|
@ -19,7 +18,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* @Date: 2024/4/2
|
||||
* @Description: 实时数据事件
|
||||
*/
|
||||
@Service(AnalyzeEventContents.REAL_TIME_DATA)
|
||||
@Service("real_time_data")
|
||||
@Log4j2
|
||||
public class RealTimeDataServiceImpl implements IncidentService {
|
||||
|
||||
|
@ -38,8 +37,7 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
|||
* @param coupletMsgData
|
||||
*/
|
||||
@Override
|
||||
public synchronized void incident(CoupletMsgData coupletMsgData) {
|
||||
|
||||
public void incident(CoupletMsgData coupletMsgData) {
|
||||
|
||||
log.info("实时数据事件开始.....");
|
||||
|
||||
|
@ -71,6 +69,6 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
|||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return AnalyzeEventContents.REAL_TIME_DATA;
|
||||
return "real-time-data";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.couplet.analyze.msg.service.impl;
|
||||
|
||||
import com.couplet.analyze.common.contents.AnalyzeEventContents;
|
||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||
import com.couplet.analyze.msg.service.IncidentService;
|
||||
|
@ -13,7 +12,7 @@ import org.springframework.stereotype.Service;
|
|||
* @Date: 2024/4/2
|
||||
* @Description: 事件存储服务
|
||||
*/
|
||||
@Service(AnalyzeEventContents.STORED_EVENT)
|
||||
@Service("stored_event")
|
||||
@Log4j2
|
||||
public class StoredEventServiceImpl implements IncidentService {
|
||||
@Autowired
|
||||
|
@ -37,6 +36,6 @@ public class StoredEventServiceImpl implements IncidentService {
|
|||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return AnalyzeEventContents.STORED_EVENT;
|
||||
return "stored-event";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -93,13 +93,4 @@ public class SysTroubleController extends BaseController {
|
|||
troubleService.newFaultData(code);
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询故障的状态并处理
|
||||
*/
|
||||
@PostMapping("/getUpdState")
|
||||
public Result<?> getUpdState(@RequestBody CoupletTroubleCode code) {
|
||||
int updateState = troubleService.updateState(code);
|
||||
return Result.success(updateState);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,4 @@ public interface SysTroubleMapper extends BaseMapper<CoupletTroubleCode> {
|
|||
void newFaultData(CoupletTroubleCode code);
|
||||
|
||||
void cleanTroubleCode();
|
||||
|
||||
int updateState(CoupletTroubleCode code);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,4 @@ public interface SysTroubleService extends IService<CoupletTroubleCode> {
|
|||
void newFaultData(CoupletTroubleCode code);
|
||||
|
||||
void cleanTroubleCode();
|
||||
|
||||
int updateState(CoupletTroubleCode code);
|
||||
}
|
||||
|
|
|
@ -58,14 +58,4 @@ public class SysTroubleServiceImpl extends ServiceImpl<SysTroubleMapper, Couplet
|
|||
sysTroubleMapper.cleanTroubleCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取故障状态
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int updateState(CoupletTroubleCode code) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -26,9 +26,6 @@
|
|||
<update id="cleanTroubleCode">
|
||||
truncate table couplet_trouble_code
|
||||
</update>
|
||||
<update id="updateState">
|
||||
update couplet_trouble_code set processing_state = 1 where thourble_id = #{troubleId}
|
||||
</update>
|
||||
|
||||
<select id="selectTroubleList" parameterType="com.couplet.business.server.mapper.SysTroubleMapper" resultMap="SysTroubleResult">
|
||||
<include refid="selectTroubleVo"/>
|
||||
|
|
|
@ -15,11 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -17,11 +17,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,11 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,11 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,9 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
@ -36,7 +38,7 @@ mqtt:
|
|||
# broker: mqtt://115.159.47.13:1883
|
||||
username:
|
||||
password:
|
||||
clientId: xiaoYao
|
||||
clientId: liuyunhu
|
||||
qos: 0
|
||||
topic: xiaoYao
|
||||
topic: liuyunhu
|
||||
|
||||
|
|
|
@ -15,11 +15,9 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
|
@ -15,11 +15,11 @@ spring:
|
|||
discovery:
|
||||
# 服务注册地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
config:
|
||||
# 配置中心地址
|
||||
server-addr: 121.89.211.230:8848
|
||||
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
|
||||
namespace: 172469
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
|
Loading…
Reference in New Issue