From a1fca6b081c529b2d2cfa5dead58194608a0c391 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=91=E5=B9=B4=E6=A2=A6=E4=B8=8E=E7=A0=96?=
<2847127106@qq.com>
Date: Thu, 26 Sep 2024 20:28:07 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=95=B0=E6=8D=AE=E5=A4=84?=
=?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97,=E5=AE=8C=E6=88=90=E8=BD=A6?=
=?UTF-8?q?=E8=BE=86=E4=B8=8A=E4=B8=8B=E7=BA=BFRabbit=E7=9B=91=E5=90=AC?=
=?UTF-8?q?=E5=99=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
cloud-data-processing/pom.xml | 113 ++++++++++++++++++
.../data/processing/MyDataApplication.java | 27 +++++
.../processing/rebbit/DownlineRabbit.java | 53 ++++++++
.../processing/rebbit/GoOnlineRabbit.java | 54 +++++++++
.../src/main/resources/banner.txt | 2 +
.../src/main/resources/bootstrap.yml | 59 +++++++++
.../src/main/resources/logback/dev.xml | 74 ++++++++++++
.../src/main/resources/logback/prod.xml | 81 +++++++++++++
.../src/main/resources/logback/test.xml | 81 +++++++++++++
9 files changed, 544 insertions(+)
create mode 100644 cloud-data-processing/pom.xml
create mode 100644 cloud-data-processing/src/main/java/com/muyu/data/processing/MyDataApplication.java
create mode 100644 cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/DownlineRabbit.java
create mode 100644 cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/GoOnlineRabbit.java
create mode 100644 cloud-data-processing/src/main/resources/banner.txt
create mode 100644 cloud-data-processing/src/main/resources/bootstrap.yml
create mode 100644 cloud-data-processing/src/main/resources/logback/dev.xml
create mode 100644 cloud-data-processing/src/main/resources/logback/prod.xml
create mode 100644 cloud-data-processing/src/main/resources/logback/test.xml
diff --git a/cloud-data-processing/pom.xml b/cloud-data-processing/pom.xml
new file mode 100644
index 0000000..d06b4e2
--- /dev/null
+++ b/cloud-data-processing/pom.xml
@@ -0,0 +1,113 @@
+
+
+ 4.0.0
+
+ com.muyu
+ cloud-server
+ 3.6.3
+
+
+ cloud-data-processing
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+ com.muyu
+ cloud-common-caffeine
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-sentinel
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+ com.mysql
+ mysql-connector-j
+
+
+
+
+ com.muyu
+ cloud-common-datasource
+
+
+
+
+ com.muyu
+ cloud-common-datascope
+
+
+
+
+ com.muyu
+ cloud-common-log
+
+
+
+
+ com.muyu
+ cloud-common-api-doc
+
+
+ com.muyu
+ cloud-common-security
+
+
+
+ com.muyu
+ cloud-common-rabbit
+
+
+
+
+
+
+
+
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+
+
diff --git a/cloud-data-processing/src/main/java/com/muyu/data/processing/MyDataApplication.java b/cloud-data-processing/src/main/java/com/muyu/data/processing/MyDataApplication.java
new file mode 100644
index 0000000..142d45e
--- /dev/null
+++ b/cloud-data-processing/src/main/java/com/muyu/data/processing/MyDataApplication.java
@@ -0,0 +1,27 @@
+package com.muyu.data.processing;
+
+import com.muyu.common.security.annotation.EnableCustomConfig;
+import com.muyu.common.security.annotation.EnableMyFeignClients;
+import org.springframework.amqp.rabbit.annotation.EnableRabbit;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @Author: 胡杨
+ * @Name: MyData
+ * @Description: 数据处理模块启动器
+ * @CreatedDate: 2024/9/26 下午7:31
+ * @FilePath: com.muyu.data.processing
+ */
+
+@EnableCustomConfig
+//@EnableCustomSwagger2
+@EnableMyFeignClients
+@EnableRabbit
+@SpringBootApplication
+public class MyDataApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(MyDataApplication.class, args);
+ System.out.println("MyData 模块启动成功!");
+ }
+}
diff --git a/cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/DownlineRabbit.java b/cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/DownlineRabbit.java
new file mode 100644
index 0000000..7113ae4
--- /dev/null
+++ b/cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/DownlineRabbit.java
@@ -0,0 +1,53 @@
+package com.muyu.data.processing.rebbit;
+
+
+import com.muyu.common.caffeine.CaffeineCacheUtils;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.HashSet;
+
+/**
+ * @Author: 胡杨
+ * @Name: DownlineRabbit
+ * @Description: 车辆下线监听器
+ * @CreatedDate: 2024/9/26 下午8:21
+ * @FilePath: com.muyu.data.processing.rebbit
+ */
+@Slf4j
+@Component
+public class DownlineRabbit {
+ @Resource
+ private CaffeineCacheUtils caffeineCacheUtils;
+
+ private static final HashSet DOWNLINE_SET = new HashSet<>();
+
+ @RabbitListener(queuesToDeclare = {@Queue("Downline")})
+ public void downline(String vin, Message message, Channel channel) {
+ log.info("车辆 {} 下线, 配置信息准备中。。。",vin);
+ try {
+ // 重复性校验
+ if (DOWNLINE_SET.add(message.getMessageProperties().getMessageId())) {
+ caffeineCacheUtils.deleteCarCache(vin);
+ log.info("车辆 {} 下线, 消息已确认。。。",vin);
+ } else {
+ log.info("车辆 {} 下线, 消息重复消费,已确认。。。",vin);
+ }
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+ log.info("车辆 {} 下线, 配置信息已准备完毕。。。",vin);
+ } catch (IOException e) {
+ try {
+ log.warn("车辆 {} 下线, 配置信息准备失败,返回队列,原因:{}", vin, e.getMessage());
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
+ } catch (IOException ex) {
+ log.warn("车辆 {} 下线, 消息返回队列失败,原因:{}", vin, ex.getMessage());
+ }
+ }
+ }
+}
diff --git a/cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/GoOnlineRabbit.java b/cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/GoOnlineRabbit.java
new file mode 100644
index 0000000..b78a6e6
--- /dev/null
+++ b/cloud-data-processing/src/main/java/com/muyu/data/processing/rebbit/GoOnlineRabbit.java
@@ -0,0 +1,54 @@
+package com.muyu.data.processing.rebbit;
+
+
+import com.muyu.common.caffeine.CaffeineCacheUtils;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.HashSet;
+
+/**
+ * @Author: 胡杨
+ * @Name: GoOnlineRabbit
+ * @Description: 上线事件
+ * @CreatedDate: 2024/9/26 下午7:38
+ * @FilePath: com.muyu.data.processing.rebbit
+ */
+@Slf4j
+@Component
+public class GoOnlineRabbit {
+
+ @Resource
+ private CaffeineCacheUtils caffeineCacheUtils;
+
+ private static final HashSet DATA_SET = new HashSet<>();
+
+ @RabbitListener(queuesToDeclare = {@Queue("GoOnline")})
+ public void goOnline(String vin, Message message, Channel channel){
+ log.info("车辆 {} 上线, 配置信息准备中。。。",vin);
+ try {
+ // 重复性校验
+ if (DATA_SET.add(message.getMessageProperties().getMessageId())) {
+ caffeineCacheUtils.addCarCache(vin);
+ log.info("车辆 {} 上线, 消息已确认。。。",vin);
+ } else {
+ log.info("车辆 {} 上线, 消息重复消费,已确认。。。",vin);
+ }
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+ log.info("车辆 {} 上线, 配置信息已准备完毕。。。",vin);
+ } catch (IOException e) {
+ try {
+ log.warn("车辆 {} 上线, 配置信息准备失败,返回队列,原因:{}", vin, e.getMessage());
+ channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
+ } catch (IOException ex) {
+ log.warn("车辆 {} 上线, 消息返回队列失败,原因:{}", vin, ex.getMessage());
+ }
+ }
+ }
+}
diff --git a/cloud-data-processing/src/main/resources/banner.txt b/cloud-data-processing/src/main/resources/banner.txt
new file mode 100644
index 0000000..0dd5eee
--- /dev/null
+++ b/cloud-data-processing/src/main/resources/banner.txt
@@ -0,0 +1,2 @@
+Spring Boot Version: ${spring-boot.version}
+Spring Application Name: ${spring.application.name}
diff --git a/cloud-data-processing/src/main/resources/bootstrap.yml b/cloud-data-processing/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..390055c
--- /dev/null
+++ b/cloud-data-processing/src/main/resources/bootstrap.yml
@@ -0,0 +1,59 @@
+# Tomcat
+server:
+ port: 9701
+
+# nacos线上地址
+nacos:
+ addr: 47.116.173.119:8848
+ user-name: nacos
+ password: nacos
+ namespace: one-saas
+# SPRING_AMQP_DESERIALIZATION_TRUST_ALL=true spring.amqp.deserialization.trust.all
+# Spring
+spring:
+ amqp:
+ deserialization:
+ trust:
+ all: true
+ main:
+ allow-bean-definition-overriding: true
+ application:
+ # 应用名称
+ name: cloud-data-processing
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: ${nacos.addr}
+ # nacos用户名
+ username: ${nacos.user-name}
+ # nacos密码
+ password: ${nacos.password}
+ # 命名空间
+ namespace: ${nacos.namespace}
+ config:
+ # 服务注册地址
+ server-addr: ${nacos.addr}
+ # nacos用户名
+ username: ${nacos.user-name}
+ # nacos密码
+ password: ${nacos.password}
+ # 命名空间
+ namespace: ${nacos.namespace}
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ # 系统共享配置
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+ # 系统环境Config共享配置
+ - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+ # xxl-job 配置文件
+ - application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+
+logging:
+ level:
+ com.muyu.system.mapper: DEBUG
diff --git a/cloud-data-processing/src/main/resources/logback/dev.xml b/cloud-data-processing/src/main/resources/logback/dev.xml
new file mode 100644
index 0000000..8af8bf1
--- /dev/null
+++ b/cloud-data-processing/src/main/resources/logback/dev.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+ ${log.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cloud-data-processing/src/main/resources/logback/prod.xml b/cloud-data-processing/src/main/resources/logback/prod.xml
new file mode 100644
index 0000000..35744e3
--- /dev/null
+++ b/cloud-data-processing/src/main/resources/logback/prod.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cloud-data-processing/src/main/resources/logback/test.xml b/cloud-data-processing/src/main/resources/logback/test.xml
new file mode 100644
index 0000000..35744e3
--- /dev/null
+++ b/cloud-data-processing/src/main/resources/logback/test.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+