数据解析超级大改动!!!!!

master
fst1996 2023-11-28 00:08:38 +08:00
parent 867d76b705
commit ec51998aaf
34 changed files with 1147 additions and 591 deletions

View File

@ -8,7 +8,7 @@ EXPOSE 9801
VOLUME /home/logs/god-data-server
# 复制jar文件到docker内部
COPY /car-data-server/target/car-data-server.jar /home/app.jar
COPY /target/car-data-data.jar /home/app.jar
#工作目录 exec -it 进来默认就是这个目
WORKDIR /home

View File

@ -1,50 +0,0 @@
<?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.god</groupId>
<artifactId>god-car-data</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>car-data-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>
<!-- God Common DataSource -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-datasource</artifactId>
</dependency>
<!-- God Common DataScope -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-datascope</artifactId>
</dependency>
<!-- God Common Log -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-log</artifactId>
</dependency>
<!-- God Common Swagger -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-swagger</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,28 +0,0 @@
<?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.god</groupId>
<artifactId>god-car-data</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>car-data-remote</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.god</groupId>
<artifactId>car-data-common</artifactId>
<version>3.6.3</version>
</dependency>
</dependencies>
</project>

View File

@ -1,115 +0,0 @@
<?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.god</groupId>
<artifactId>god-car-data</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>car-data-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>
<!-- kafka-->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</dependency>
<!-- 公共层-->
<dependency>
<groupId>com.god</groupId>
<artifactId>car-data-common</artifactId>
<version>3.6.3</version>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 加入maven deploy插件当在deploy时忽略些model-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,111 +0,0 @@
package com.god.data.server.config;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
import org.springframework.kafka.listener.ContainerProperties;
import org.springframework.kafka.support.serializer.JsonDeserializer;
import java.util.HashMap;
import java.util.Map;
/**
* @author
* @date 2022/10/31 18:05
* kafkaymlyml
*/
@SpringBootConfiguration
public class KafkaConsumerConfig {
@Value("${spring.kafka.consumer.bootstrap-servers}")
private String bootstrapServers;
@Value("${spring.kafka.consumer.group-id}")
private String groupId;
@Value("${spring.kafka.consumer.enable-auto-commit}")
private boolean enableAutoCommit;
@Value("${spring.kafka.properties.session.timeout.ms}")
private String sessionTimeout;
@Value("${spring.kafka.properties.max.poll.interval.ms}")
private String maxPollIntervalTime;
@Value("${spring.kafka.consumer.max-poll-records}")
private String maxPollRecords;
@Value("${spring.kafka.consumer.auto-offset-reset}")
private String autoOffsetReset;
@Value("${spring.kafka.listener.concurrency}")
private Integer concurrency;
@Value("${spring.kafka.listener.missing-topics-fatal}")
private boolean missingTopicsFatal;
@Value("${spring.kafka.listener.poll-timeout}")
private long pollTimeout;
@Bean
public Map<String, Object> consumerConfigs() {
Map<String, Object> propsMap = new HashMap<>(16);
propsMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
propsMap.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
//是否自动提交偏移量默认值是true为了避免出现重复数据和数据丢失可以把它设置为false然后手动提交偏移量
propsMap.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, enableAutoCommit);
//自动提交的时间间隔,自动提交开启时生效
propsMap.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "2000");
//该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
//earliest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时从头开始消费分区的记录
//latest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时消费新产生的该分区下的数据在消费者启动之后生成的记录
//none当各分区都存在已提交的offset时从提交的offset开始消费只要有一个分区不存在已提交的offset则抛出异常
propsMap.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
//两次poll之间的最大间隔默认值为5分钟。如果超过这个间隔会触发reBalance
propsMap.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalTime);
//这个参数定义了poll方法最多可以拉取多少条消息默认值为500。如果在拉取消息的时候新消息不足500条那有多少返回多少如果超过500条每次只返回500。
//这个默认值在有些场景下太大有些场景很难保证能够在5min内处理完500条消息
//如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
//然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
//要避免出现上述问题提前评估好处理一条消息最长需要多少时间然后覆盖默认的max.poll.records参数
//注需要开启BatchListener批量监听才会生效如果不开启BatchListener则不会出现reBalance情况
propsMap.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords);
//当broker多久没有收到consumer的心跳请求后就触发reBalance默认值是10s
propsMap.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, sessionTimeout);
//序列化建议使用Json这种序列化方式可以无需额外配置传输实体类
propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
return propsMap;
}
@Bean
public ConsumerFactory<Object, Object> consumerFactory() {
// 配置消费者的 Json 反序列化的可信赖包,反序列化实体类需要
try (JsonDeserializer<Object> deserializer = new JsonDeserializer<>()) {
deserializer.trustedPackages("*");
return new DefaultKafkaConsumerFactory<>(consumerConfigs(), new JsonDeserializer<>(), deserializer);
}
}
/**
* KafkaListenerContainerFactorySpring KafkaKafkaListenerContainer
* KafkaListenerContainerKafkaKafkaAPI便使
* KafkaListenerContainerFactoryKafkaListenerContainer
* Spring KafkaKafkaListenerContainerFactoryKafkaListenerContainerKafka
* @return
*/
@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<Object, Object>> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<Object, Object> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
//在侦听器容器中运行的线程数,一般设置为 机器数*分区数
factory.setConcurrency(concurrency);
// 消费监听接口监听的主题不存在时默认会报错所以设置为false忽略错误
factory.setMissingTopicsFatal(missingTopicsFatal);
// 自动提交关闭,需要设置手动消息确认
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
factory.getContainerProperties().setPollTimeout(pollTimeout);
// 设置为批量监听需要用List接收
// factory.setBatchListener(true);
return factory;
}
}

