fast()获取信息
parent
1512c54b1a
commit
fe2ae95a94
|
@ -0,0 +1,211 @@
|
|||
package com.business.common.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* 车辆信息
|
||||
* @ClassName VehicleInfo
|
||||
* @Author GuanTieLin
|
||||
* @Date 2024/5/30 18:40
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleInfo {
|
||||
/**
|
||||
* vin
|
||||
*/
|
||||
private String vin;
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
private String time;
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private String longitude;
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private String latitude;
|
||||
/**
|
||||
* 车速
|
||||
*/
|
||||
private String speed;
|
||||
/**
|
||||
* 总里程
|
||||
*/
|
||||
private String totalMileage;
|
||||
/**
|
||||
* 总电压
|
||||
*/
|
||||
private String totalVoltage;
|
||||
/**
|
||||
* 总电流
|
||||
*/
|
||||
private String totalCurrent;
|
||||
/**
|
||||
* 绝缘电阻
|
||||
*/
|
||||
private String insulationResistance;
|
||||
/**
|
||||
* 档位
|
||||
*/
|
||||
private String gears;
|
||||
/**
|
||||
* 加速踏板行程值
|
||||
*/
|
||||
private String acceleratorPedal;
|
||||
/**
|
||||
* 制动踏板行程值
|
||||
*/
|
||||
private String brakePedal;
|
||||
/**
|
||||
* 燃料消耗率
|
||||
*/
|
||||
private String fuelConsumptionRate;
|
||||
/**
|
||||
* 电机控制器温度
|
||||
*/
|
||||
private String MotorControllerTemperature;
|
||||
/**
|
||||
* 电机转速
|
||||
*/
|
||||
private String motorSpeed;
|
||||
/**
|
||||
* 电机转矩
|
||||
*/
|
||||
private String motorTorque;
|
||||
/**
|
||||
* 电机温度
|
||||
*/
|
||||
private String motorTemperature;
|
||||
/**
|
||||
* 电机电压
|
||||
*/
|
||||
private String motorVoltage;
|
||||
/**
|
||||
* 电机电流
|
||||
*/
|
||||
private String motorCurrent;
|
||||
/**
|
||||
* 动力电池剩余电量SOC
|
||||
*/
|
||||
private String remainingPower;
|
||||
/**
|
||||
* 当前状态允许的最大反馈功率
|
||||
*/
|
||||
private String maximumFeedbackPower;
|
||||
/**
|
||||
* 当前状态允许最大放电功率
|
||||
*/
|
||||
private String maximumDischargePower;
|
||||
/**
|
||||
* BMS自检计数器
|
||||
*/
|
||||
private String selfTestCounter;
|
||||
/**
|
||||
* 动力电池充放电电流
|
||||
*/
|
||||
private String batteryChargeOrDischargeCurrent;
|
||||
/**
|
||||
* 动力电池负载端总电压V3
|
||||
*/
|
||||
private String totalVoltageV3;
|
||||
/**
|
||||
* 单次最大电压
|
||||
*/
|
||||
private String maximumVoltage;
|
||||
/**
|
||||
* 单体电池最低电压
|
||||
*/
|
||||
private String minimumBatteryVoltage;
|
||||
/**
|
||||
* 单体电池最高温度
|
||||
*/
|
||||
private String maximumBatteryTemperature;
|
||||
/**
|
||||
* 单体电池最低温度
|
||||
*/
|
||||
private String minimumBatteryTemperature;
|
||||
/**
|
||||
* 动力电池可用容量
|
||||
*/
|
||||
private String usableBatteryCapacity;
|
||||
/**
|
||||
* 车辆状态
|
||||
*/
|
||||
private String vehicleStatus;
|
||||
/**
|
||||
* 充电状态
|
||||
*/
|
||||
private String chargeStatus;
|
||||
/**
|
||||
* 运行状态
|
||||
*/
|
||||
private String operationalStatus;
|
||||
/**
|
||||
* SOC
|
||||
*/
|
||||
private String soc;
|
||||
/**
|
||||
* 可充电储能装置工作状态
|
||||
*/
|
||||
private String energyStorageDeviceWorkingStatus;
|
||||
/**
|
||||
* 驱动电机状态
|
||||
*/
|
||||
private String driveMotorStatus;
|
||||
/**
|
||||
* 定位是否有效
|
||||
*/
|
||||
private String positioningIsOrNotEffective;
|
||||
/**
|
||||
* EAS
|
||||
*/
|
||||
private String eas;
|
||||
/**
|
||||
* PTC
|
||||
*/
|
||||
private String ptc;
|
||||
/**
|
||||
* EPS
|
||||
*/
|
||||
private String eps;
|
||||
/**
|
||||
* ABS
|
||||
*/
|
||||
private String abs;
|
||||
/**
|
||||
* MCU
|
||||
*/
|
||||
private String mcu;
|
||||
/**
|
||||
* 动力电池加热状态
|
||||
*/
|
||||
private String batteryHeatingStatus;
|
||||
/**
|
||||
* 动力电池当前状态
|
||||
*/
|
||||
private String batteryCurrentStatus;
|
||||
/**
|
||||
* 动力电池保温状态
|
||||
*/
|
||||
private String batteryInsulationStatus;
|
||||
/**
|
||||
* DCDC
|
||||
*/
|
||||
private String dcdc;
|
||||
/**
|
||||
* CHG
|
||||
*/
|
||||
private String chg;
|
||||
/**
|
||||
* 校验位
|
||||
*/
|
||||
private String checkDigit;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-business-kafka</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-business-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package muyu.business.kafka.common;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
|
||||
@Component
|
||||
public class KafkaMonitor {
|
||||
|
||||
@KafkaListener(topics = "${kafka.topic}")
|
||||
public void receive(String message){
|
||||
System.out.println("监听到:" + message);
|
||||
}
|
||||
}
|
|
@ -95,6 +95,23 @@
|
|||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-common-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- rabbitmq-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--定时器-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
//package com.muyu.goods.client;
|
||||
//
|
||||
//import org.springframework.kafka.annotation.KafkaListener;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//@Component
|
||||
//public class KafkaConsumer {
|
||||
//
|
||||
// @KafkaListener(topics = "my-topic")
|
||||
// public void listenToMessage(String message) {
|
||||
// System.out.println("监听到kafka: " + message);
|
||||
// // 在这里处理消息逻辑
|
||||
// }
|
||||
//
|
||||
// // 如果需要监听多个主题,可以添加更多的@KafkaListener注解方法
|
||||
// @KafkaListener(topics = "#{'${kafka.topics}'.split(',')}")
|
||||
// public void listenToMultipleTopics(String message) {
|
||||
// // ...
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,24 @@
|
|||
package com.muyu.goods.client;
|
||||
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MqConsumer {
|
||||
|
||||
|
||||
// @RabbitListener(queuesToDeclare = {@Queue("vehicle.event")})
|
||||
//监听交换机 Queue(队列名) @Exchange(value = "交换机名称", type = ExchangeTypes.FANOUT)
|
||||
@RabbitListener(bindings = {@QueueBinding(value = @Queue("vehicle.event"),
|
||||
exchange = @Exchange(value = "vehicle.event", type = ExchangeTypes.FANOUT))})
|
||||
public void handleMessage(String message) {
|
||||
System.out.println("Received message: " + message);
|
||||
// 在这里处理接收到的消息
|
||||
}
|
||||
}
|
|
@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import com.business.common.domain.Car;
|
||||
import com.muyu.goods.service.ICarService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
@ -34,6 +35,8 @@ public class CarController extends BaseController
|
|||
{
|
||||
@Autowired
|
||||
private ICarService carService;
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
/**
|
||||
* 查询车辆信息列表
|
||||
|
@ -47,6 +50,15 @@ public class CarController extends BaseController
|
|||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/lists")
|
||||
public Result<List<Car>> lists() {
|
||||
return success(carService.lists());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出车辆信息列表
|
||||
*/
|
||||
|
@ -107,4 +119,24 @@ public class CarController extends BaseController
|
|||
{
|
||||
return toAjax(carService.deleteCarByCarIds(carIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动实时数据事件
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("activate")
|
||||
public Result activate() {
|
||||
redisTemplate.opsForList();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束实时数据事件
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("finish")
|
||||
public Result finish() {
|
||||
String s = redisTemplate.opsForValue().get("01");
|
||||
return Result.success(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.goods.incident.mq;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Producer {
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
public void electronic(Integer id) {
|
||||
rabbitTemplate.convertAndSend("vehicle.event","",id);
|
||||
}
|
||||
}
|
|
@ -20,6 +20,11 @@ public interface CarMapper
|
|||
*/
|
||||
public Car selectCarByCarId(Long carId);
|
||||
|
||||
/**
|
||||
* 车辆列表
|
||||
* @return
|
||||
*/
|
||||
List<Car> lists();
|
||||
/**
|
||||
* 查询车辆信息列表
|
||||
*
|
||||
|
@ -63,4 +68,5 @@ public interface CarMapper
|
|||
Car query(Long carId);
|
||||
|
||||
Car carByCar();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.muyu.goods.mapper;
|
||||
|
||||
import com.business.common.domain.Car;
|
||||
import com.business.common.domain.Fence;
|
||||
import com.business.common.domain.FenceGroups;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
@ -20,4 +21,5 @@ public interface MapMapper {
|
|||
Fence queryFence(@Param("fenceId") Long fenceId);
|
||||
|
||||
int updateFence(@Param("fenceId") Long fenceId, @Param("status") String status);
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,11 @@ public interface ICarService
|
|||
*/
|
||||
public Car selectCarByCarId(Long carId);
|
||||
|
||||
/**
|
||||
* 车辆列表
|
||||
* @return
|
||||
*/
|
||||
List<Car> lists();
|
||||
/**
|
||||
* 查询车辆信息列表
|
||||
*
|
||||
|
@ -61,4 +66,5 @@ public interface ICarService
|
|||
public int deleteCarByCarId(Long carId);
|
||||
|
||||
Car query(Long carId);
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,11 @@ public class CarServiceImpl implements ICarService
|
|||
return carMapper.selectCarByCarId(carId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Car> lists() {
|
||||
return carMapper.lists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询车辆信息列表
|
||||
*
|
||||
|
|
|
@ -22,6 +22,10 @@ public class MapService implements IMapService {
|
|||
@Autowired
|
||||
private MapMapper mapMapper;
|
||||
|
||||
/**
|
||||
* 围栏组
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<FenceGroups> selectFenceGroups() {
|
||||
List<FenceGroups> fenceGroupsList = mapMapper.selectFenceGroups();
|
||||
|
@ -35,18 +39,32 @@ public class MapService implements IMapService {
|
|||
return fenceGroupsList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看电子围栏
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Fence> selectFence() {
|
||||
List<Fence> fenceList = mapMapper.selectFence();
|
||||
return fenceList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 围栏组详情
|
||||
* @param carId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public FenceGroups selectFenceGroupsById(Long carId) {
|
||||
List<FenceGroups> groups = selectFenceGroups().stream().filter(car -> car.getCarId() == carId).collect(Collectors.toList());
|
||||
return groups.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 传入电子围栏
|
||||
* @param pences
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String getSel(Pences pences) {
|
||||
System.out.println(pences);
|
||||
|
@ -68,6 +86,11 @@ public class MapService implements IMapService {
|
|||
return "传入电子围栏失败";
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除电子围栏
|
||||
* @param fenceId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String deleteFence(Long fenceId) {
|
||||
int i = mapMapper.deleteFence(fenceId);
|
||||
|
@ -77,11 +100,21 @@ public class MapService implements IMapService {
|
|||
return "无效";
|
||||
}
|
||||
|
||||
/**
|
||||
* 电子围栏详情
|
||||
* @param fenceId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Fence queryFence(Long fenceId) {
|
||||
return mapMapper.queryFence(fenceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改电子围栏状态
|
||||
* @param fenceId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String updateFence(Long fenceId) {
|
||||
Fence fence = queryFence(fenceId);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.muyu.goods.timer;
|
||||
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.kafka.common.protocol.types.Field;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@EnableScheduling
|
||||
@Log4j2
|
||||
public class Timer {
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
@Scheduled(fixedDelay = 1000)
|
||||
public void generateRandomNumber() {
|
||||
// Random random = new Random();
|
||||
// int i = random.nextInt(100);
|
||||
// System.out.println(i);
|
||||
String rightPopAndLeftPush = null;
|
||||
try {
|
||||
rightPopAndLeftPush = redisTemplate.opsForList().leftPop("event_handler:realtime_data:JAV0VJUJYOTOK9KSY"
|
||||
, 3, TimeUnit.SECONDS);
|
||||
if (rightPopAndLeftPush != null) {
|
||||
log.info("处理消息: {}", rightPopAndLeftPush);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 处理超时异常,进行持久化操作,消息没处理可进行后续处理
|
||||
// if (rightPopAndLeftPush != null) {
|
||||
// redisTemplate.opsForList().leftPush("backupList", rightPopAndLeftPush);
|
||||
// }
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -23,6 +23,14 @@ spring:
|
|||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
kafka:
|
||||
bootstrap-servers: 129.211.23.219:9200 # kafka集群地址
|
||||
consumer:
|
||||
group-id: my-group #消费者组id
|
||||
auto-offset-reset: earliest #默认偏移量位置
|
||||
key-deserializer: org.apache.kafka.common.serialization.StringDeserializer #键序列化器
|
||||
value-deserializer: org.apache.kafka.common.serialization.StringDeserializer #值序列化器
|
||||
enable-auto-commit: false # 是否自动提交offset
|
||||
logging:
|
||||
level:
|
||||
com.muyu.rule.mapper: DEBUG
|
||||
|
|
|
@ -46,6 +46,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectCarVo"></include>
|
||||
ORDER BY car_id DESC LIMIT 1;
|
||||
</select>
|
||||
<select id="lists" resultType="com.business.common.domain.Car">
|
||||
<include refid="selectCarVo"></include>
|
||||
</select>
|
||||
|
||||
<insert id="insertCar" parameterType="com.business.common.domain.Car" useGeneratedKeys="true" keyProperty="carId">
|
||||
insert into car
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<module>muyu-business-common</module>
|
||||
<module>muyu-business-server</module>
|
||||
<module>muyu-business-client</module>
|
||||
<module>muyu-business-kafka</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.muyu.common.system.domain.SysUser;
|
|||
import com.muyu.goods.domain.Custom;
|
||||
import com.muyu.goods.domain.Enterprise;
|
||||
import com.muyu.goods.domain.Sources;
|
||||
import com.muyu.goods.mq.Producer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
|
@ -32,6 +33,12 @@ public class EnterpriseController extends BaseController
|
|||
@Autowired
|
||||
private IEnterpriseService enterpriseService;
|
||||
|
||||
|
||||
@PostMapping("rest")
|
||||
public void send() {
|
||||
enterpriseService.send();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询企业列表
|
||||
*/
|
||||
|
|
|
@ -14,5 +14,13 @@ public class Producer {
|
|||
rabbitTemplate.convertAndSend("datasource",ip);
|
||||
}
|
||||
|
||||
public void exchangeSource(String ip) {
|
||||
rabbitTemplate.convertAndSend("datasource","",ip);
|
||||
}
|
||||
|
||||
public void vehicleEvent(String name) {
|
||||
rabbitTemplate.convertAndSend("vehicle.event","",name);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -97,4 +97,5 @@ public interface IEnterpriseService
|
|||
|
||||
List<Custom> listCustom();
|
||||
|
||||
void send();
|
||||
}
|
||||
|
|
|
@ -252,4 +252,11 @@ public class EnterpriseServiceImpl implements IEnterpriseService
|
|||
return enterpriseMapper.listCustom();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send() {
|
||||
List<Enterprise> lists = lists();
|
||||
String jsonString = JSONObject.toJSONString(lists);
|
||||
producer.vehicleEvent(jsonString);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-incident</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-incident-client</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-incident-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-incident-server</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.incident.client;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 事件系统启动类
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class VehicleEventClientApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VehicleEventClientApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.incident.client.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* kafka配置
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "kafka")
|
||||
public class KafkaConfig {
|
||||
private static final String queueName = null;
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
/**
|
||||
* 分区
|
||||
*/
|
||||
private Integer partition;
|
||||
public String queueName() {
|
||||
return topic + "." + partition;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.muyu.incident.client.config;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.incident.server.model.IncidentModel;
|
||||
import com.muyu.incident.common.config.MsgConfig;
|
||||
import com.muyu.incident.common.constants.VehicleConstant;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitAdmin;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
|
||||
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* 消息处理配置
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class MsgComponent {
|
||||
/**
|
||||
* 队列声明
|
||||
* @param kafkaConfig 名称依据
|
||||
* @return 队列对象
|
||||
*/
|
||||
@Bean
|
||||
public Queue initCehicleEventClientQueue(KafkaConfig kafkaConfig) {
|
||||
return new Queue(kafkaConfig.queueName(),true,true,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定交换机
|
||||
// * @param vehicleEventExchange 交换机
|
||||
* @param initCehicleEventClientQueue 队列
|
||||
* @return 绑定结果
|
||||
*/
|
||||
@Bean
|
||||
public Binding binding1(Queue initCehicleEventClientQueue) {
|
||||
MsgConfig msgConfig = new MsgConfig();
|
||||
FanoutExchange fanoutExchange = msgConfig.VehicleEvent();
|
||||
System.out.println(fanoutExchange);
|
||||
System.out.println(initCehicleEventClientQueue);
|
||||
return BindingBuilder.bind(initCehicleEventClientQueue).to(fanoutExchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义rabbitmq
|
||||
* @param connectionFactory
|
||||
* @param kafkaConfig
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public SimpleMessageListenerContainer messageListenerContainer(ConnectionFactory connectionFactory,KafkaConfig kafkaConfig) {
|
||||
SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer(connectionFactory);
|
||||
//针对哪些队列(参数为可变参数)
|
||||
simpleMessageListenerContainer.setQueueNames(kafkaConfig.queueName());
|
||||
//同时有多少个消费者线程在消费这个队列,相当于线程池的线程数字。
|
||||
simpleMessageListenerContainer.setConcurrentConsumers(3);
|
||||
//最大的消费者线程数
|
||||
simpleMessageListenerContainer.setMaxConcurrentConsumers(5);
|
||||
//设置消息确认方式 NONE=不确认,MANUAL=手动确认,AUTO=自动确认;
|
||||
//自动确认
|
||||
simpleMessageListenerContainer.setAcknowledgeMode(AcknowledgeMode.AUTO);
|
||||
// simpleMessageListenerContainer.setMessageListener(message -> log.info("springboot.rabbitmq-queue接收到的消息:[{}]", message.toString()));
|
||||
//手动确认(单条确认)
|
||||
simpleMessageListenerContainer.setAcknowledgeMode(AcknowledgeMode.MANUAL);
|
||||
simpleMessageListenerContainer.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
|
||||
log.info("springboot.rabbitmq-queue接收到的消息:[{}]",
|
||||
JSONObject.parseObject(new String(message.getBody()), IncidentModel.class)
|
||||
);
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
});
|
||||
//消费端限流
|
||||
simpleMessageListenerContainer.setPrefetchCount(1);
|
||||
return simpleMessageListenerContainer;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConnectionFactory connectionFactory(RabbitProperties rabbitProperties) {
|
||||
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
|
||||
cachingConnectionFactory.setHost(rabbitProperties.getHost());
|
||||
cachingConnectionFactory.setPort(rabbitProperties.getPort());
|
||||
cachingConnectionFactory.setUsername(rabbitProperties.getUsername());
|
||||
cachingConnectionFactory.setPassword(rabbitProperties.getPassword());
|
||||
//开启发送确认
|
||||
cachingConnectionFactory.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
|
||||
//开启消息返回
|
||||
cachingConnectionFactory.setPublisherReturns(true);
|
||||
cachingConnectionFactory.createConnection();
|
||||
return cachingConnectionFactory;
|
||||
}
|
||||
@Bean
|
||||
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
|
||||
RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
|
||||
rabbitAdmin.setAutoStartup(true);
|
||||
return rabbitAdmin;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
||||
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
||||
rabbitTemplate.setMandatory(true);
|
||||
//消息返回
|
||||
rabbitTemplate.setReturnCallback((message, i, s, s1, s2) -> {
|
||||
log.info("消息返回实现,message:{},replyCode:{},replyText:{},exchange:{},routingKey:{}", message, i, s, s1, s2);
|
||||
});
|
||||
//发送端确认
|
||||
rabbitTemplate.setConfirmCallback((correlationData, b, s) -> {
|
||||
log.info("发送端确认,correlationData:{},ack:{},cause:{}", correlationData, b, s);
|
||||
});
|
||||
return rabbitTemplate;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#server:
|
||||
# port: 8088
|
||||
kafka:
|
||||
topic: vehicle.gateway.001
|
||||
partition: 0
|
||||
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: 129.211.23.219
|
||||
port: 5672
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-incident-common</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.incident.common.config;
|
||||
|
||||
import com.muyu.incident.common.constants.VehicleConstant;
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 工具类
|
||||
*/
|
||||
@Component
|
||||
public class MsgConfig {
|
||||
/**
|
||||
* 创建交换机
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public FanoutExchange VehicleEvent() {
|
||||
return new FanoutExchange(VehicleConstant.VEHICLE_EVENT_EXCHANGE);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.muyu.incident.common.constants;
|
||||
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* 事件系统常量
|
||||
*/
|
||||
public class VehicleConstant {
|
||||
/**
|
||||
* 车辆事件系统交换机
|
||||
*/
|
||||
public static String VEHICLE_EVENT_EXCHANGE = "vehicle.event";
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-incident</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-incident-server</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-incident-common</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,11 @@
|
|||
package com.incident.server;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class VehicleEventSeverApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(VehicleEventSeverApplication.class,args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.incident.server.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.incident.server.model.IncidentModel;
|
||||
import com.muyu.incident.common.constants.VehicleConstant;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class IncidentController {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@PostMapping
|
||||
public String sendMsg(@RequestBody IncidentModel incidentModel) {
|
||||
rabbitTemplate.convertSendAndReceive(VehicleConstant.VEHICLE_EVENT_EXCHANGE,"",
|
||||
JSONObject.toJSONString(incidentModel));
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.incident.server.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class IncidentModel {
|
||||
/**
|
||||
* 唯一键
|
||||
*/
|
||||
private String vin;
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
server:
|
||||
port: 8087
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: 129.211.23.219
|
||||
port: 5672
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>muyu-incident</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>muyu-incident-common</module>
|
||||
<module>muyu-incident-server</module>
|
||||
<module>muyu-incident-client</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -89,12 +89,17 @@
|
|||
<artifactId>muyu-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- rabbitmq-->
|
||||
<!-- rabbitmq依赖-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 添加RabbitMQ支持 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-integration</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSour
|
|||
import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||
import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
|
||||
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;
|
||||
|
@ -14,6 +15,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableMyFeignClients
|
||||
@EnableRabbit
|
||||
@SpringBootApplication(exclude = {DynamicDataSourceAutoConfiguration.class, DataSourceAutoConfiguration.class})
|
||||
public class CloudManyDataSourceApplication {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -8,7 +8,11 @@ import com.rabbitmq.client.Channel;
|
|||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.AmqpAdmin;
|
||||
import org.springframework.amqp.core.ExchangeTypes;
|
||||
import org.springframework.amqp.rabbit.annotation.Exchange;
|
||||
import org.springframework.amqp.rabbit.annotation.Queue;
|
||||
import org.springframework.amqp.rabbit.annotation.QueueBinding;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -22,14 +26,22 @@ import static java.lang.Thread.sleep;
|
|||
@Component
|
||||
@Log4j2
|
||||
public class Consumer {
|
||||
@Autowired
|
||||
private AmqpAdmin amqpAdmin;
|
||||
@Autowired
|
||||
private DruidConfig druidConfig;
|
||||
@Autowired
|
||||
private CloudController controller;
|
||||
|
||||
@RabbitListener(queuesToDeclare = {@Queue("datasource")})
|
||||
|
||||
|
||||
// @RabbitListener(queuesToDeclare = {@Queue("datasource")})
|
||||
@RabbitListener(bindings = {@QueueBinding(value = @Queue("datasource"),
|
||||
exchange = @Exchange(value = "datasource", type = ExchangeTypes.FANOUT))})
|
||||
public void dataSource(String ip){
|
||||
System.out.println(ip);
|
||||
controller.selectIp(ip);
|
||||
amqpAdmin.deleteQueue("datasource");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue