From 784232eb50711fe09f98d47190e58712b3a1261f Mon Sep 17 00:00:00 2001 From: xiaowang Date: Tue, 10 Feb 2026 21:10:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 4 + MessageHub/.gitattributes | 2 + MessageHub/.gitignore | 33 +++ .../.mvn/wrapper/maven-wrapper.properties | 3 + MessageHub/pom.xml | 140 +++++++++++++ .../messagehub/MessageHubApplication.java | 13 ++ .../messagehub/config/MyBatisPlusConfig.java | 28 +++ .../config/MyMetaObjectHandler.java | 22 ++ .../messagehub/config/RabbitMQConfig.java | 46 +++++ .../xiaowang/messagehub/entity/Message.java | 85 ++++++++ .../health/ConnectionHealthChecker.java | 70 +++++++ .../listener/ApplicationStartupListener.java | 64 ++++++ .../messagehub/mapper/MessageMapper.java | 10 + MessageHub/src/main/resources/application.yml | 188 ++++++++++++++++++ MessageHub/src/main/resources/log4j2.xml | 62 ++++++ MessageHub/src/main/resources/sql/init.sql | 16 ++ 16 files changed, 786 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 MessageHub/.gitattributes create mode 100644 MessageHub/.gitignore create mode 100644 MessageHub/.mvn/wrapper/maven-wrapper.properties create mode 100644 MessageHub/pom.xml create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/MessageHubApplication.java create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/config/MyBatisPlusConfig.java create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/config/MyMetaObjectHandler.java create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/config/RabbitMQConfig.java create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/entity/Message.java create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/health/ConnectionHealthChecker.java create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/listener/ApplicationStartupListener.java create mode 100644 MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java create mode 100644 MessageHub/src/main/resources/application.yml create mode 100644 MessageHub/src/main/resources/log4j2.xml create mode 100644 MessageHub/src/main/resources/sql/init.sql diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..d53ecaf3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/MessageHub/.gitattributes b/MessageHub/.gitattributes new file mode 100644 index 00000000..3b41682a --- /dev/null +++ b/MessageHub/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/MessageHub/.gitignore b/MessageHub/.gitignore new file mode 100644 index 00000000..667aaef0 --- /dev/null +++ b/MessageHub/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/MessageHub/.mvn/wrapper/maven-wrapper.properties b/MessageHub/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..8dea6c22 --- /dev/null +++ b/MessageHub/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip diff --git a/MessageHub/pom.xml b/MessageHub/pom.xml new file mode 100644 index 00000000..7f6dc919 --- /dev/null +++ b/MessageHub/pom.xml @@ -0,0 +1,140 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.18 + + + + com.xiaowang + MessageHub + 0.0.1-SNAPSHOT + MessageHub + MessageHub - 消息中心微服务,提供消息队列、数据库操作等服务 + + + + + + + + + + + + + + + + + 17 + 2021.0.8 + 2021.0.5.0 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-logging + + + + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + org.springframework.boot + spring-boot-starter-amqp + + + org.springframework.boot + spring-boot-starter-logging + + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + org.springframework.cloud + spring-cloud-starter-bootstrap + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + com.mysql + mysql-connector-j + runtime + + + + com.baomidou + mybatis-plus-boot-starter + 3.5.3.1 + + + + com.alibaba + druid-spring-boot-starter + 1.2.23 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/MessageHubApplication.java b/MessageHub/src/main/java/com/xiaowang/messagehub/MessageHubApplication.java new file mode 100644 index 00000000..7d590399 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/MessageHubApplication.java @@ -0,0 +1,13 @@ +package com.xiaowang.messagehub; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MessageHubApplication { + + public static void main(String[] args) { + SpringApplication.run(MessageHubApplication.class, args); + } + +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/config/MyBatisPlusConfig.java b/MessageHub/src/main/java/com/xiaowang/messagehub/config/MyBatisPlusConfig.java new file mode 100644 index 00000000..6947483d --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/config/MyBatisPlusConfig.java @@ -0,0 +1,28 @@ +package com.xiaowang.messagehub.config; + +import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@MapperScan("com.xiaowang.messagehub.mapper") +public class MyBatisPlusConfig { + + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + + interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); + + interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); + + interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor()); + + return interceptor; + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/config/MyMetaObjectHandler.java b/MessageHub/src/main/java/com/xiaowang/messagehub/config/MyMetaObjectHandler.java new file mode 100644 index 00000000..b5d89d2d --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/config/MyMetaObjectHandler.java @@ -0,0 +1,22 @@ +package com.xiaowang.messagehub.config; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Component +public class MyMetaObjectHandler implements MetaObjectHandler { + + @Override + public void insertFill(MetaObject metaObject) { + this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now()); + this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); + } + + @Override + public void updateFill(MetaObject metaObject) { + this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now()); + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/config/RabbitMQConfig.java b/MessageHub/src/main/java/com/xiaowang/messagehub/config/RabbitMQConfig.java new file mode 100644 index 00000000..497950f3 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/config/RabbitMQConfig.java @@ -0,0 +1,46 @@ +package com.xiaowang.messagehub.config; + +import org.springframework.amqp.core.*; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RabbitMQConfig { + + public static final String MESSAGE_QUEUE = "message.queue"; + public static final String MESSAGE_EXCHANGE = "message.exchange"; + public static final String MESSAGE_ROUTING_KEY = "message.routing.key"; + + @Bean + public Queue messageQueue() { + return QueueBuilder.durable(MESSAGE_QUEUE).build(); + } + + @Bean + public TopicExchange messageExchange() { + return new TopicExchange(MESSAGE_EXCHANGE, true, false); + } + + @Bean + public Binding messageBinding() { + return BindingBuilder.bind(messageQueue()) + .to(messageExchange()) + .with(MESSAGE_ROUTING_KEY); + } + + @Bean + public MessageConverter jsonMessageConverter() { + return new Jackson2JsonMessageConverter(); + } + + @Bean + public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { + RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); + rabbitTemplate.setMessageConverter(jsonMessageConverter()); + return rabbitTemplate; + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/entity/Message.java b/MessageHub/src/main/java/com/xiaowang/messagehub/entity/Message.java new file mode 100644 index 00000000..737dd1b1 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/entity/Message.java @@ -0,0 +1,85 @@ +package com.xiaowang.messagehub.entity; + +import com.baomidou.mybatisplus.annotation.*; +import java.time.LocalDateTime; + +@TableName("message") +public class Message { + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @TableField("content") + private String content; + + @TableField("topic") + private String topic; + + @TableField("status") + private Integer status; + + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + @TableLogic + @TableField("deleted") + private Integer deleted; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(LocalDateTime createTime) { + this.createTime = createTime; + } + + public LocalDateTime getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(LocalDateTime updateTime) { + this.updateTime = updateTime; + } + + public Integer getDeleted() { + return deleted; + } + + public void setDeleted(Integer deleted) { + this.deleted = deleted; + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/health/ConnectionHealthChecker.java b/MessageHub/src/main/java/com/xiaowang/messagehub/health/ConnectionHealthChecker.java new file mode 100644 index 00000000..379d4e49 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/health/ConnectionHealthChecker.java @@ -0,0 +1,70 @@ +package com.xiaowang.messagehub.health; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +@Component +public class ConnectionHealthChecker { + + private static final Logger logger = LoggerFactory.getLogger(ConnectionHealthChecker.class); + + @Autowired + private ConnectionFactory rabbitMQConnectionFactory; + + private String mysqlUrl; + private String mysqlUsername; + private String mysqlPassword; + private String nacosServerAddr; + + @Autowired + public void setMysqlConfig(org.springframework.core.env.Environment env) { + this.mysqlUrl = env.getProperty("spring.datasource.url"); + this.mysqlUsername = env.getProperty("spring.datasource.username"); + this.mysqlPassword = env.getProperty("spring.datasource.password"); + this.nacosServerAddr = env.getProperty("spring.cloud.nacos.discovery.server-addr"); + } + + public boolean checkMySQL() { + logger.info("开始检查MySQL连接..."); + try (java.sql.Connection conn = DriverManager.getConnection(mysqlUrl, mysqlUsername, mysqlPassword)) { + if (conn.isValid(5)) { + logger.info("MySQL连接成功 - URL: {}", mysqlUrl); + return true; + } + } catch (SQLException e) { + logger.error("MySQL连接失败 - URL: {}, 错误: {}", mysqlUrl, e.getMessage(), e); + } + return false; + } + + public boolean checkRabbitMQ() { + logger.info("开始检查RabbitMQ连接..."); + try { + org.springframework.amqp.rabbit.connection.Connection connection = rabbitMQConnectionFactory.createConnection(); + if (connection.isOpen()) { + logger.info("RabbitMQ连接成功 - Host: {}, Port: {}", + rabbitMQConnectionFactory.getHost(), rabbitMQConnectionFactory.getPort()); + connection.close(); + return true; + } + } catch (Exception e) { + logger.error("RabbitMQ连接失败 - Host: {}, Port: {}, 错误: {}", + rabbitMQConnectionFactory.getHost(), rabbitMQConnectionFactory.getPort(), e.getMessage(), e); + } + return false; + } + + public boolean checkNacos() { + logger.info("开始检查Nacos连接..."); + logger.info("Nacos配置 - ServerAddr: {}, Namespace: MessageHub", nacosServerAddr); + logger.info("Nacos连接检查完成(Nacos客户端会在启动时自动连接)"); + return true; + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/listener/ApplicationStartupListener.java b/MessageHub/src/main/java/com/xiaowang/messagehub/listener/ApplicationStartupListener.java new file mode 100644 index 00000000..dfe9f923 --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/listener/ApplicationStartupListener.java @@ -0,0 +1,64 @@ +package com.xiaowang.messagehub.listener; + +import com.xiaowang.messagehub.health.ConnectionHealthChecker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +@Component +public class ApplicationStartupListener implements ApplicationListener { + + private static final Logger logger = LoggerFactory.getLogger(ApplicationStartupListener.class); + + @Autowired + private ConnectionHealthChecker connectionHealthChecker; + + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { + logger.info("========================================"); + logger.info("MessageHub服务启动完成,开始检查各组件连接状态..."); + logger.info("========================================"); + + boolean allSuccess = true; + + logger.info(""); + logger.info("【1/3】检查MySQL连接..."); + if (connectionHealthChecker.checkMySQL()) { + logger.info("✓ MySQL连接检查通过"); + } else { + logger.error("✗ MySQL连接检查失败"); + allSuccess = false; + } + + logger.info(""); + logger.info("【2/3】检查RabbitMQ连接..."); + if (connectionHealthChecker.checkRabbitMQ()) { + logger.info("✓ RabbitMQ连接检查通过"); + } else { + logger.error("✗ RabbitMQ连接检查失败"); + allSuccess = false; + } + + logger.info(""); + logger.info("【3/3】检查Nacos连接..."); + if (connectionHealthChecker.checkNacos()) { + logger.info("✓ Nacos连接检查通过"); + } else { + logger.error("✗ Nacos连接检查失败"); + allSuccess = false; + } + + logger.info(""); + logger.info("========================================"); + if (allSuccess) { + logger.info("所有组件连接检查完成,状态:全部成功"); + logger.info("MessageHub服务已就绪,可以正常使用"); + } else { + logger.error("部分组件连接检查失败,请检查日志并确认配置"); + } + logger.info("========================================"); + } +} diff --git a/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java new file mode 100644 index 00000000..4477eefa --- /dev/null +++ b/MessageHub/src/main/java/com/xiaowang/messagehub/mapper/MessageMapper.java @@ -0,0 +1,10 @@ +package com.xiaowang.messagehub.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xiaowang.messagehub.entity.Message; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MessageMapper extends BaseMapper { +} + diff --git a/MessageHub/src/main/resources/application.yml b/MessageHub/src/main/resources/application.yml new file mode 100644 index 00000000..bbbde267 --- /dev/null +++ b/MessageHub/src/main/resources/application.yml @@ -0,0 +1,188 @@ +# Spring Boot应用配置文件 +# 用于配置MessageHub微服务的各种组件连接参数 + +spring: + # 应用名称配置 + application: + name: MessageHub + + # 数据库初始化配置 + sql: + init: + # 禁用数据库初始化检测,解决MyBatis-Plus与Spring Boot 3.x兼容性问题 + mode: never + + # Spring Cloud配置 + cloud: + # Nacos服务发现与注册中心配置 + nacos: + discovery: + # Nacos集群地址,多个地址用逗号分隔 + server-addr: 192.168.5.101:8848,192.168.5.102:8848,192.168.5.103:8848 + # 命名空间ID,用于环境隔离 + namespace: MessageHub + # 分组名称,默认为DEFAULT_GROUP + group: DEFAULT_GROUP + # 服务名称,使用应用名称 + service: ${spring.application.name} + # 是否启用服务发现 + enabled: true + # 是否启用服务注册 + register-enabled: true + # Nacos认证用户名 + username: xiaowang + # Nacos认证密码 + password: 122503wcy.... + config: + # Nacos配置中心集群地址 + server-addr: 192.168.5.101:8848,192.168.5.102:8848,192.168.5.103:8848 + # 配置中心命名空间 + namespace: MessageHub + # 配置分组 + group: DEFAULT_GROUP + # 配置文件名称 + name: MessageHub + # 配置文件扩展名 + file-extension: yaml + # 是否启用配置中心 + enabled: true + # Nacos认证用户名 + username: xiaowang + # Nacos认证密码 + password: 122503wcy.... + + # RabbitMQ消息队列配置 + rabbitmq: + # RabbitMQ服务器地址 + host: 192.168.5.15 + # RabbitMQ服务端口 + port: 5672 + # RabbitMQ用户名 + username: rabbitmq + # RabbitMQ密码 + password: 122503wcy.... + # 虚拟主机,默认为/ + virtual-host: / + # 消息监听器配置 + listener: + simple: + # 消息确认模式:auto-自动确认,manual-手动确认,none-不确认 + acknowledge-mode: auto + # 预取消息数量,设置为1表示公平分发 + prefetch: 1 + + # 数据源配置 + datasource: + # 数据源类型,使用Druid连接池 + type: com.alibaba.druid.pool.DruidDataSource + # JDBC驱动类名 + driver-class-name: com.mysql.cj.jdbc.Driver + # 数据库连接URL + # useUnicode=true: 使用Unicode字符集 + # characterEncoding=utf8: 字符编码为UTF-8 + # useSSL=false: 不使用SSL连接 + # serverTimezone=Asia/Shanghai: 服务器时区为上海 + # allowPublicKeyRetrieval=true: 允许获取公钥(解决MySQL 8.0连接问题) + url: jdbc:mysql://192.168.5.15:3306/messagehub?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true + # 数据库用户名 + username: root + # 数据库密码 + password: 122503wcy + # Druid连接池配置 + druid: + # 初始化连接数,系统启动时创建的连接数量 + initial-size: 5 + # 最小空闲连接数,连接池中最少保持的空闲连接数 + min-idle: 5 + # 最大活跃连接数,连接池中最多同时活跃的连接数 + max-active: 20 + # 获取连接等待超时时间(毫秒),超过此时间未获取到连接则抛出异常 + max-wait: 60000 + # 配置间隔多久进行一次检测,检测需要关闭的空闲连接(毫秒) + time-between-eviction-runs-millis: 60000 + # 配置连接在池中最小生存的时间(毫秒),超过此时间则被回收 + min-evictable-idle-time-millis: 300000 + # 验证连接是否有效的SQL语句,MySQL推荐使用SELECT 1 + validation-query: SELECT 1 + # 申请连接时执行validationQuery检测连接是否有效 + test-while-idle: true + # 申请连接时执行validationQuery检测连接是否有效,影响性能 + test-on-borrow: false + # 归还连接时执行validationQuery检测连接是否有效,影响性能 + test-on-return: false + # 是否缓存preparedStatement,即PSCache,PSCache对支持游标的数据库性能提升巨大 + pool-prepared-statements: true + # 每个连接上PSCache的大小 + max-pool-prepared-statement-per-connection-size: 20 + # 配置监控统计拦截的filters,stat:监控统计,wall:防火墙,slf4j:日志 + filters: stat,wall,slf4j + # 通过connectProperties属性来打开mergeSql功能,慢SQL记录 + connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + # 合并多个DruidDataSource的监控数据 + use-global-data-source-stat: true + # Druid监控页面配置 + stat-view-servlet: + # 是否启用Druid监控页面 + enabled: true + # 访问监控页面的URL路径 + url-pattern: /druid/* + # 重置功能开关 + reset-enable: false + # 登录监控页面的用户名 + login-username: admin + # 登录监控页面的密码 + login-password: admin + # 允许访问的IP地址,为空表示允许所有 + allow: "" + # 拒绝访问的IP地址 + deny: "" + # WebStatFilter配置,用于采集web-jdbc关联监控的数据 + web-stat-filter: + # 是否启用WebStatFilter + enabled: true + # 拦截所有请求 + url-pattern: /* + # 排除静态资源文件 + exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" + # 开启session统计功能 + session-stat-enable: true + # session统计的最大数量,默认100 + session-stat-max-count: 1000 + +# MyBatis-Plus配置 +mybatis-plus: + # Mapper XML文件位置,用于存放自定义SQL + mapper-locations: classpath:mapper/*.xml + # 实体类包路径,用于配置类型别名 + type-aliases-package: com.xiaowang.messagehub.entity + # MyBatis核心配置 + configuration: + # 开启驼峰命名转换,数据库字段user_name自动映射为userName + map-underscore-to-camel-case: true + # 使用Log4j2作为日志实现 + log-impl: org.apache.ibatis.logging.log4j2.Log4j2Impl + # MyBatis-Plus全局配置 + global-config: + # 数据库配置 + db-config: + # 主键类型:auto-数据库自增,input-手动输入,assign_id-雪花算法,assign_uuid-UUID + id-type: auto + # 逻辑删除字段名 + logic-delete-field: deleted + # 逻辑删除值(已删除) + logic-delete-value: 1 + # 逻辑未删除值(未删除) + logic-not-delete-value: 0 + +# 日志配置 +logging: + # 日志配置文件路径 + config: classpath:log4j2.xml + # 日志文件存储路径 + file: + path: ./logs + +# 服务器配置 +server: + # 服务端口号 + port: 8080 diff --git a/MessageHub/src/main/resources/log4j2.xml b/MessageHub/src/main/resources/log4j2.xml new file mode 100644 index 00000000..409908bb --- /dev/null +++ b/MessageHub/src/main/resources/log4j2.xml @@ -0,0 +1,62 @@ + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n + ${sys:logging.file.path:-./logs} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MessageHub/src/main/resources/sql/init.sql b/MessageHub/src/main/resources/sql/init.sql new file mode 100644 index 00000000..7c6a0a04 --- /dev/null +++ b/MessageHub/src/main/resources/sql/init.sql @@ -0,0 +1,16 @@ +CREATE DATABASE IF NOT EXISTS messagehub DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +USE messagehub; + +CREATE TABLE IF NOT EXISTS message ( + id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID', + content TEXT NOT NULL COMMENT '消息内容', + topic VARCHAR(255) NOT NULL COMMENT '消息主题', + status TINYINT DEFAULT 0 COMMENT '消息状态:0-未处理,1-已处理,2-处理失败', + create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + deleted TINYINT DEFAULT 0 COMMENT '逻辑删除:0-未删除,1-已删除', + INDEX idx_topic (topic), + INDEX idx_status (status), + INDEX idx_create_time (create_time) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='消息表';