View File

@ -1,89 +0,0 @@
package com.god.data.server.config;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.kafka.transaction.KafkaTransactionManager;
import org.springframework.kafka.support.serializer.JsonSerializer;
import java.util.HashMap;
import java.util.Map;
/**
* kafka
*/
@SpringBootConfiguration
public class KafkaProviderConfig {
@Value("${spring.kafka.producer.bootstrap-servers}")
private String bootstrapServers;
@Value("${spring.kafka.producer.transaction-id-prefix}")
private String transactionIdPrefix;
@Value("${spring.kafka.producer.acks}")
private String acks;
@Value("${spring.kafka.producer.retries}")
private String retries;
@Value("${spring.kafka.producer.batch-size}")
private String batchSize;
@Value("${spring.kafka.producer.buffer-memory}")
private String bufferMemory;
/**
* Map Kafka
* @return
*/
@Bean
public Map<String, Object> producerConfigs() {
Map<String, Object> props = new HashMap<>(16);
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
//acks=0 生产者在成功写入消息之前不会等待任何来自服务器的响应。
//acks=1 只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。
//acks=all :只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。
//开启事务必须设为all
props.put(ProducerConfig.ACKS_CONFIG, acks);
//发生错误后消息重发的次数开启事务必须大于0
props.put(ProducerConfig.RETRIES_CONFIG, retries);
//当多个消息发送到相同分区时,生产者会将消息打包到一起,以减少请求交互. 而不是一条条发送
//批次的大小可以通过batch.size 参数设置.默认是16KB
//较小的批次大小有可能降低吞吐量批次大小为0则完全禁用批处理
//比如说kafka里的消息5秒钟Batch才凑满了16KB才能发送出去。那这些消息的延迟就是5秒钟
//实测batchSize这个参数没有用
props.put(ProducerConfig.BATCH_SIZE_CONFIG, batchSize);
//有的时刻消息比较少,过了很久,比如5min也没有凑够16KB,这样延时就很大,所以需要一个参数. 再设置一个时间,到了这个时间,
//即使数据没达到16KB,也将这个批次发送出去
props.put(ProducerConfig.LINGER_MS_CONFIG, "5000");
//生产者内存缓冲区的大小
props.put(ProducerConfig.BUFFER_MEMORY_CONFIG, bufferMemory);
//反序列化,和生产者的序列化方式对应
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
return props;
}
/**
*
* @return
*/
@Bean
public ProducerFactory<Object, Object> producerFactory() {
DefaultKafkaProducerFactory<Object, Object> factory = new DefaultKafkaProducerFactory<>(producerConfigs());
//开启事务,会导致 LINGER_MS_CONFIG 配置失效
factory.setTransactionIdPrefix(transactionIdPrefix);
return factory;
}
@Bean
public KafkaTransactionManager<Object, Object> kafkaTransactionManager(ProducerFactory<Object, Object> producerFactory) {
return new KafkaTransactionManager<>(producerFactory);
}
@Bean
public KafkaTemplate<Object, Object> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory());
}
}

View File

@ -1,47 +0,0 @@
package com.god.data.server.controller;
import com.god.common.core.domain.Result;
import com.god.data.server.config.KafkaSendResultHandler;
import com.god.data.server.test.KafkaMessageTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @description:
* @Author fst
* @date 2023/11/21 20:21
*/
@RequestMapping("kafka")
@Controller
public class KafkaController {
@Autowired
KafkaMessageTest messageTest;
private KafkaTemplate<Object,Object> kafkaTemplate;
//使用构造器注入
public KafkaController(KafkaTemplate<Object,Object> kafkaTemplate, KafkaSendResultHandler kafkaSendResultHandler){
this.kafkaTemplate=kafkaTemplate;
this.kafkaTemplate.setProducerListener(kafkaSendResultHandler);
}
@GetMapping("test001")
public Result test001(){
messageTest.providerMessage();
messageTest.consumerMessage();
System.out.println("11111");
return Result.success();
}
@GetMapping("test002")
@Transactional
public Result test002(){
kafkaTemplate.send("test002","能不能测试成功");
return Result.success();
}
}

View File

