commit f16094885f5cb07902f2d8408c434f40f55f8133
Author: 86186 <2002915>
Date: Sun Dec 17 09:14:57 2023 +0800
后端框架
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..bac9fd8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..de4bfbe
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..597c296
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..5a2f139
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..d5cd614
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/bwie-auth/pom.xml b/bwie-auth/pom.xml
new file mode 100644
index 0000000..02f7232
--- /dev/null
+++ b/bwie-auth/pom.xml
@@ -0,0 +1,43 @@
+
+
+
+ bwie-12_16manage
+ com.bwie
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ bwie-auth
+
+
+
+ com.bwie
+ bwie-common
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-xml
+
+
+
+
+ org.springframework.kafka
+ spring-kafka
+
+
+
+
\ No newline at end of file
diff --git a/bwie-auth/src/main/java/com/bwie/auth/AuthApplication.java b/bwie-auth/src/main/java/com/bwie/auth/AuthApplication.java
new file mode 100644
index 0000000..c43cad0
--- /dev/null
+++ b/bwie-auth/src/main/java/com/bwie/auth/AuthApplication.java
@@ -0,0 +1,17 @@
+package com.bwie.auth;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * @ClassName AuthApplication
+ * @Description 描述
+ * @Author LiAng.xiAo
+ * @Date 2023/12/17 9:04
+ */
+@SpringBootApplication
+public class AuthApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(AuthApplication.class);
+ }
+}
diff --git a/bwie-auth/src/main/java/com/bwie/auth/config/ConfirmCallbackConfig.java b/bwie-auth/src/main/java/com/bwie/auth/config/ConfirmCallbackConfig.java
new file mode 100644
index 0000000..6cbc083
--- /dev/null
+++ b/bwie-auth/src/main/java/com/bwie/auth/config/ConfirmCallbackConfig.java
@@ -0,0 +1,48 @@
+package com.bwie.auth.config;
+
+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
+public class ConfirmCallbackConfig implements RabbitTemplate.ConfirmCallback {
+
+ @Autowired
+ private RabbitTemplate rabbitTemplate;
+
+ /**
+ * @PostContruct是spring框架的注解,在⽅法上加该注解会在项⽬启动的时候执⾏该⽅法,也可以理解为在spring容器初始化的时候执
+ * @PostConstruct bean 被初始化的时候执行的方法的注解
+ * @PreDestory bean 被销毁的时候执行的方法的注解
+ */
+ @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) {
+ // 消息投递到 broker 的状态,true表示成功
+ System.out.println("消息发送成功!");
+ } else {
+ // 发送异常
+ System.out.println("发送异常原因 = " + cause);
+ // TODO 可以将消息 内容 以及 失败的原因 记录到 日志表中
+ }
+ }
+
+}
diff --git a/bwie-auth/src/main/java/com/bwie/auth/config/KafkaConsumerConfig.java b/bwie-auth/src/main/java/com/bwie/auth/config/KafkaConsumerConfig.java
new file mode 100644
index 0000000..5dced0e
--- /dev/null
+++ b/bwie-auth/src/main/java/com/bwie/auth/config/KafkaConsumerConfig.java
@@ -0,0 +1,103 @@
+package com.bwie.auth.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
+ * kafka配置,也可以写在yml,这个文件会覆盖yml
+ */
+@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 consumerConfigs() {
+
+ Map 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