初始化
commit
789e445e70
|
@ -0,0 +1,32 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
/.idea
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
|
@ -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>
|
||||
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>vehicle-event</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>vehicle-event-server</module>
|
||||
<module>vehicle-event-client</module>
|
||||
<module>vehicle-event-common</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>2.7.18</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<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>
|
|
@ -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>vehicle-event</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>vehicle-event-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>vehicle-event-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.vehicle.event.client;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: 事件系统启动类
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class VehicleEventClientApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(VehicleEventClientApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.muyu.vehicle.event.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;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: kafka配置
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "kafka")
|
||||
public class KafkaConfig {
|
||||
|
||||
|
||||
/**
|
||||
* 主题
|
||||
*/
|
||||
private String topic;
|
||||
|
||||
/**
|
||||
* 分区
|
||||
*/
|
||||
private Integer partition;
|
||||
|
||||
public String queueName(){
|
||||
return topic + "." + partition;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package com.muyu.vehicle.event.client.config;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.vhilce.event.common.model.EventModel;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.core.*;
|
||||
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
|
||||
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: 消息处理配置
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Log4j2
|
||||
@Component
|
||||
public class MsgComponent {
|
||||
|
||||
/**
|
||||
* 队列声明
|
||||
* @param kafkaConfig 名称依据
|
||||
* @return 队列对象
|
||||
*/
|
||||
@Bean
|
||||
public Queue initVehicleEventClientQueue(KafkaConfig kafkaConfig){
|
||||
return new Queue(kafkaConfig.queueName(), true, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定
|
||||
* @param vehicleEventExchange 交换机
|
||||
* @param initVehicleEventClientQueue 队列
|
||||
* @return 绑定结果
|
||||
*/
|
||||
@Bean
|
||||
public Binding binding1(FanoutExchange vehicleEventExchange,
|
||||
Queue initVehicleEventClientQueue) {
|
||||
return BindingBuilder.bind(initVehicleEventClientQueue).to(vehicleEventExchange);
|
||||
}
|
||||
|
||||
@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));
|
||||
//手动确认(单条确认)
|
||||
simpleMessageListenerContainer.setAcknowledgeMode(AcknowledgeMode.MANUAL);
|
||||
simpleMessageListenerContainer.setMessageListener((ChannelAwareMessageListener) (message, channel) -> {
|
||||
log.info("springboot.rabbitmq-queue接收到的消息:[{}]",
|
||||
JSONObject.parseObject(new String(message.getBody()), EventModel.class)
|
||||
);
|
||||
if (channel != null) {
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
}
|
||||
});
|
||||
//消费端限流
|
||||
simpleMessageListenerContainer.setPrefetchCount(1);
|
||||
return simpleMessageListenerContainer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
kafka:
|
||||
topic: vehicle.gateway.001
|
||||
partition: 0
|
||||
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: 175.24.138.82
|
|
@ -0,0 +1,48 @@
|
|||
<?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>vehicle-event</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>vehicle-event-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</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.25</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.50</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,26 @@
|
|||
package com.muyu.vhilce.event.common.config;
|
||||
|
||||
import com.muyu.vhilce.event.common.constants.VehicleConstant;
|
||||
import org.springframework.amqp.core.FanoutExchange;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: 消息配置
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class MsgConfig {
|
||||
|
||||
/**
|
||||
* 创建交换机
|
||||
* @return 事件交互交换机
|
||||
*/
|
||||
@Bean
|
||||
public FanoutExchange vehicleEventExchange() {
|
||||
return new FanoutExchange(VehicleConstant.VEHICLE_EVENT_EXCHANGE);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.muyu.vhilce.event.common.constants;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: 事件系统常量
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class VehicleConstant {
|
||||
|
||||
/**
|
||||
* 车辆事件系统交换机
|
||||
*/
|
||||
public static final String VEHICLE_EVENT_EXCHANGE = "vehicle.event";
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.vhilce.event.common.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: 事件模型
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EventModel {
|
||||
|
||||
/**
|
||||
* 车辆VIN
|
||||
*/
|
||||
private String vin;
|
||||
|
||||
/**
|
||||
* 消息类型
|
||||
*/
|
||||
private String type;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.muyu.vhilce.event.common.config.MsgConfig
|
|
@ -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>vehicle-event</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>vehicle-event-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>vehicle-event-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
package com.muyu.vehicle.event.server;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: 事件处理服务端
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class VehicleEventServerApplication {
|
||||
public static void main (String[] args) {
|
||||
SpringApplication.run(VehicleEventServerApplication.class, args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.muyu.vehicle.event.server.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.muyu.vhilce.event.common.constants.VehicleConstant;
|
||||
import com.muyu.vhilce.event.common.model.EventModel;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Author: DongZeLiang
|
||||
* @date: 2024/6/14
|
||||
* @Description: 测试msg
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/test")
|
||||
public class TestMsgController {
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@PostMapping
|
||||
public String sendMsg(@RequestBody EventModel eventModel){
|
||||
rabbitTemplate.convertSendAndReceive(VehicleConstant.VEHICLE_EVENT_EXCHANGE, "",
|
||||
JSONObject.toJSONString(eventModel)
|
||||
|
||||
);
|
||||
return "成功";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
spring:
|
||||
rabbitmq:
|
||||
host: 175.24.138.82
|
||||
server:
|
||||
port: 9023
|
Loading…
Reference in New Issue