@ -1,43 +0,0 @@
package com.god.data.server.listeners;
import com.god.common.redis.service.RedisService;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;
/**
* @description: kafka
* @Author fst
* @date 2023/11/21 21:24
*/
@Component
@Log4j2
public class KafkaListenerTest {
@Autowired
private RedisService redisService;
/**
* @description: kafka
*/
@KafkaListener(topics = { "test002" },
containerFactory = "kafkaListenerContainerFactory",
errorHandler = "myKafkaListenerErrorHandler")
public void kafkaProducer(ConsumerRecord<Object,Object> record, Acknowledgment acknowledgment){
//获取消息
String value = (String) record.value();
log.info("监听到消息,开始消费,消息为:{}",value);
//获取消息的key
String key = (String) record.key();
System.out.println("======================");
System.out.println(value);
//手动确认
acknowledgment.acknowledge();
}
}

View File

@ -1,74 +0,0 @@
package com.god.data.server.test;
import com.god.data.server.config.KafkaConsumerConfig;
import com.god.data.server.config.KafkaProviderConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.protocol.types.Field;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
/**
* @description: kafka
* @Author fst
* @date 2023/11/21 18:42
*/
@Component
public class KafkaMessageTest {
@Autowired
KafkaProviderConfig kafkaProviderConfig;
@Autowired
KafkaConsumerConfig kafkaConsumerConfig;
/**
* @description: Kafka
*/
public void providerMessage(){
//通过配置工具类获取配置map
Map<String, Object> stringObjectMap = kafkaProviderConfig.producerConfigs();
Properties properties = new Properties();
properties.putAll(stringObjectMap);
//通过map来生成kafka生产者对象
KafkaProducer<String, String> stringStringKafkaProducer = new KafkaProducer<String, String>(properties);
//发送消息 封装发送消息对象
ProducerRecord<String, String> stringStringProducerRecord = new ProducerRecord<>("test001", "hello_kafka");
stringStringKafkaProducer.send(stringStringProducerRecord);
//关闭通道
stringStringKafkaProducer.close();
}
/**
* @description: -
*/
public void consumerMessage(){
Map<String, Object> stringObjectMap = kafkaConsumerConfig.consumerConfigs();
Properties properties = new Properties();
properties.putAll(stringObjectMap);
//构建kafka消费者对象
KafkaConsumer<String, String> kafkaConsumer = new KafkaConsumer<String, String>(properties);
//订阅主题
kafkaConsumer.subscribe(Collections.singleton("test001"));
//循环获取消息
ConsumerRecords<String, String> poll = kafkaConsumer.poll(Duration.ofMillis(1000));
for (ConsumerRecord<String, String> consumerRecord : poll) {
System.out.println("====================");
System.out.println(consumerRecord.key());
System.out.println(consumerRecord.value());
}
}
}

137
pom.xml
View File

@ -7,12 +7,6 @@
<artifactId>god-car</artifactId>
<version>3.6.3</version>
</parent>
<packaging>pom</packaging>
<modules>
<module>car-data-common</module>
<module>car-data-remote</module>
<module>car-data-server</module>
</modules>
<modelVersion>4.0.0</modelVersion>
<version>3.6.3</version>
@ -22,6 +16,12 @@
god-car-data车联网数据解析层
</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>menghang-public</id>
@ -31,6 +31,7 @@
</repositories>
<distributionManagement>
<repository>
<id>menghang-releases</id>
<name>梦航-releases</name>
@ -38,5 +39,129 @@
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<!-- kafka-->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
</dependency>
<!-- 公共层-->
<dependency>
<groupId>com.god</groupId>
<artifactId>car-data-common</artifactId>
<version>3.6.3</version>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<!-- God Common DataSource -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-datasource</artifactId>
</dependency>
<!-- God Common DataScope -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-datascope</artifactId>
</dependency>
<!-- God Common Log -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-log</artifactId>
</dependency>
<!-- God Common Swagger -->
<dependency>
<groupId>com.god</groupId>
<artifactId>god-common-swagger</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 加入maven deploy插件当在deploy时忽略些model-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,256 @@
package com.god.data.common.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @description:
* @Author fst
* @date 2023/11/23 14:33
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CarMessage {
/**
* VIN
*/
private String vin;
/**
*
*/
private Long timeString;
/**
*
*/
private BigDecimal longitude;
/**
*
*/
private BigDecimal latitude;
/**
* KM/H
*/
private BigDecimal speed;
/**
*
*/
private BigDecimal sumMileage;
/**
*
*/
private BigDecimal sumVoltage;
/**
*
*/
private BigDecimal sumElectricity;
/**
*
*/
private BigDecimal sumResistance;
/**
*
*/
private String gear;
/**
*
*/
private BigDecimal acceleratorPedal;
/**
*
*/
private BigDecimal brakePedal;
/**
* Specific fuel consumption
*/
private BigDecimal specificFuelConsumption;
/**
*
*/
private BigDecimal motorControllerTemperature;
/**
*
*/
private Long motorSpeed;
/**
*
*/
private Long motorTorque;
/**
*
*/
private BigDecimal motorTemperature;
/**
*
*/
private BigDecimal motorTage;
/**
*
*/
private BigDecimal motorCurrent;
/**
* SOC
*/
private BigDecimal remainingBattery;
/**
*
*/
private BigDecimal maximumFeedbackPower;
/**
*
*/
private BigDecimal maximumDischargePower;
/**
* BMS
*/
private Integer selfCheckCounter;
/**
*
*/
private BigDecimal totalBatteryCurrent;
/**
* V3
*/
private BigDecimal totalBatteryVoltage;
/**
*
*/
private BigDecimal singleBatteryMaxVoltage;
/**
*
*/
private BigDecimal singleBatteryMinVoltage;
/**
*
*/
private BigDecimal singleBatteryMaxTemperature;
/**
*
*/
private BigDecimal singleBatteryMinTemperature;
/**
*
*/
private BigDecimal availableBatteryCapacity;
/**
*
*/
private Integer vehicleStatus;
/**
*
*/
private Integer chargingStatus;
/**
*
*/
private Integer operatingStatus;
/**
* SOC
*/
private Integer socStatus;
/**
*
*/
private Integer chargingEnergyStorageStatus;
/**
*
*/
private Integer driveMotorStatus;
/**
*
*/
private Integer positionStatus;
/**
* EAS
*/
private Integer easStatus;
/**
* PTC
*/
private Integer ptcStatus;
/**
* EPS
*/
private Integer epsStatus;
/**
* ABS
*/
private Integer absStatus;
/**
* MCU
*/
private Integer mcuStatus;
/**
*
*/
private Integer heatingStatus;
/**
*
*/
private Integer batteryStatus;
/**
*
*/
private Integer batteryInsulationStatus;
/**
* DCDC
*/
private Integer dcdcStatus;
/**
* CHG
*/
private Integer chgStatus;
}

View File

@ -0,0 +1,25 @@
package com.god.data.common.domain;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* rabbitmq
* @deprecated rabbitmqjava
* Serializable
* Serializable
*/
@Data
public class LogMessage implements Serializable {
private Long id;
private String msg;
private String logLevel;
private String serviceType;
private Date createTime;
private Long userId;
private String exchange;
}

View File

@ -0,0 +1,89 @@
package com.god.data.config.kafka;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.support.serializer.JsonDeserializer;
import java.util.List;
import java.util.Properties;
import static com.god.data.contents.KafkaContent.TOPIC;
/**
* @author fst
* @date 2023/11/24 17:30
* kafkaymlyml
*/
@Data
@Builder
@Configuration
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "spring.kafka.consumer")
public class KafkaConsumerConfig {
// kafka消费者服务器
private String bootstrapServers;
// 分组id
private String groupId;
// 是否自动提交偏移量默认为true为了避免出现重复数据和数据丢失设置为false手动提交
private boolean enableAutoCommit;
private Integer autoCommitInterval;
private String sessionTimeout;
private String maxPollIntervalTime;
private String maxPollRecords;
private String autoOffsetReset;
private String keyDeserializer;
private String valueDeserializer;
@Bean
public KafkaConsumer<String, String> consumerConfigs() {
Properties properties = new Properties();
properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
properties.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
//是否自动提交偏移量默认值是true为了避免出现重复数据和数据丢失可以把它设置为false然后手动提交偏移量
properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, enableAutoCommit);
//自动提交的时间间隔,自动提交开启时生效
properties.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, autoCommitInterval);
//该属性指定了消费者在读取一个没有偏移量的分区或者偏移量无效的情况下该作何处理:
//earliest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时从头开始消费分区的记录
//latest当各分区下有已提交的offset时从提交的offset开始消费无提交的offset时消费新产生的该分区下的数据在消费者启动之后生成的记录
//none当各分区都存在已提交的offset时从提交的offset开始消费只要有一个分区不存在已提交的offset则抛出异常
properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, autoOffsetReset);
//两次poll之间的最大间隔默认值为5分钟。如果超过这个间隔会触发reBalance
properties.put(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG, maxPollIntervalTime);
//这个参数定义了poll方法最多可以拉取多少条消息默认值为500。如果在拉取消息的时候新消息不足500条那有多少返回多少如果超过500条每次只返回500。
//这个默认值在有些场景下太大有些场景很难保证能够在5min内处理完500条消息
//如果消费者无法在5分钟内处理完500条消息的话就会触发reBalance,
//然后这批消息会被分配到另一个消费者中,还是会处理不完,这样这批消息就永远也处理不完。
//要避免出现上述问题提前评估好处理一条消息最长需要多少时间然后覆盖默认的max.poll.records参数
//注需要开启BatchListener批量监听才会生效如果不开启BatchListener则不会出现reBalance情况
properties.put(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords);
//当broker多久没有收到consumer的心跳请求后就触发reBalance默认值是10s
properties.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG, sessionTimeout);
//序列化建议使用Json这种序列化方式可以无需额外配置传输实体类
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
properties.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
//设置分区器
properties.put("partitioner.class", "com.god.kafka.partitioner.MyPartitioner");
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(properties);
consumer.subscribe(List.of(TOPIC));
return consumer;
}
}

View File

@ -1,4 +1,4 @@
package com.god.data.server.config;
package com.god.data.config.kafka;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

View File

@ -1,4 +1,4 @@
package com.god.data.server.config;
package com.god.data.config.kafka;
import org.apache.kafka.clients.consumer.Consumer;

View File

@ -0,0 +1,48 @@
package com.god.data.config.rabbitmq;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
*
*
*/
@Component
@Log4j2
public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @PostContructspringspring
*/
@PostConstruct
public void init() {
rabbitTemplate.setConfirmCallback(this);
}
/**
*
*
* @param correlationData
* @param ack
* @param cause
*/
@Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
if (!ack) {
String exchange = correlationData.getReturned().getExchange();
String message = correlationData.getReturned().getMessage().getBody().toString();
// 发送异常
log.error("消息:{},发送到交换机:{}失败,原因是:{}", message, exchange, cause);
// TODO 可以把异常信息 以及 消息的内容直接添加到 MYSQL
}
}
}

View File

@ -0,0 +1,41 @@
package com.god.data.config.rabbitmq;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
*
*/
@Component
@Log4j2
public class ReturnCallbackConfig implements RabbitTemplate.ReturnsCallback {
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @PostContructspringspring
*/
@PostConstruct
public void init() {
rabbitTemplate.setReturnsCallback(this);
}
/**
*
*
* @param returnedMessage the returned message and metadata.
*/
@Override
public void returnedMessage(ReturnedMessage returnedMessage) {
log.error("消息:{},被交换机:{} 回退!退回原因为:{}",
returnedMessage.getMessage().toString(), returnedMessage.getExchange(), returnedMessage.getReplyText());
// TODO 回退了所有的信息,可做补偿机制
}
}

View File

@ -0,0 +1,13 @@
package com.god.data.contents;
/**
* @author DongZl
* @description: kafka
* @Date 2023/8/25 18:47
*/
public class KafkaContent {
public static final String TOPIC = "top";
public static final String KAFKA_CON = "39.100.65.135:39092,39.100.65.135:29092,39.100.65.135:19092";
}

View File

@ -0,0 +1,9 @@
package com.god.data.contents;
/**
* rabbitmq
* @Author fst
* @date 2023/11/28 0:07
*/
public class RabbitmqContent {
}

View File

@ -0,0 +1,42 @@
//package com.god.data.listeners;
//
//import com.god.common.redis.service.RedisService;
//import lombok.extern.log4j.Log4j2;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.kafka.support.Acknowledgment;
//import org.springframework.stereotype.Component;
//
///**
// * @description: kafka消费监听
// * @Author fst
// * @date 2023/11/21 21:24
// */
//@Component
//@Log4j2
//public class KafkaListenerTest {
//
// @Autowired
// private RedisService redisService;
//
//
// /**
// * @description: kafka监听
// */
// @KafkaListener(topics = { "test002" },
// containerFactory = "kafkaListenerContainerFactory",
// errorHandler = "myKafkaListenerErrorHandler")
// public void kafkaProducer(ConsumerRecord<Object,Object> record, Acknowledgment acknowledgment){
// //获取消息
// String value = (String) record.value();
// log.info("监听到消息,开始消费,消息为:{}",value);
// //获取消息的key
// String key = (String) record.key();
// System.out.println("======================");
// System.out.println(value);
// //手动确认
// acknowledgment.acknowledge();
// }
//
//}

View File

@ -0,0 +1,43 @@
package com.god.data.partitioner;
import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;
import org.apache.kafka.common.PartitionInfo;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
* @authorfst
* @date2023/11/25
* @aim
*/
@Component
public class MyPartitioner implements Partitioner {
/**
* kafka 3
* @param topic
* @param key key
* @param keyBytes key
* @param value value
* @param valueBytes value
* @param cluster kafka
* @return 3, 0 1 2
*/
public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
//获取topic的partitions信息
List<PartitionInfo> partitionInfos = cluster.partitionsForTopic(topic);
int partitionsNum = partitionInfos.size();
// 这里以 key 的哈希值作为分区选择依据
System.out.println("================================");
System.out.println(Math.abs(key.hashCode()) % partitionsNum);
return Math.abs(key.hashCode()) % partitionsNum;
}
public void close() {
}
public void configure(Map<String, ?> map) {
}
}

View File

@ -0,0 +1,37 @@
package com.god.data.rabbitmq.producer;
import com.god.data.common.domain.LogMessage;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.UUID;
/**
* - Producer
* @Component ProducerSpring
* 使SpringBootAMQP访rabbitmqAmqpTemplate
* rabbitmqstarter-amqpspringAmqpTemplate
*/
@Component
public class Sender {
@Autowired
private AmqpTemplate rabbitAmqpTemplate;
/*
*
*/
public void send(LogMessage msg){
/*
convertAndSend - template
javarabbitmqmessagerabbitmq
String
String
Object
*/
this.rabbitAmqpTemplate.convertAndSend(msg.getExchange(), UUID.randomUUID().toString(), msg);
}
}

View File

@ -0,0 +1,27 @@
package com.god.data.service;
import com.god.data.common.domain.CarMessage;
/**
* @description:
* @Author fst
* @date 2023/11/27 20:40
*/
public interface EventService {
/**
*
*/
public void insert();
/**
*
*/
public void execute(CarMessage carMessage);
/**
*
* @param event
*/
public void remove(String event);
}

View File

@ -0,0 +1,65 @@
package com.god.data.service;
import com.god.common.core.utils.SpringUtils;
import com.god.common.redis.service.RedisService;
import com.god.data.common.domain.CarMessage;
import com.god.data.utils.AnalyzeUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.time.Duration;
import java.util.List;
/**
* kafka
* @author fst
* @Date 2023-11-27 20:02
*/
@Log4j2
@Component
public class ParseDataService {
@Autowired
private RedisService redisService;
private final KafkaConsumer<String, String> consumer;
@Autowired
public ParseDataService(KafkaConsumer<String, String> consumer) {
this.consumer = consumer;
}
@PostConstruct
public void start(){
new Thread(() -> {
while (true){
ConsumerRecords<String, String> records = null;
try {
//死循环拉取kafka数据
records = consumer.poll(Duration.ofMillis(100));
for (ConsumerRecord<String, String> record : records) {
CarMessage carMessage = AnalyzeUtils.parseVehicleData(record.value());
//根据对象车辆vin获取事件集合从redis中获取
List<String> eventList = redisService.getCacheList("event" + carMessage.getVin());
//执行事件
if(eventList!= null && !eventList.isEmpty()){
for (String event : eventList) {
EventService eventService = SpringUtils.getBean(event);
eventService.execute(carMessage);
}
}
System.out.println(record.offset() +" - "+ record.key() +" - "+ record.value());
}
}catch (Exception e){
log.info("records {}", records);
log.error(e);
}
}
}).start();
}
}

View File

@ -0,0 +1,28 @@
package com.god.data.service.impl;
import com.god.data.common.domain.CarMessage;
import com.god.data.service.EventService;
import org.springframework.stereotype.Service;
/**
*
* @Author fst
* @date 2023/11/27 20:43
*/
@Service(value = "Fence")
public class ElectronicFenceEvent implements EventService {
@Override
public void insert() {
}
@Override
public void execute(CarMessage carMessage) {
}
@Override
public void remove(String event) {
}
}

View File

@ -0,0 +1,45 @@
package com.god.data.service.impl;
import com.god.common.redis.service.RedisService;
import com.god.data.common.domain.CarMessage;
import com.god.data.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
/**
*
* @Author fst
* @date 2023/11/27 21:50
*/
@Service(value = "FaultAlarm")
public class FaultAlarmEvent implements EventService {
@Autowired
private RedisService redisService;
@Override
public void insert() {
}
@Override
public void execute(CarMessage carMessage) {
//创建集合存故障码
ArrayList<String> strings = new ArrayList<>();
//判断车辆目前的报错故障,添加对应的故障码
if (carMessage.getBatteryStatus()==1){
strings.add("111");
}
//把对应的故障码存入rabbitmq
}
@Override
public void remove(String event) {
}
}

View File

@ -0,0 +1,28 @@
package com.god.data.service.impl;
import com.god.data.common.domain.CarMessage;
import com.god.data.service.EventService;
import org.springframework.stereotype.Service;
/**
*
* @Author fst
* @date 2023/11/27 21:47
*/
@Service(value = "RealTimeTrajectory")
public class RealTimeTrajectoryEvent implements EventService {
@Override
public void insert() {
}
@Override
public void execute(CarMessage carMessage) {
}
@Override
public void remove(String event) {
}
}

View File

@ -0,0 +1,69 @@
//package com.god.data.test;
//
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.apache.kafka.clients.consumer.ConsumerRecords;
//import org.apache.kafka.clients.consumer.KafkaConsumer;
//import org.apache.kafka.clients.producer.KafkaProducer;
//import org.apache.kafka.clients.producer.ProducerRecord;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.time.Duration;
//import java.util.Collections;
//import java.util.Map;
//import java.util.Properties;
//
///**
// * @description: kafka消费测试一
// * @Author fst
// * @date 2023/11/21 18:42
// */
//@Component
//public class KafkaMessageTest {
//
// @Autowired
// KafkaProviderConfig kafkaProviderConfig;
//
// @Autowired
// KafkaConsumerConfig kafkaConsumerConfig;
//
//
// /**
// * @description: Kafka生产者
// */
// public void providerMessage(){
// //通过配置工具类获取配置map
// Map<String, Object> stringObjectMap = kafkaProviderConfig.producerConfigs();
// Properties properties = new Properties();
// properties.putAll(stringObjectMap);
// //通过map来生成kafka生产者对象
// KafkaProducer<String, String> stringStringKafkaProducer = new KafkaProducer<String, String>(properties);
// //发送消息 封装发送消息对象
// ProducerRecord<String, String> stringStringProducerRecord = new ProducerRecord<>("test001", "hello_kafka");
// stringStringKafkaProducer.send(stringStringProducerRecord);
// //关闭通道
// stringStringKafkaProducer.close();
// }
//
// /**
// * @description: 独立消费者-订阅主题
// */
// public void consumerMessage(){
// Map<String, Object> stringObjectMap = kafkaConsumerConfig.consumerConfigs();
// Properties properties = new Properties();
// properties.putAll(stringObjectMap);
// //构建kafka消费者对象
// KafkaConsumer<String, String> kafkaConsumer = new KafkaConsumer<String, String>(properties);
// //订阅主题
// kafkaConsumer.subscribe(Collections.singleton("test001"));
// //循环获取消息
//
// ConsumerRecords<String, String> poll = kafkaConsumer.poll(Duration.ofMillis(1000));
// for (ConsumerRecord<String, String> consumerRecord : poll) {
// System.out.println("====================");
// System.out.println(consumerRecord.key());
// System.out.println(consumerRecord.value());
// }
//
// }
//}

View File

@ -0,0 +1,34 @@
package com.god.data.test;
import com.alibaba.fastjson2.JSONObject;
import com.god.data.common.domain.CarMessage;
import com.god.data.utils.AnalyzeUtils;
import org.junit.jupiter.api.Test;
/**
* @description:
* @Author fst
* @date 2023/11/23 21:59
*/
public class Test007 {
/**
* showStr
*/
@Test
public void showStr(){
/*
* str
*/
String str = "7E 56 49 4e 31 32 33 34 35 36 37 38 39 31 32 33 34 35 31 37 30 30 37 34 37 34 37 35 37 39 34 31 31 36 2e 36 37 30 32 33 35 30 33 39 2e 35 33 38 39 39 36 30 31 38 30 2e 30 30 31 33 2e 30 38 30 30 30 30 30 30 36 38 36 30 30 30 34 38 30 30 30 37 35 37 31 30 30 30 30 30 44 37 30 39 30 31 30 2e 30 30 36 32 30 30 30 30 31 34 33 32 30 35 33 39 30 38 31 30 30 30 30 31 36 33 30 30 37 36 35 39 30 30 30 30 34 34 39 35 38 2e 37 38 30 30 30 30 32 30 30 30 30 30 31 33 31 31 30 30 30 32 36 33 30 30 30 33 30 30 30 33 30 30 30 31 30 30 30 30 30 35 33 30 30 30 30 37 39 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 dc 7E";
/*
* 使AnalyzeUtilsparseVehicleData
*/
CarMessage carMessage = AnalyzeUtils.parseVehicleData(str);
/*
*
*/
System.out.println(carMessage);
}
}

View File

@ -0,0 +1,90 @@
package com.god.data.utils;
import com.god.data.common.domain.CarMessage;
import java.math.BigDecimal;
/**
*
* @description:
* @Author fst
* @date 2023/11/23 14:30
*/
public class AnalyzeUtils {
/**
*
*/
public static CarMessage parseVehicleData(String hexInput) {
//先去除空格
String inputString = hexInput.replaceAll(" ", "");
//调用工具类解析报文
String input = hexToString(inputString);
CarMessage carMessage = new CarMessage();
CarMessage.builder()
.vin(input.substring(1, 17))
.timeString(Long.valueOf(input.substring(18, 30)))
.longitude(BigDecimal.valueOf(Double.parseDouble(input.substring(31, 41))))
.latitude(BigDecimal.valueOf(Double.parseDouble(input.substring(42, 51))))
.speed(BigDecimal.valueOf(Double.parseDouble(input.substring(52, 57))))
.sumMileage(BigDecimal.valueOf(Double.parseDouble(input.substring(58, 68))))
.sumVoltage(BigDecimal.valueOf(Double.parseDouble(input.substring(69, 74))))
.sumElectricity(BigDecimal.valueOf(Double.parseDouble(input.substring(75, 79))))
.sumResistance(BigDecimal.valueOf(Double.parseDouble(input.substring(80, 88))))
.gear(input.substring(89, 89))
.acceleratorPedal(BigDecimal.valueOf(Double.parseDouble(input.substring(90, 91))))
.brakePedal(BigDecimal.valueOf(Double.parseDouble(input.substring(92, 93))))
.specificFuelConsumption(BigDecimal.valueOf(Double.parseDouble(input.substring(94, 98))))
.motorControllerTemperature(BigDecimal.valueOf(Double.parseDouble(input.substring(99, 104))))
.motorSpeed(Long.valueOf(input.substring(105, 109)))
.motorTorque(Long.valueOf(input.substring(110, 113)))
.motorTemperature(BigDecimal.valueOf(Double.parseDouble(input.substring(114, 119))))
.motorTage(BigDecimal.valueOf(Double.parseDouble(input.substring(120, 124))))
.motorCurrent(BigDecimal.valueOf(Double.parseDouble(input.substring(125, 132))))
.remainingBattery(BigDecimal.valueOf(Double.parseDouble(input.substring(133, 138))))
.maximumFeedbackPower(BigDecimal.valueOf(Double.parseDouble(input.substring(139, 144))))
.maximumDischargePower(BigDecimal.valueOf(Double.parseDouble(input.substring(145, 150))))
.selfCheckCounter(Integer.valueOf(input.substring(151, 152)))
.totalBatteryCurrent(BigDecimal.valueOf(Double.parseDouble(input.substring(153, 157))))
.totalBatteryVoltage(BigDecimal.valueOf(Double.parseDouble(input.substring(158, 163))))
.singleBatteryMaxVoltage(BigDecimal.valueOf(Double.parseDouble(input.substring(164, 167))))
.singleBatteryMinVoltage(BigDecimal.valueOf(Double.parseDouble(input.substring(168, 171))))
.singleBatteryMaxTemperature(BigDecimal.valueOf(Double.parseDouble(input.substring(172, 177))))
.singleBatteryMinTemperature(BigDecimal.valueOf(Double.parseDouble(input.substring(178, 183))))
.availableBatteryCapacity(BigDecimal.valueOf(Double.parseDouble(input.substring(184, 189))))
.vehicleStatus(Integer.valueOf(input.substring(190, 190)))
.chargingStatus(Integer.valueOf(input.substring(191, 191)))
.operatingStatus(Integer.valueOf(input.substring(192, 192)))
.socStatus(Integer.valueOf(input.substring(193, 193)))
.chargingEnergyStorageStatus(Integer.valueOf(input.substring(194, 194)))
.driveMotorStatus(Integer.valueOf(input.substring(195, 195)))
.positionStatus(Integer.valueOf(input.substring(196, 196)))
.easStatus(Integer.valueOf(input.substring(197, 197)))
.ptcStatus(Integer.valueOf(input.substring(198, 198)))
.epsStatus(Integer.valueOf(input.substring(199, 199)))
.absStatus(Integer.valueOf(input.substring(200, 200)))
.mcuStatus(Integer.valueOf(input.substring(201, 201)))
.heatingStatus(Integer.valueOf(input.substring(202, 202)))
.batteryStatus(Integer.valueOf(input.substring(203, 203)))
.batteryInsulationStatus(Integer.valueOf(input.substring(204, 204)))
.dcdcStatus(Integer.valueOf(input.substring(205, 205)))
.chgStatus(Integer.valueOf(input.substring(206, 206)));
//返回解析完的对象
return carMessage;
}
private static String hexToString(String hex) {
StringBuilder output = new StringBuilder();
for (int i = 0; i < hex.length(); i += 2) {
String str = hex.substring(i, i + 2);
output.append((char) Integer.parseInt(str, 16));
}
return output.toString();
}
}

View File

@ -25,25 +25,6 @@ spring:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
# kafka
kafka:
producer:
# Kafka生产者服务器
bootstrap-servers: 10.100.1.8:9092
transaction-id-prefix: kafkaTx-
retries: 3
# acks=0 : 生产者成功写入消息不会等待任何来自服务器的相应
# acks=1 : 只要集群的master收到消息生产者就会收到一个来自服务器的响应。
# acks=all : 只有当所有参与者的复制节点全部收到消息时,生产者才会收到一个来自服务器的响应
# 开启事务时 必须设置为all
acks: all
# 当有多个消息需要被发送到同一分区时,生产者会把他们放在同一批次里。
batch-size: 16384
# 生产者内存缓冲区的大小
buffer-memory: 1024000
# 键的序列化方式
key-serializer: org.springframework.kafka.support.serializer.JsonSerializer
# 值的序列化方式
value-serializer: org.springframework.kafka.support.serializer.JsonSerializer
consumer:
# kafka消费者服务器
bootstrap-servers: 10.100.1.8:9092
@ -57,11 +38,11 @@ spring:
# 是否自动提交偏移量默认为true为了避免出现重复数据和数据丢失设置为false手动提交
enable-auto-commit: false
# 键的序列化方式
key-deserializer: org.springframework.kafka.support.serializer.JsonSerializer
key-deserializer: org.apache.kafka.common.serialization.StringSerializer
# 值的序列化方式
value-deserializer: org.springframework.kafka.support.serializer.JsonSerializer
value-deserializer: org.apache.kafka.common.serialization.StringSerializer
# 自动提交时间间隔
#auto-commit-interval: 2s
auto-commit-interval: 2000
# 配置消费者的Json反序列化的可信赖包反序列化实体需要
properties:
spring:
@ -75,6 +56,10 @@ spring:
# 要避免出现上述问题提前评估好处理一条消息最长需要多少时间然后覆盖默认的max.poll.records参数
# 注需要开启BatchListener批量监听才会生效如果不开启BatchListener则不会出现reBalance情况
max-poll-records: 3
max-poll-interval-time: 600000
# 当broker多久没有收到consumer的心跳请求后就触发reBalance,默认值是10s
session-timeout: 10000
properties:
# 两次poll之间的最大间隔默认值为5分钟。如果超过这个间隔会触发reBalance
max:
@ -92,9 +77,23 @@ spring:
ack-mode: manual_immediate
# 消费监听接口监听的主题不存在时默认会报错所以设置为false忽略报错
missing-topics-fatal: false
# 两次poll之间的最大间隔默认值为5分钟。如果超过这个间隔会触发reBalance
poll-timeout: 600000
#rabbitmq配置
rabbitmq:
port: 5672
host: 10.100.1.5
username: guest
password: guest
#这个配置是保证提供者确保消息推送到交换机中,不管成不成功,都会回调
publisher-confirm-type: correlated
#保证交换机能把消息推送到队列中
publisher-returns: true
virtual-host: /
#这个配置是保证消费者会消费消息,手动确认
listener:
simple:
acknowledge-mode: manual
template:
mandatory: true
logging:
level:
com.god.system.mapper: DEBUG