作者 王勇

拆分服务--接收消息服务

正在显示 48 个修改的文件 包含 4709 行增加0 行删除

要显示太多修改。

为保证性能只显示 48 of 48+ 个文件。

  1 +HELP.md
  2 +target/
  3 +!.mvn/wrapper/maven-wrapper.jar
  4 +!**/src/main/**/target/
  5 +!**/src/test/**/target/
  6 +
  7 +### STS ###
  8 +.apt_generated
  9 +.classpath
  10 +.factorypath
  11 +.project
  12 +.settings
  13 +.springBeans
  14 +.sts4-cache
  15 +
  16 +### IntelliJ IDEA ###
  17 +.idea
  18 +*.iws
  19 +*.iml
  20 +*.ipr
  21 +
  22 +### NetBeans ###
  23 +/nbproject/private/
  24 +/nbbuild/
  25 +/dist/
  26 +/nbdist/
  27 +/.nb-gradle/
  28 +build/
  29 +!**/src/main/**/build/
  30 +!**/src/test/**/build/
  31 +
  32 +### VS Code ###
  33 +.vscode/
  1 +server:
  2 + port: 9032
  3 +
  4 +# spring 配置
  5 +spring:
  6 + security:
  7 + user:
  8 + name: admin
  9 + password: 123456
  10 +
  11 + application:
  12 + name: message-bus-receive
  13 +
  14 + # 数据源配置
  15 + datasource:
  16 + type: com.alibaba.druid.pool.DruidDataSource
  17 + driver-class-name: com.mysql.cj.jdbc.Driver
  18 + url: jdbc:mysql://118.31.66.166:3306/bus_service?characterEncoding=utf8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
  19 + username: 110
  20 + password: QAHqCJf2kFYCLirM
  21 +
  22 + # redis设置
  23 + redis:
  24 + database: 0 # Redis 数据库索引(默认为 0)
  25 + host: 192.168.37.139 # Redis 服务器地址
  26 + port: 6379 # Redis 服务器连接端口
  27 + password: 123456 # Redis 服务器连接密码(默认为空)
  28 + lettuce:
  29 + pool:
  30 + max-active: 8 # 连接池最大连接数(使用负值表示没有限制) 默认 8
  31 + max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1
  32 + max-idle: 8 # 连接池中的最大空闲连接 默认 8
  33 + min-idle: 0 # 连接池中的最小空闲连接 默认 0
  34 +
  35 + # rabbitmq配置
  36 + rabbitmq:
  37 + host: 192.168.37.139
  38 + port: 5672
  39 + username: rabbit
  40 + password: 123456
  41 + virtual-host: /
  42 +
  43 + # 多环境配置
  44 + profiles:
  45 + active: dev
  46 +
  47 + # Jackson配置
  48 + jackson:
  49 + default-property-inclusion: ALWAYS
  50 + time-zone: GMT+8
  51 + date-format: yyyy-MM-dd HH:mm:ss
  52 +
  53 + # zipkin 链路追踪配置
  54 + zipkin:
  55 + base-url: http://192.168.1.63:9411
  56 + sleuth:
  57 + sampler:
  58 + probability: 1
  59 +
  60 +# mybatis 配置
  61 +mybatis:
  62 + mapper-locations: classpath:mapper/*.xml
  63 + type-aliases-package: com.sunyo.wlpt.message.bus.service.domain
  64 +
  65 +# 日志配置
  66 +logging:
  67 + config: config/logback-dev.xml
  68 + level:
  69 + com.sunyo.wlpt.message.bus.service.mapper: debug
  70 +logback:
  71 + appname: message-bus-service
  72 + logdir: ./log
  73 +
  74 +#eureka 配置
  75 +eureka:
  76 + instance:
  77 + status-page-url: http://${eureka.instance.hostname}:${server.port}/index
  78 + prefer-ip-address: true
  79 + instance-id: ${spring.cloud.client.ip-address}:${server.port}
  80 + hostname: ${spring.cloud.client.ip-address}
  81 + metadata-map:
  82 + user:
  83 + name: "admin"
  84 + password: "123456"
  85 +
  86 + client:
  87 + healthcheck:
  88 + enabled: true
  89 + service-url:
  90 + defaultZone: http://192.168.1.53:12345/eureka/
  91 +
  92 +# boot admin
  93 +management:
  94 + endpoints:
  95 + enabled-by-default: true
  96 + web:
  97 + exposure:
  98 + include: "*"
  99 + endpoint:
  100 + health:
  101 + show-details: always
  102 + shutdown:
  103 + enabled: true
  104 +
  105 +# 基础信息配置
  106 +info:
  107 + version: 1.0
  108 + description: "消息总线平台——发送消息服务"
  109 +
  1 +# 解决eureka的多网卡配置问题,指定网卡的IP地址的前缀
  2 +spring:
  3 + cloud:
  4 + inetutils:
  5 + preferred-networks: 192.168.1.
  6 +eureka:
  7 + instance:
  8 + prefer-ip-address: true
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!--参考文档链接:https://blog.csdn.net/qq_34912478/article/details/80877132-->
  3 +<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
  4 +<!-- scan:当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true -->
  5 +<!-- scanPeriod:设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。 -->
  6 +<!-- debug:当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。默认值为false。 -->
  7 +<configuration scan="true" scanPeriod="10 seconds">
  8 +
  9 + <!--<include resource="org/springframework/boot/logging/logback/base.xml" />-->
  10 +
  11 + <contextName>logback</contextName>
  12 + <!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
  13 + <property name="log.path" value="./logs" />
  14 +
  15 + <!-- 彩色日志 -->
  16 + <!-- 彩色日志依赖的渲染类 -->
  17 + <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
  18 + <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
  19 + <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
  20 + <!-- 彩色日志格式 -->
  21 + <property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
  22 +
  23 +
  24 + <!--输出到控制台-->
  25 + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
  26 + <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
  27 + <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
  28 + <level>debug</level>
  29 + </filter>
  30 + <encoder>
  31 + <Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
  32 + <!-- 设置字符集 windows系统这里设置成GBK-->
  33 + <charset>UTF-8</charset>
  34 + </encoder>
  35 + </appender>
  36 +
  37 +
  38 + <!--输出到文件-->
  39 +
  40 + <!-- 时间滚动输出 level为 DEBUG 日志 -->
  41 + <appender name="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  42 + <!-- 正在记录的日志文件的路径及文件名 -->
  43 + <file>${log.path}/log_debug.log</file>
  44 + <!--日志文件输出格式-->
  45 + <encoder>
  46 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
  47 + <charset>UTF-8</charset> <!-- 设置字符集 -->
  48 + </encoder>
  49 + <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
  50 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  51 + <!-- 日志归档 -->
  52 + <fileNamePattern>${log.path}/debug/log-debug-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  53 + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  54 + <maxFileSize>100MB</maxFileSize>
  55 + </timeBasedFileNamingAndTriggeringPolicy>
  56 + <!--日志文件保留天数-->
  57 + <maxHistory>15</maxHistory>
  58 + </rollingPolicy>
  59 + <!-- 此日志文件只记录debug级别的 -->
  60 + <filter class="ch.qos.logback.classic.filter.LevelFilter">
  61 + <level>debug</level>
  62 + <onMatch>ACCEPT</onMatch>
  63 + <onMismatch>DENY</onMismatch>
  64 + </filter>
  65 + </appender>
  66 +
  67 + <!-- 时间滚动输出 level为 INFO 日志 -->
  68 + <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  69 + <!-- 正在记录的日志文件的路径及文件名 -->
  70 + <file>${log.path}/log_info.log</file>
  71 + <!--日志文件输出格式-->
  72 + <encoder>
  73 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
  74 + <charset>UTF-8</charset>
  75 + </encoder>
  76 + <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
  77 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  78 + <!-- 每天日志归档路径以及格式 -->
  79 + <fileNamePattern>${log.path}/info/log-info-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  80 + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  81 + <maxFileSize>100MB</maxFileSize>
  82 + </timeBasedFileNamingAndTriggeringPolicy>
  83 + <!--日志文件保留天数-->
  84 + <maxHistory>15</maxHistory>
  85 + </rollingPolicy>
  86 + <!-- 此日志文件只记录info级别的 -->
  87 + <filter class="ch.qos.logback.classic.filter.LevelFilter">
  88 + <level>info</level>
  89 + <onMatch>ACCEPT</onMatch>
  90 + <onMismatch>DENY</onMismatch>
  91 + </filter>
  92 + </appender>
  93 +
  94 + <!-- 时间滚动输出 level为 WARN 日志 -->
  95 + <appender name="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  96 + <!-- 正在记录的日志文件的路径及文件名 -->
  97 + <file>${log.path}/log_warn.log</file>
  98 + <!--日志文件输出格式-->
  99 + <encoder>
  100 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
  101 + <charset>UTF-8</charset> <!-- 此处设置字符集 -->
  102 + </encoder>
  103 + <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
  104 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  105 + <fileNamePattern>${log.path}/warn/log-warn-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  106 + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  107 + <maxFileSize>100MB</maxFileSize>
  108 + </timeBasedFileNamingAndTriggeringPolicy>
  109 + <!--日志文件保留天数-->
  110 + <maxHistory>15</maxHistory>
  111 + </rollingPolicy>
  112 + <!-- 此日志文件只记录warn级别的 -->
  113 + <filter class="ch.qos.logback.classic.filter.LevelFilter">
  114 + <level>warn</level>
  115 + <onMatch>ACCEPT</onMatch>
  116 + <onMismatch>DENY</onMismatch>
  117 + </filter>
  118 + </appender>
  119 +
  120 +
  121 + <!-- 时间滚动输出 level为 ERROR 日志 -->
  122 + <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  123 + <!-- 正在记录的日志文件的路径及文件名 -->
  124 + <file>${log.path}/log_error.log</file>
  125 + <!--日志文件输出格式-->
  126 + <encoder>
  127 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
  128 + <charset>UTF-8</charset> <!-- 此处设置字符集 -->
  129 + </encoder>
  130 + <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
  131 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  132 + <fileNamePattern>${log.path}/error/log-error-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  133 + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  134 + <maxFileSize>100MB</maxFileSize>
  135 + </timeBasedFileNamingAndTriggeringPolicy>
  136 + <!--日志文件保留天数-->
  137 + <maxHistory>15</maxHistory>
  138 + </rollingPolicy>
  139 + <!-- 此日志文件只记录ERROR级别的 -->
  140 + <filter class="ch.qos.logback.classic.filter.LevelFilter">
  141 + <level>ERROR</level>
  142 + <onMatch>ACCEPT</onMatch>
  143 + <onMismatch>DENY</onMismatch>
  144 + </filter>
  145 + </appender>
  146 +
  147 + <!-- 时间滚动输出 level为 trace 日志 -->
  148 + <appender name="TRACE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  149 + <!-- 正在记录的日志文件的路径及文件名 -->
  150 + <file>${log.path}/log_trace.log</file>
  151 + <!--日志文件输出格式-->
  152 + <encoder>
  153 + <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
  154 + <charset>UTF-8</charset> <!-- 此处设置字符集 -->
  155 + </encoder>
  156 + <!-- 日志记录器的滚动策略,按日期,按大小记录 -->
  157 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  158 + <fileNamePattern>${log.path}/trace/log-trace-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
  159 + <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
  160 + <maxFileSize>100MB</maxFileSize>
  161 + </timeBasedFileNamingAndTriggeringPolicy>
  162 + <!--日志文件保留天数-->
  163 + <maxHistory>15</maxHistory>
  164 + </rollingPolicy>
  165 + <!-- 此日志文件只记录trace级别的 -->
  166 + <filter class="ch.qos.logback.classic.filter.LevelFilter">
  167 + <level>TRACE</level>
  168 + <onMatch>ACCEPT</onMatch>
  169 + <onMismatch>DENY</onMismatch>
  170 + </filter>
  171 + </appender>
  172 +
  173 +
  174 + <!--
  175 + <logger>用来设置某一个包或者具体的某一个类的日志打印级别、
  176 + 以及指定<appender>。<logger>仅有一个name属性,
  177 + 一个可选的level和一个可选的addtivity属性。
  178 + name:用来指定受此logger约束的某一个包或者具体的某一个类。
  179 + level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
  180 + 还有一个特俗值INHERITED或者同义词NULL,代表强制执行上级的级别。
  181 + 如果未设置此属性,那么当前logger将会继承上级的级别。
  182 + addtivity:是否向上级logger传递打印信息。默认是true。
  183 + -->
  184 + <!--<logger name="org.springframework.web" level="info"/>-->
  185 + <!--<logger name="org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor" level="INFO"/>-->
  186 + <!--
  187 + 使用mybatis的时候,sql语句是debug下才会打印,而这里我们只配置了info,所以想要查看sql语句的话,有以下两种操作:
  188 + 第一种把<root level="info">改成<root level="DEBUG">这样就会打印sql,不过这样日志那边会出现很多其他消息
  189 + 第二种就是单独给dao下目录配置debug模式,代码如下,这样配置sql语句会打印,其他还是正常info级别:
  190 + -->
  191 +
  192 +
  193 + <!--
  194 + root节点是必选节点,用来指定最基础的日志输出级别,只有一个level属性
  195 + level:用来设置打印级别,大小写无关:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF,
  196 + 不能设置为INHERITED或者同义词NULL。默认是DEBUG
  197 + 可以包含零个或多个元素,标识这个appender将会添加到这个logger。
  198 + -->
  199 + <!--<logger name="com.tianbo.analysis" level="trace">-->
  200 + <!--<appender-ref ref="CONSOLE" />-->
  201 + <!--<appender-ref ref="TRACE_FILE" />-->
  202 + <!--<appender-ref ref="DEBUG_FILE" />-->
  203 + <!--<appender-ref ref="INFO_FILE" />-->
  204 + <!--<appender-ref ref="WARN_FILE" />-->
  205 + <!--<appender-ref ref="ERROR_FILE" />-->
  206 + <!--</logger>-->
  207 +
  208 + <!--开发环境:打印控制台-->
  209 + <springProfile name="dev">
  210 + <logger name="org.springframework" level="info"/>
  211 + <logger name="com.sunyo.wlpt.nmms.mapper" level="debug">
  212 + <appender-ref ref="CONSOLE" />
  213 + <appender-ref ref="DEBUG_FILE" />
  214 + </logger>
  215 + <logger name="org.apache.tomcat" level="info" />
  216 + <root level="info">
  217 + <appender-ref ref="CONSOLE" />
  218 + <appender-ref ref="TRACE_FILE" />
  219 + <appender-ref ref="DEBUG_FILE" />
  220 + <appender-ref ref="INFO_FILE" />
  221 + <appender-ref ref="WARN_FILE" />
  222 + <appender-ref ref="ERROR_FILE" />
  223 + </root>
  224 + </springProfile>
  225 +
  226 + <!--生产环境:输出到文件-->
  227 + <springProfile name="pro">
  228 + <logger name="org.springframework" level="INFO"/>
  229 + <root level="info">
  230 + <appender-ref ref="CONSOLE" />
  231 + <appender-ref ref="DEBUG_FILE" />
  232 + <appender-ref ref="INFO_FILE" />
  233 + <appender-ref ref="ERROR_FILE" />
  234 + <appender-ref ref="WARN_FILE" />
  235 + <appender-ref ref="TRACE_FILE" />
  236 + </root>
  237 + </springProfile>
  238 +
  239 +</configuration>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<configuration scan="ture" scanPeriod="60 seconds" debug="false">
  3 +
  4 + <springProperty scope="context" name="appname" source="logback.appname"/>
  5 + <springProperty scope="context" name="logdir" source="logback.logdir"/>
  6 + <!--文件名-->
  7 + <contextName>${appname}</contextName>
  8 +
  9 + <!--输出到控制面板-->
  10 + <appender name="consoleLog1" class="ch.qos.logback.core.ConsoleAppender">
  11 + <!-- layout输出方式输出-->
  12 + <layout class="ch.qos.logback.classic.PatternLayout">
  13 + <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
  14 + </layout>
  15 + </appender>
  16 + <!--输出到控制面板-->
  17 + <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
  18 + <encoder>
  19 + <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
  20 + </encoder>
  21 + </appender>
  22 + <!--输出info级别日志-->
  23 + <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
  24 + <filter class="ch.qos.logback.classic.filter.LevelFilter">
  25 + <!--过滤 Error-->
  26 + <level>ERROR</level>
  27 + <!--匹配到就禁止-->
  28 + <onMatch>DENY</onMatch>
  29 + <!--没有匹配到就允许-->
  30 + <onMismatch>ACCEPT</onMismatch>
  31 + </filter>
  32 + <!--<File>../logs</File>-->
  33 + <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  34 + <FileNamePattern>${logdir}/info.${appname}.%d{yyyy-MM-dd}.log</FileNamePattern>
  35 + <maxHistory>100</maxHistory>
  36 + <totalSizeCap>100MB</totalSizeCap>
  37 + </rollingPolicy>
  38 + <encoder>
  39 + <charset>UTF-8</charset>
  40 + <pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>
  41 + </encoder>
  42 + </appender>
  43 + <!--输出Error级别日志-->
  44 + <!--<appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
  45 + <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">-->
  46 + <!--&lt;!&ndash;过滤 Error &ndash;&gt;-->
  47 + <!--<level>ERROR</level>-->
  48 + <!--</filter>-->
  49 + <!--&lt;!&ndash;<File>../logs</File>&ndash;&gt;-->
  50 + <!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
  51 + <!--<FileNamePattern>${logdir}/error.${appname}.%d{yyyy-MM-dd}.log</FileNamePattern>-->
  52 + <!--<maxHistory>100</maxHistory>-->
  53 + <!--<totalSizeCap>100MB</totalSizeCap>-->
  54 + <!--</rollingPolicy>-->
  55 + <!--<encoder>-->
  56 + <!--<charset>UTF-8</charset>-->
  57 + <!--<pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>-->
  58 + <!--</encoder>-->
  59 + <!--</appender>-->
  60 + <!--监控下列类的所有日志,定义输出级别-->
  61 + <logger name="java.sql.PreparedStatement" level="DEBUG" additivity="false">
  62 + <appender-ref ref="consoleLog"/>
  63 + </logger>    
  64 + <logger name="java.sql.Connection" level="DEBUG" additivity="false"> 
  65 + <appender-ref ref="consoleLog"/>
  66 + </logger>  
  67 + <logger name="java.sql.Statement" level="DEBUG" additivity="false">
  68 + <appender-ref ref="consoleLog"/>
  69 + </logger>    
  70 + <logger name="com.ibatis" level="DEBUG" additivity="false">
  71 + <appender-ref ref="consoleLog"/>
  72 + </logger>    
  73 + <logger name="com.ibatis.common.jdbc.SimpleDataSource" level="DEBUG" additivity="false">
  74 + <appender-ref ref="consoleLog"/>
  75 + </logger>    
  76 + <logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG" additivity="false">
  77 + <appender-ref ref="consoleLog"/>
  78 + </logger>    
  79 + <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" additivity="false">
  80 + <appender-ref ref="consoleLog"/>
  81 + </logger> 
  82 + <!--输出-->
  83 + <root level="INFO">
  84 + <appender-ref ref="consoleLog"/>
  85 + <!--<appender-ref ref="consoleLog"/>-->
  86 + <appender-ref ref="fileInfoLog"/>
  87 + <!--<appender-ref ref="fileErrorLog"/>-->
  88 + </root>
  89 +
  90 +</configuration>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4 + <modelVersion>4.0.0</modelVersion>
  5 + <parent>
  6 + <groupId>org.springframework.boot</groupId>
  7 + <artifactId>spring-boot-starter-parent</artifactId>
  8 + <version>2.2.5.RELEASE</version>
  9 + <relativePath/> <!-- lookup parent from repository -->
  10 + </parent>
  11 + <groupId>com.sunyo.wlpt.message.bus.service</groupId>
  12 + <artifactId>message_bus_receive</artifactId>
  13 + <version>1.0.0</version>
  14 + <name>message_bus_receive</name>
  15 + <description>消息总线平台——接收消息服务</description>
  16 +
  17 + <properties>
  18 + <java.version>1.8</java.version>
  19 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  20 + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  21 + <spring-cloud.version>Hoxton.RELEASE</spring-cloud.version>
  22 + <!-- springboot 2.2.1默认的es版本是6.8.4,下面的es的版本要和ES的版本一致 -->
  23 + <elasticsearch.version>7.4.0</elasticsearch.version>
  24 + </properties>
  25 +
  26 + <dependencies>
  27 + <!-- SpringBoot start -->
  28 + <dependency>
  29 + <groupId>org.springframework.boot</groupId>
  30 + <artifactId>spring-boot-starter-web</artifactId>
  31 + </dependency>
  32 +
  33 + <dependency>
  34 + <groupId>org.springframework.boot</groupId>
  35 + <artifactId>spring-boot-starter</artifactId>
  36 + </dependency>
  37 +
  38 + <dependency>
  39 + <groupId>org.springframework.boot</groupId>
  40 + <artifactId>spring-boot-starter-security</artifactId>
  41 + </dependency>
  42 +
  43 + <dependency>
  44 + <groupId>org.springframework.boot</groupId>
  45 + <artifactId>spring-boot-starter-amqp</artifactId>
  46 + </dependency>
  47 +
  48 + <dependency>
  49 + <groupId>org.apache.httpcomponents</groupId>
  50 + <artifactId>httpclient</artifactId>
  51 + </dependency>
  52 +
  53 + <dependency>
  54 + <groupId>com.rabbitmq</groupId>
  55 + <artifactId>http-client</artifactId>
  56 + <version>3.7.0.RELEASE</version>
  57 + </dependency>
  58 +
  59 + <dependency>
  60 + <groupId>org.springframework.boot</groupId>
  61 + <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
  62 + </dependency>
  63 + <!-- SpringBoot end -->
  64 +
  65 + <!-- SpringCloud start -->
  66 + <dependency>
  67 + <groupId>org.springframework.cloud</groupId>
  68 + <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  69 + </dependency>
  70 +
  71 + <dependency>
  72 + <groupId>org.springframework.cloud</groupId>
  73 + <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
  74 + </dependency>
  75 +
  76 + <dependency>
  77 + <groupId>org.springframework.cloud</groupId>
  78 + <artifactId>spring-cloud-starter-openfeign</artifactId>
  79 + </dependency>
  80 +
  81 + <dependency>
  82 + <groupId>org.springframework.cloud</groupId>
  83 + <artifactId>spring-cloud-starter-zipkin</artifactId>
  84 + </dependency>
  85 +
  86 + <dependency>
  87 + <groupId>de.codecentric</groupId>
  88 + <artifactId>spring-boot-admin-starter-client</artifactId>
  89 + <version>2.2.0</version>
  90 + </dependency>
  91 +
  92 + <dependency>
  93 + <groupId>org.springframework.boot</groupId>
  94 + <artifactId>spring-boot-starter-actuator</artifactId>
  95 + </dependency>
  96 + <!-- SpringCloud end -->
  97 + <!-- database start -->
  98 + <dependency>
  99 + <groupId>org.springframework.boot</groupId>
  100 + <artifactId>spring-boot-starter-data-redis</artifactId>
  101 + </dependency>
  102 +
  103 + <dependency>
  104 + <groupId>org.mybatis.spring.boot</groupId>
  105 + <artifactId>mybatis-spring-boot-starter</artifactId>
  106 + <version>2.1.1</version>
  107 + </dependency>
  108 +
  109 + <dependency>
  110 + <groupId>mysql</groupId>
  111 + <artifactId>mysql-connector-java</artifactId>
  112 + <scope>runtime</scope>
  113 + </dependency>
  114 +
  115 + <dependency>
  116 + <groupId>com.github.pagehelper</groupId>
  117 + <artifactId>pagehelper-spring-boot-starter</artifactId>
  118 + <version>1.2.12</version>
  119 + </dependency>
  120 +
  121 + <dependency>
  122 + <groupId>com.alibaba</groupId>
  123 + <artifactId>druid-spring-boot-starter</artifactId>
  124 + <version>1.1.9</version>
  125 + </dependency>
  126 + <!-- database end -->
  127 + <!-- tools start -->
  128 + <dependency>
  129 + <groupId>org.projectlombok</groupId>
  130 + <artifactId>lombok</artifactId>
  131 + <optional>true</optional>
  132 + </dependency>
  133 +
  134 + <dependency>
  135 + <groupId>com.alibaba</groupId>
  136 + <artifactId>fastjson</artifactId>
  137 + <version>1.2.73</version>
  138 + </dependency>
  139 +
  140 + <dependency>
  141 + <groupId>log4j</groupId>
  142 + <artifactId>log4j</artifactId>
  143 + <version>1.2.17</version>
  144 + </dependency>
  145 +
  146 + <dependency>
  147 + <groupId>io.springfox</groupId>
  148 + <artifactId>springfox-swagger2</artifactId>
  149 + <version>2.9.2</version>
  150 + </dependency>
  151 + <dependency>
  152 + <groupId>com.github.xiaoymin</groupId>
  153 + <artifactId>swagger-bootstrap-ui</artifactId>
  154 + <version>1.9.6</version>
  155 + </dependency>
  156 + <dependency>
  157 + <groupId>joda-time</groupId>
  158 + <artifactId>joda-time</artifactId>
  159 + <version>2.10.5</version>
  160 + </dependency>
  161 +
  162 + <dependency>
  163 + <groupId>org.apache.commons</groupId>
  164 + <artifactId>commons-lang3</artifactId>
  165 + <version>3.9</version>
  166 + </dependency>
  167 +
  168 + <dependency>
  169 + <groupId>org.apache.commons</groupId>
  170 + <artifactId>commons-pool2</artifactId>
  171 + </dependency>
  172 +
  173 + <!-- dom4j解析xml -->
  174 + <dependency>
  175 + <groupId>dom4j</groupId>
  176 + <artifactId>dom4j</artifactId>
  177 + <version>1.6.1</version>
  178 + </dependency>
  179 +
  180 + <dependency>
  181 + <groupId>org.springframework.boot</groupId>
  182 + <artifactId>spring-boot-starter-test</artifactId>
  183 + <scope>test</scope>
  184 + </dependency>
  185 + <!-- tools end -->
  186 + </dependencies>
  187 +
  188 + <dependencyManagement>
  189 + <dependencies>
  190 +<!-- <dependency>-->
  191 + <!-- <groupId>org.springframework.boot</groupId>-->
  192 + <!-- <artifactId>spring-boot-dependencies</artifactId>-->
  193 + <!-- <version>${spring-boot.version}</version>-->
  194 + <!-- <type>pom</type>-->
  195 + <!-- <scope>import</scope>-->
  196 + <!-- </dependency>-->
  197 + <dependency>
  198 + <groupId>org.springframework.cloud</groupId>
  199 + <artifactId>spring-cloud-dependencies</artifactId>
  200 + <version>${spring-cloud.version}</version>
  201 + <type>pom</type>
  202 + <scope>import</scope>
  203 + </dependency>
  204 + </dependencies>
  205 + </dependencyManagement>
  206 +
  207 + <build>
  208 + <plugins>
  209 + <plugin>
  210 + <groupId>org.apache.maven.plugins</groupId>
  211 + <artifactId>maven-compiler-plugin</artifactId>
  212 + <configuration>
  213 + <source>1.8</source>
  214 + <target>1.8</target>
  215 + <encoding>UTF-8</encoding>
  216 + </configuration>
  217 + </plugin>
  218 + <plugin>
  219 + <groupId>org.springframework.boot</groupId>
  220 + <artifactId>spring-boot-maven-plugin</artifactId>
  221 + </plugin>
  222 + </plugins>
  223 + </build>
  224 + <repositories>
  225 + <repository>
  226 + <id>spring-milestone</id>
  227 + <name>Spring Milestone</name>
  228 + <url>https://repo.spring.io/milestone</url>
  229 + <snapshots>
  230 + <enabled>false</enabled>
  231 + </snapshots>
  232 + </repository>
  233 + <repository>
  234 + <id>spring-snapshot</id>
  235 + <name>Spring Snapshot</name>
  236 + <url>https://repo.spring.io/snapshot</url>
  237 + <snapshots>
  238 + <enabled>true</enabled>
  239 + </snapshots>
  240 + </repository>
  241 + </repositories>
  242 +
  243 + <pluginRepositories>
  244 + <pluginRepository>
  245 + <id>spring-milestone</id>
  246 + <name>Spring Milestone</name>
  247 + <url>https://repo.spring.io/milestone</url>
  248 + <snapshots>
  249 + <enabled>false</enabled>
  250 + </snapshots>
  251 + </pluginRepository>
  252 +
  253 + <pluginRepository>
  254 + <id>spring-snapshot</id>
  255 + <name>Spring Snapshot</name>
  256 + <url>https://repo.spring.io/snapshot</url>
  257 + <snapshots>
  258 + <enabled>true</enabled>
  259 + </snapshots>
  260 + </pluginRepository>
  261 + </pluginRepositories>
  262 +</project>
  1 +package com.sunyo.wlpt.message.bus.service;
  2 +
  3 +import org.mybatis.spring.annotation.MapperScan;
  4 +import org.springframework.boot.SpringApplication;
  5 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  6 +import org.springframework.cache.annotation.EnableCaching;
  7 +import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
  8 +import org.springframework.cloud.openfeign.EnableFeignClients;
  9 +import org.springframework.scheduling.annotation.EnableAsync;
  10 +import org.springframework.scheduling.annotation.EnableScheduling;
  11 +import org.springframework.transaction.annotation.EnableTransactionManagement;
  12 +
  13 +/**
  14 + * @author 子诚
  15 + */
  16 +@EnableCaching
  17 +@SpringBootApplication
  18 +@MapperScan("com.sunyo.wlpt.message.bus.service.mapper")
  19 +@EnableFeignClients
  20 +@EnableEurekaClient
  21 +@EnableTransactionManagement
  22 +@EnableScheduling
  23 +@EnableAsync
  24 +public class MessageBusReceiveApplication {
  25 +
  26 + public static void main(String[] args)
  27 + {
  28 + SpringApplication.run(MessageBusReceiveApplication.class, args);
  29 + }
  30 +
  31 +}
  1 +package com.sunyo.wlpt.message.bus.service.cache;
  2 +
  3 +import org.springframework.beans.BeansException;
  4 +import org.springframework.context.ApplicationContext;
  5 +import org.springframework.context.ApplicationContextAware;
  6 +import org.springframework.stereotype.Component;
  7 +
  8 +/**
  9 + * @author 子诚
  10 + * Description:用来获取springboot创建好的工厂
  11 + * 时间:2020/8/6 9:31
  12 + */
  13 +@Component
  14 +public class ApplicationContextUtils implements ApplicationContextAware {
  15 +
  16 + /**
  17 + * 保留下来工厂
  18 + */
  19 + private static ApplicationContext context;
  20 +
  21 + /**
  22 + * 将创建好工厂以参数形式传递给这个类
  23 + *
  24 + * @param applicationContext 上下文
  25 + * @throws BeansException
  26 + */
  27 + @Override
  28 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
  29 + {
  30 + context = applicationContext;
  31 + }
  32 +
  33 + /**
  34 + * 提供在工厂中获取对象的方法 例如:RedisTemplate redisTemplate
  35 + *
  36 + * @param beanName bean的名称
  37 + * @return
  38 + */
  39 + public static Object getBean(String beanName)
  40 + {
  41 + return context.getBean(beanName);
  42 + }
  43 +
  44 +}
  45 +
  46 +
  1 +package com.sunyo.wlpt.message.bus.service.cache;
  2 +
  3 +import org.apache.ibatis.cache.Cache;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import org.springframework.data.redis.core.RedisTemplate;
  7 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  8 +import org.springframework.util.DigestUtils;
  9 +
  10 +import java.util.concurrent.TimeUnit;
  11 +import java.util.concurrent.locks.ReadWriteLock;
  12 +import java.util.concurrent.locks.ReentrantReadWriteLock;
  13 +
  14 +
  15 +/**
  16 + * @author 子诚
  17 + * Description:自定义Redis作为mybatis二级缓存实现
  18 + * 问题描述:缓存穿透、缓存雪崩
  19 + * <p>
  20 + * 缓存穿透:就是说利用一些列措施,使得访问避开了缓存,直接访问数据库,使得数据库不堪重负引起的问题。比如(压测)访问数据库中不存在的数据
  21 + * 解决方案:读取数据库,不存在;依旧生成对应的key,放到缓存中,但是对应的value是null(mybatis的二级缓存是这样解决的)。
  22 + * 下次再次访问的话,就是读取缓存。
  23 + * <p>
  24 + * 缓存雪崩:是指在某一特殊时刻,缓存中的缓存全部失效,然后这一时刻又有大量的数据库访问,导致数据库不堪重负。
  25 + * 解决方案:根据业务的不同设置不同的缓存失效时间。
  26 + * 比如:这个项目,做了3个namespace的缓存,其中一个namespace,共有5个Mapper指向它。所以选择使用范围内的随机值,来做缓存失效时间
  27 + * <p>
  28 + * 时间:2020/8/6 9:37
  29 + */
  30 +public class RedisCache implements Cache {
  31 +
  32 + /**
  33 + * slf4j的日志记录器
  34 + */
  35 + private static final Logger logger = LoggerFactory.getLogger(RedisCache.class);
  36 +
  37 + /**
  38 + * 用于事务性缓存操作的读写锁
  39 + */
  40 + private static final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  41 +
  42 + /**
  43 + * 当前放入缓存的mapper的namespace
  44 + */
  45 + private final String id;
  46 +
  47 + /**
  48 + * 必须存在构造方法
  49 + */
  50 + public RedisCache(String id)
  51 + {
  52 + this.id = id;
  53 + }
  54 +
  55 + /**
  56 + * 返回cache唯一标识
  57 + */
  58 + @Override
  59 + public String getId()
  60 + {
  61 + return this.id;
  62 + }
  63 +
  64 + /**
  65 + * 缓存放入值 redis RedisTemplate StringRedisTemplate
  66 + *
  67 + * @param key hash_key
  68 + * @param value hash_value
  69 + */
  70 + @Override
  71 + public void putObject(Object key, Object value)
  72 + {
  73 + RedisTemplate redisTemplate = getRedisTemplate();
  74 + // 使用redis的hash类型作为缓存存储模型
  75 + redisTemplate.opsForHash().put(id.toString(), encryptionKey(key.toString()), value);
  76 +
  77 + /**
  78 + * 根据业务的不同,设置不同的缓存时间,解决掉缓存雪崩
  79 + */
  80 + if (id.equals("com.sunyo.wlpt.message.bus.service.mapper.VirtualHostMapper")) {
  81 + // 设置缓存时间
  82 + redisTemplate.expire(id.toString(), random(1, 3), TimeUnit.HOURS);
  83 + }
  84 +
  85 + if (id.equals("com.sunyo.wlpt.message.bus.service.mapper.UserMessageBindingMapper")) {
  86 + // 设置缓存时间
  87 + redisTemplate.expire(id.toString(), random(60, 100), TimeUnit.MINUTES);
  88 + }
  89 +
  90 + if (id.equals("com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper")) {
  91 + // 设置缓存时间
  92 + redisTemplate.expire(id.toString(), random(30, 50), TimeUnit.MINUTES);
  93 + }
  94 + }
  95 +
  96 + /**
  97 + *
  98 + */
  99 + public int random(int low, int high)
  100 + {
  101 + int num = ((int) (Math.random() * (high - low))) + low;
  102 + return num;
  103 + }
  104 +
  105 + /**
  106 + * 缓存中中获取数据
  107 + */
  108 + @Override
  109 + public Object getObject(Object key)
  110 + {
  111 + RedisTemplate redisTemplate = getRedisTemplate();
  112 + //根据key 从redis的hash类型中获取数据
  113 + return redisTemplate.opsForHash().get(id.toString(), encryptionKey(key.toString()));
  114 + }
  115 +
  116 + /**
  117 + * 注意:这个方法为mybatis保留方法 默认没有实现 后续版本可能会实现
  118 + *
  119 + * @param key hash_key
  120 + * @return
  121 + */
  122 + @Override
  123 + public Object removeObject(Object key)
  124 + {
  125 + RedisTemplate redisTemplate = getRedisTemplate();
  126 + redisTemplate.delete(key);
  127 + return null;
  128 + }
  129 +
  130 + @Override
  131 + public void clear()
  132 + {
  133 + logger.info("清空->{}<-缓存", id);
  134 + RedisTemplate redisTemplate = getRedisTemplate();
  135 + // 清空 namespace
  136 + redisTemplate.delete(id.toString());
  137 + }
  138 +
  139 + /**
  140 + * 用来计算缓存数量
  141 + */
  142 + @Override
  143 + public int getSize()
  144 + {
  145 + RedisTemplate redisTemplate = getRedisTemplate();
  146 + // 获取hash中key value数量
  147 + return redisTemplate.opsForHash().size(id.toString()).intValue();
  148 + }
  149 +
  150 + /**
  151 + * 封装redisTemplate
  152 + *
  153 + * @return RedisTemplate
  154 + */
  155 + private RedisTemplate getRedisTemplate()
  156 + {
  157 + //通过application工具类获取redisTemplate
  158 + RedisTemplate redisTemplate = (RedisTemplate) ApplicationContextUtils.getBean("redisTemplate");
  159 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  160 + redisTemplate.setHashKeySerializer(new StringRedisSerializer());
  161 + return redisTemplate;
  162 + }
  163 +
  164 + /**
  165 + * 封装一个对key进行md5处理方法
  166 + */
  167 + private String encryptionKey(String key)
  168 + {
  169 + return DigestUtils.md5DigestAsHex(key.getBytes());
  170 + }
  171 +
  172 + @Override
  173 + public ReadWriteLock getReadWriteLock()
  174 + {
  175 + return readWriteLock;
  176 + }
  177 +
  178 +}
  179 +
  1 +package com.sunyo.wlpt.message.bus.service.common;
  2 +
  3 +/**
  4 + * @author 子诚
  5 + * Description:常量公共类
  6 + * 时间:2020/7/17 9:49
  7 + */
  8 +public class Constant {
  9 + public static final String EXIST_SERVERNAME = "MQ服务器名称已存在";
  10 + public static final String EXIST_SERVER_INFO = "该-MQ服务器(ServerIp以及ServerPort)-信息已存在,请谨慎输入";
  11 +
  12 + public static final String EXIST_HOST_INFO = "该-虚拟主机(虚拟主机名称)-信息已存在,请谨慎输入";
  13 +
  14 + public static final String EXIST_EXCHANGE_INFO = "该-交换机(交换机名称)-信息已存在,请谨慎输入";
  15 +
  16 + public static final String EXIST_QUEUE_INFO = "该-消息队列-信息已存在,请谨慎输入";
  17 +
  18 + public static final String EXIST_ROUTINGKEY_INFO = "该-路由键(路由键名称)-信息已存在,请谨慎输入";
  19 +
  20 + public static final String EXIST_UMB = "该绑定关系已经存在了";
  21 +
  22 + public static final String RESULT_SUCCESS = "200";
  23 +}
  1 +package com.sunyo.wlpt.message.bus.service.config;
  2 +
  3 +import org.apache.http.HttpHost;
  4 +import org.elasticsearch.client.RestClient;
  5 +import org.elasticsearch.client.RestHighLevelClient;
  6 +import org.springframework.context.annotation.Bean;
  7 +import org.springframework.context.annotation.Configuration;
  8 +import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
  9 +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:ES的配置文件
  14 + * 时间:2020/8/5 10:23
  15 + */
  16 +@Configuration
  17 +public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
  18 +
  19 +
  20 + private String hostname;
  21 +
  22 + private Integer port;
  23 +
  24 + private String scheme;
  25 +
  26 +
  27 + @Override
  28 + @Bean
  29 +
  30 + public RestHighLevelClient elasticsearchClient()
  31 + {
  32 + RestHighLevelClient client = new RestHighLevelClient(
  33 + RestClient.builder(
  34 + // 天生契合集群,有几个es环境,就 new HttpHost 几个,用,相隔
  35 + new HttpHost("192.168.37.139", 9200, "http")
  36 + )
  37 + );
  38 + return client;
  39 + }
  40 +
  41 + @Bean
  42 + public ElasticsearchRestTemplate elasticsearchRestTemplate()
  43 + {
  44 + return new ElasticsearchRestTemplate(elasticsearchClient());
  45 + }
  46 +}
  1 +package com.sunyo.wlpt.message.bus.service.config;
  2 +
  3 +import org.springframework.context.annotation.Configuration;
  4 +import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  5 +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  6 +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  7 +
  8 +/**
  9 + * @author 子诚
  10 + * Description:SpringSecurity 权限配置框架
  11 + * 时间:2020/7/5 13:38
  12 + */
  13 +@EnableWebSecurity
  14 +@Configuration
  15 +public class SecurityConfig extends WebSecurityConfigurerAdapter {
  16 + @Override
  17 + protected void configure(HttpSecurity http) throws Exception {
  18 + http.csrf().disable();
  19 + }
  20 +}
  1 +package com.sunyo.wlpt.message.bus.service.config;
  2 +
  3 +import org.springframework.context.annotation.Bean;
  4 +import org.springframework.context.annotation.Configuration;
  5 +import springfox.documentation.builders.ApiInfoBuilder;
  6 +import springfox.documentation.builders.PathSelectors;
  7 +import springfox.documentation.builders.RequestHandlerSelectors;
  8 +import springfox.documentation.service.ApiInfo;
  9 +import springfox.documentation.spi.DocumentationType;
  10 +import springfox.documentation.spring.web.plugins.Docket;
  11 +import springfox.documentation.swagger2.annotations.EnableSwagger2;
  12 +
  13 +/**
  14 + * @author 子诚
  15 + * Description:swagger-knife4j 的配置文件
  16 + * 时间:2020/7/10 11:48
  17 + */
  18 +@Configuration
  19 +@EnableSwagger2
  20 +public class SwaggerConfig {
  21 + @Bean
  22 + public Docket createRestApi()
  23 + {
  24 + return new Docket(DocumentationType.SWAGGER_2)
  25 + .apiInfo(apiInfo())
  26 + .select()
  27 + .apis(RequestHandlerSelectors.basePackage("com.sunyo.wlpt.message.bus.service.controller"))
  28 + .paths(PathSelectors.any())
  29 + .build();
  30 + }
  31 +
  32 + private ApiInfo apiInfo()
  33 + {
  34 + return new ApiInfoBuilder()
  35 + .title("消息总线平台--接收消息服务")
  36 + .description("消息总线平台--接收消息服务")
  37 + .termsOfServiceUrl("http://localhost:9032/")
  38 + .contact("子诚")
  39 + .version("1.0.0")
  40 + .build();
  41 + }
  42 +}
  1 +package com.sunyo.wlpt.message.bus.service.config;
  2 +
  3 +import org.springframework.context.annotation.Bean;
  4 +import org.springframework.context.annotation.Configuration;
  5 +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  6 +
  7 +import java.util.concurrent.Executor;
  8 +import java.util.concurrent.ThreadPoolExecutor;
  9 +
  10 +/**
  11 + * @author 子诚
  12 + * Description:为异步任务,创建线程池
  13 + * 时间:2020/8/20 14:15
  14 + */
  15 +@Configuration
  16 +public class TaskConfiguration {
  17 + @Bean("taskExecutor")
  18 + public Executor taskExecutor() {
  19 + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
  20 + // 核心线程数
  21 + executor.setCorePoolSize(20);
  22 + // 最大线程数
  23 + executor.setMaxPoolSize(100);
  24 + // 缓冲队列
  25 + executor.setQueueCapacity(200);
  26 + // 允许线程的空闲时间
  27 + executor.setKeepAliveSeconds(60);
  28 + // 线程池名的前缀
  29 + executor.setThreadNamePrefix("taskExecutor-");
  30 +
  31 + // 优雅的关闭线程池,
  32 + executor.setWaitForTasksToCompleteOnShutdown(true);
  33 + executor.setAwaitTerminationSeconds(60);
  34 +
  35 + // 线程池对拒绝任务的处理策略,CallerRunsPolicy策略,当线程池没有处理能力的时候,该策略会直接在execute方法的调用线程中运行被拒绝的任务;
  36 + // 如果执行程序已关闭,则会丢弃该任务
  37 + executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
  38 + return executor;
  39 + }
  40 +}
  1 +package com.sunyo.wlpt.message.bus.service.controller;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.XmlData;
  4 +import com.sunyo.wlpt.message.bus.service.exception.CustomExceptionType;
  5 +import com.sunyo.wlpt.message.bus.service.rabbit.utils.DirectUtils;
  6 +import com.sunyo.wlpt.message.bus.service.response.ResultJson;
  7 +import com.sunyo.wlpt.message.bus.service.service.UserMessageBindingService;
  8 +import com.sunyo.wlpt.message.bus.service.service.impl.AsyncTaskService;
  9 +import com.sunyo.wlpt.message.bus.service.utils.XmlUtils;
  10 +import lombok.extern.slf4j.Slf4j;
  11 +import org.dom4j.DocumentException;
  12 +import org.springframework.format.annotation.DateTimeFormat;
  13 +import org.springframework.web.bind.annotation.*;
  14 +
  15 +import javax.annotation.Resource;
  16 +import java.io.IOException;
  17 +import java.util.Date;
  18 +import java.util.concurrent.CountDownLatch;
  19 +import java.util.concurrent.Future;
  20 +import java.util.concurrent.TimeoutException;
  21 +
  22 +import static com.sunyo.wlpt.message.bus.service.common.Constant.RESULT_SUCCESS;
  23 +
  24 +/**
  25 + * @author 子诚
  26 + * Description:
  27 + * 时间:2020/7/16 14:46
  28 + */
  29 +@Slf4j
  30 +@CrossOrigin
  31 +@RequestMapping("bus/rabbit")
  32 +@RestController
  33 +public class RabbitController {
  34 +
  35 + @Resource
  36 + private UserMessageBindingService userMessageBindingService;
  37 +
  38 + @Resource
  39 + private XmlUtils xmlUtils;
  40 +
  41 + @Resource
  42 + private DirectUtils directUtils;
  43 +
  44 + @Resource
  45 + private AsyncTaskService asyncTaskService;
  46 +
  47 + /**
  48 + * 消费消息,多个
  49 + *
  50 + * @param receiver 接收者
  51 + * @param SERV 服务器
  52 + * @param VSHT 虚拟主机
  53 + * @param RCVR 队列
  54 + * @return
  55 + */
  56 + @GetMapping("/consumer_one")
  57 + public ResultJson consumerOne(
  58 + @RequestParam(value = "receiver") String receiver,
  59 + @RequestParam(value = "SERV") String SERV,
  60 + @RequestParam(value = "VSHT") String VSHT,
  61 + @RequestParam(value = "RCVR") String RCVR)
  62 + {
  63 + try {
  64 + XmlData xmlData = XmlData.builder()
  65 + .receiver(receiver)
  66 + .serverName(SERV)
  67 + .virtualHostName(VSHT)
  68 + .queueName(RCVR)
  69 + .build();
  70 + ResultJson validate = xmlUtils.validateReceiveParam(xmlData);
  71 + if (!RESULT_SUCCESS.equals(validate.getCode())) {
  72 + return validate;
  73 + }
  74 + ResultJson result = directUtils.directConsumerByPull(xmlData);
  75 + return result;
  76 + } catch (IOException | TimeoutException e) {
  77 + return ResultJson.error(CustomExceptionType.RECEIVE_SERVER_EXCEPTION);
  78 + }
  79 + }
  80 +
  81 + /**
  82 + * 消费消息,多个
  83 + *
  84 + * @param receiver 接收者
  85 + * @param SERV 服务器
  86 + * @param VSHT 虚拟主机
  87 + * @param RCVR 队列
  88 + * @param count 消息数量
  89 + * @return
  90 + */
  91 + @GetMapping("/consumer_more")
  92 + public ResultJson consumerMore(
  93 + @RequestParam(value = "receiver") String receiver,
  94 + @RequestParam(value = "SERV") String SERV,
  95 + @RequestParam(value = "VSHT") String VSHT,
  96 + @RequestParam(value = "RCVR") String RCVR,
  97 + @RequestParam(value = "count", required = false) Integer count)
  98 + {
  99 + try {
  100 + XmlData xmlData = XmlData.builder()
  101 + .receiver(receiver)
  102 + .serverName(SERV)
  103 + .virtualHostName(VSHT)
  104 + .queueName(RCVR)
  105 + .build();
  106 + ResultJson validate = xmlUtils.validateReceiveParam(xmlData);
  107 + if (!RESULT_SUCCESS.equals(validate.getCode())) {
  108 + return validate;
  109 + }
  110 + if (count == null || count < 1) {
  111 + count = 1;
  112 + }
  113 + ResultJson result = directUtils.directConsumerByPullMore(xmlData, count);
  114 + return result;
  115 + } catch (IOException | TimeoutException e) {
  116 + return ResultJson.error(CustomExceptionType.RECEIVE_SERVER_EXCEPTION);
  117 + }
  118 + }
  119 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +import java.util.Date;
  11 +
  12 +/**
  13 + * @author 子诚
  14 + * Description:MQ路由交换表
  15 + * 时间:2020/7/1 10:08
  16 + */
  17 +
  18 +@Data
  19 +@Builder
  20 +@AllArgsConstructor
  21 +@NoArgsConstructor
  22 +public class BusExchange implements Serializable {
  23 +
  24 + private static final long serialVersionUID = -8533771450468596177L;
  25 +
  26 + /**
  27 + * 交换机ID
  28 + */
  29 + private String id;
  30 +
  31 + /**
  32 + * 交换机名称
  33 + */
  34 + private String exchangeName;
  35 +
  36 + /**
  37 + * 所属虚拟主机ID
  38 + */
  39 + private String virtualHostId;
  40 +
  41 + /**
  42 + * 交换机类型:Direct、Fanout、Topic、Headers
  43 + */
  44 + private String exchangeType;
  45 +
  46 + /**
  47 + * 是否持久化,默认true:1是true;0是false
  48 + */
  49 + private Boolean durability;
  50 +
  51 + /**
  52 + * 是否自动删除,默认false:1是true;0是false
  53 + */
  54 + private Boolean autoDelete;
  55 +
  56 + /**
  57 + * 是否是RabbitMQ内部使用,默认false:1是true;0是false
  58 + */
  59 + private Boolean internal;
  60 +
  61 + /**
  62 + * 扩展参数,以JSON格式存储
  63 + */
  64 + private String arguments;
  65 +
  66 + /**
  67 + * 交换机相关描述
  68 + */
  69 + private String description;
  70 +
  71 + /**
  72 + * 交换机创建时间
  73 + */
  74 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  75 + private Date gmtCreate;
  76 +
  77 + /**
  78 + * 交换机修改时间
  79 + */
  80 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  81 + private Date gmtModified;
  82 +
  83 + private VirtualHost virtualHost;
  84 +
  85 + /**
  86 + * 交换机名称的别名
  87 + */
  88 + private String aliasName;
  89 +
  90 + /**
  91 + * 定义有参构造器,封装 BusExchangeController 的查询参数
  92 + *
  93 + * @param exchangeName 交换机名称
  94 + * @param virtualHostId 所属虚拟主机ID
  95 + */
  96 + public BusExchange(String exchangeName, String virtualHostId) {
  97 + this.exchangeName = exchangeName;
  98 + this.virtualHostId = virtualHostId;
  99 + }
  100 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +import java.io.Serializable;
  9 +import java.util.Date;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:队列表
  14 + * 时间:2020/7/23 17:16
  15 + */
  16 +
  17 +@Data
  18 +@Builder
  19 +@AllArgsConstructor
  20 +@NoArgsConstructor
  21 +public class BusQueue implements Serializable {
  22 +
  23 + private static final long serialVersionUID = 6999154061907346103L;
  24 +
  25 + /**
  26 + * 队列的ID
  27 + */
  28 + private String id;
  29 +
  30 + /**
  31 + * 队列名称
  32 + */
  33 + private String queueName;
  34 +
  35 + /**
  36 + * 所属用户id
  37 + */
  38 + private String userId;
  39 +
  40 + /**
  41 + * 所属用户登录名称
  42 + */
  43 + private String username;
  44 +
  45 + /**
  46 + * 所属虚拟主机ID
  47 + */
  48 + private String virtualHostId;
  49 +
  50 + /**
  51 + * 是否持久化,默认true:1是true;0是false
  52 + */
  53 + private Boolean durability;
  54 +
  55 + /**
  56 + * 是否自动删除,默认false:1是true;0是false
  57 + */
  58 + private Boolean autoDelete;
  59 +
  60 + /**
  61 + * 扩展参数,以JSON格式存储
  62 + */
  63 + private String arguments;
  64 +
  65 + /**
  66 + * 队列相关描述
  67 + */
  68 + private String description;
  69 +
  70 + /**
  71 + * 队列创建时间
  72 + */
  73 + private Date gmtCreate;
  74 +
  75 + /**
  76 + * 队列修改时间
  77 + */
  78 + private Date gmtModified;
  79 +
  80 + /**
  81 + * 队列名称的别名
  82 + */
  83 + private String aliasName;
  84 +
  85 + /**
  86 + * 一个队列对应一个虚拟机
  87 + */
  88 + private VirtualHost virtualHost;
  89 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +import java.util.Date;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * @author 子诚
  15 + * Description:MQ服务器静态信息表
  16 + * 时间:2020/8/12 14:07
  17 + */
  18 +@Data
  19 +@Builder
  20 +@AllArgsConstructor
  21 +@NoArgsConstructor
  22 +public class BusServer implements Serializable {
  23 +
  24 + private static final long serialVersionUID = -5662106932282473768L;
  25 +
  26 + /**
  27 + * 服务器ID
  28 + */
  29 + private String id;
  30 +
  31 + /**
  32 + * 服务器名称
  33 + */
  34 + private String serverName;
  35 +
  36 + /**
  37 + * 服务器IP地址
  38 + */
  39 + private String serverIp;
  40 +
  41 + /**
  42 + * 服务器端口号
  43 + */
  44 + private Integer serverPort;
  45 +
  46 + /**
  47 + * 客户端的端口号
  48 + */
  49 + private Integer clientPort;
  50 +
  51 + /**
  52 + * 备用字段,超级用户的用户名
  53 + */
  54 + private String superUsername;
  55 +
  56 + /**
  57 + * 备用字段,超级用户的密码
  58 + */
  59 + private String superPassword;
  60 +
  61 + /**
  62 + * 服务器相关描述
  63 + */
  64 + private String description;
  65 +
  66 + /**
  67 + * 服务器创建时间
  68 + */
  69 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  70 + private Date gmtCreate;
  71 +
  72 + /**
  73 + * 服务器修改时间
  74 + */
  75 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  76 + private Date gmtModified;
  77 +
  78 + /**
  79 + * 一个服务器对应多个虚拟主机
  80 + */
  81 + private List<VirtualHost> virtualHosts;
  82 +
  83 + /**
  84 + * 对应的多个虚拟主机的别名,前端特殊使用,误删
  85 + */
  86 + private List<VirtualHost> aliasList;
  87 +
  88 + /**
  89 + * 服务器名称的别名
  90 + */
  91 + private String aliasName;
  92 +
  93 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +import java.io.Serializable;
  9 +import java.util.Date;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:交换机、队列、routing_key绑定关系表
  14 + * 时间:2020/7/2 16:47
  15 + */
  16 +
  17 +@Data
  18 +@Builder
  19 +@AllArgsConstructor
  20 +@NoArgsConstructor
  21 +public class ExchangeQueueRouting implements Serializable {
  22 +
  23 + private static final long serialVersionUID = 3765854915972798115L;
  24 +
  25 + /**
  26 + * 交换机、队列、routing_key绑定关系的ID
  27 + */
  28 + private String id;
  29 +
  30 + /**
  31 + * 对应交换机ID
  32 + */
  33 + private String exchangeId;
  34 +
  35 + /**
  36 + * 对应队列的ID
  37 + */
  38 + private String queueId;
  39 +
  40 + /**
  41 + * 对应路由键的ID
  42 + */
  43 + private String routingKeyId;
  44 +
  45 + /**
  46 + * 对应路由键的名称
  47 + */
  48 + private String routingKeyName;
  49 +
  50 + /**
  51 + * 创建时间
  52 + */
  53 + private Date gmtCreate;
  54 +
  55 + /**
  56 + * 修改时间
  57 + */
  58 + private Date gmtModified;
  59 +
  60 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +import org.springframework.data.annotation.Id;
  9 +import org.springframework.data.elasticsearch.annotations.Document;
  10 +import org.springframework.data.elasticsearch.annotations.Field;
  11 +import org.springframework.data.elasticsearch.annotations.FieldType;
  12 +
  13 +import java.io.Serializable;
  14 +import java.util.Date;
  15 +
  16 +/**
  17 + * @author 子诚
  18 + * Description:消息收发记录表(默认存储七天)
  19 + * 时间:2020/7/15 10:45
  20 + */
  21 +
  22 +@Data
  23 +@Builder
  24 +@AllArgsConstructor
  25 +@NoArgsConstructor
  26 +@Document(indexName = "message_note")
  27 +public class MessageNote implements Serializable {
  28 +
  29 + private static final long serialVersionUID = -2119333801860569470L;
  30 +
  31 + /**
  32 + * 消息收发记录表的ID
  33 + */
  34 + @Id
  35 + private String id;
  36 +
  37 + /**
  38 + * 用户的ID
  39 + */
  40 + private String userId;
  41 +
  42 + /**
  43 + * 所属用户登陆名称
  44 + */
  45 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  46 + private String username;
  47 +
  48 + /**
  49 + * 所属服务器的ID
  50 + */
  51 + @Field(type = FieldType.Text)
  52 + private String serverId;
  53 +
  54 + /**
  55 + * 所属服务器名称
  56 + */
  57 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  58 + private String serverName;
  59 +
  60 + /**
  61 + * 所属虚拟主机的ID
  62 + */
  63 + @Field(type = FieldType.Text)
  64 + private String virtualHostId;
  65 +
  66 + /**
  67 + * 所属虚拟主机名称
  68 + */
  69 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  70 + private String virtualHostName;
  71 +
  72 + /**
  73 + * 所属交换机的ID
  74 + */
  75 + @Field(type = FieldType.Text)
  76 + private String exchangeId;
  77 +
  78 + /**
  79 + * 所属交换机名称
  80 + */
  81 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  82 + private String exchangeName;
  83 +
  84 + /**
  85 + * 所属队列的ID
  86 + */
  87 + @Field(type = FieldType.Text)
  88 + private String queueId;
  89 +
  90 + /**
  91 + * 所属队列名称
  92 + */
  93 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  94 + private String queueName;
  95 +
  96 + /**
  97 + * 所属路由键的ID
  98 + */
  99 + @Field(type = FieldType.Text)
  100 + private String routingKeyId;
  101 +
  102 + /**
  103 + * 所属路由键的名称
  104 + */
  105 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  106 + private String routingKeyName;
  107 +
  108 + /**
  109 + * 消息发送时间
  110 + */
  111 + @Field(type = FieldType.Date)
  112 + @JsonFormat(timezone = "GMT+8")
  113 + private Date sendTime;
  114 +
  115 + @Field(type = FieldType.Text)
  116 + private String alias_sendTime;
  117 +
  118 + /**
  119 + * 查询时间段,开始时间
  120 + */
  121 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  122 + private Date sendTimeBegin;
  123 +
  124 + /**
  125 + * 查询时间段,结束时间
  126 + */
  127 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  128 + private Date sendTimeEnd;
  129 +
  130 +
  131 + /**
  132 + * 消息获取时间
  133 + */
  134 + private Date receiveTime;
  135 +
  136 + /**
  137 + * 发送消息内容
  138 + */
  139 + private byte[] sendContent;
  140 +
  141 + /**
  142 + * 发送消息内容,别名
  143 + */
  144 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  145 + private String alias_sendContent;
  146 +
  147 + /**
  148 + * 相关描述
  149 + */
  150 + @Field(type = FieldType.Text, analyzer = "ik_max_word")
  151 + private String description;
  152 +
  153 + /**
  154 + * 创建时间
  155 + */
  156 + @Field(type = FieldType.Date)
  157 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  158 + private Date gmtCreate;
  159 +
  160 + /**
  161 + * 修改时间
  162 + */
  163 + private Date gmtModified;
  164 +
  165 + /**
  166 + * 自定义有参构造器,封装 MessageNoteController 的查询参数
  167 + *
  168 + * @param username 用户登陆名称
  169 + * @param serverName MQ服务器名称
  170 + * @param virtualHostName 虚拟主机名称
  171 + * @param exchangeName 交换机名称
  172 + * @param queueName 队列名称
  173 + * @param routingKeyName 路由键名称
  174 + * @param sendTime 发送消息时间
  175 + * @param receiveTime 接收消息时间
  176 + */
  177 + public MessageNote(String username, String serverName, String virtualHostName, String exchangeName, String queueName, String routingKeyName, Date sendTime, Date receiveTime)
  178 + {
  179 + this.username = username;
  180 + this.serverName = serverName;
  181 + this.virtualHostName = virtualHostName;
  182 + this.exchangeName = exchangeName;
  183 + this.queueName = queueName;
  184 + this.routingKeyName = routingKeyName;
  185 + this.sendTime = sendTime;
  186 + this.receiveTime = receiveTime;
  187 + }
  188 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +import java.util.Date;
  11 +
  12 +/**
  13 + * @author 子诚
  14 + * Description:Routing key静态配置表/二级类
  15 + * 时间:2020/6/29 16:45
  16 + */
  17 +@Data
  18 +@Builder
  19 +@AllArgsConstructor
  20 +@NoArgsConstructor
  21 +public class RoutingKey implements Serializable {
  22 +
  23 + private static final long serialVersionUID = 4318583918719126325L;
  24 +
  25 + /**
  26 + * routing_key的ID
  27 + */
  28 + private String id;
  29 +
  30 + /**
  31 + * routing_key的名称
  32 + */
  33 + private String routingKeyName;
  34 +
  35 + /**
  36 + * 所属交换机ID
  37 + */
  38 + private String exchangeId;
  39 +
  40 + /**
  41 + * routing_key相关描述
  42 + */
  43 + private String description;
  44 +
  45 + /**
  46 + * routing_key创建时间
  47 + */
  48 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  49 + private Date gmtCreate;
  50 +
  51 + /**
  52 + * routing_key修改时间
  53 + */
  54 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  55 + private Date gmtModified;
  56 +
  57 + /**
  58 + * 路由键名称的别名
  59 + */
  60 + private String aliasName;
  61 +
  62 + /**
  63 + * 一个路由键对应一个交换机
  64 + */
  65 + private BusExchange busExchange;
  66 +
  67 + /**
  68 + * 定义有参构造器,封装 RoutingKeyController 的查询参数
  69 + *
  70 + * @param routingKeyName 路由键名称
  71 + * @param exchangeId 所属交换机ID
  72 + */
  73 + public RoutingKey(String routingKeyName, String exchangeId) {
  74 + this.routingKeyName = routingKeyName;
  75 + this.exchangeId = exchangeId;
  76 + }
  77 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +import java.io.Serializable;
  9 +
  10 +/**
  11 + * @author 子诚
  12 + * Description:自动定时删除的时间设置表
  13 + * 时间:2020/7/15 10:28
  14 + */
  15 +
  16 +@Data
  17 +@Builder
  18 +@AllArgsConstructor
  19 +@NoArgsConstructor
  20 +public class SchedulingDelete implements Serializable {
  21 +
  22 + private static final long serialVersionUID = -4810544767961191508L;
  23 +
  24 + /**
  25 + * 时间设置表的ID
  26 + */
  27 + private String id;
  28 +
  29 + /**
  30 + * 设置时间
  31 + */
  32 + private Integer deleteTime;
  33 +
  34 + /**
  35 + * 类型
  36 + */
  37 + private String deleteType;
  38 +
  39 + /**
  40 + * 相关描述
  41 + */
  42 + private String description;
  43 +
  44 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +import java.io.Serializable;
  9 +import java.util.Date;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:MQ账户信息表
  14 + * 时间:2020/8/10 17:44
  15 + */
  16 +@Data
  17 +@Builder
  18 +@AllArgsConstructor
  19 +@NoArgsConstructor
  20 +public class UserInfo implements Serializable {
  21 + private static final long serialVersionUID = 8510385519421924997L;
  22 +
  23 + /**
  24 + * 用户的ID
  25 + */
  26 + private String id;
  27 +
  28 + /**
  29 + * 用户登陆名称
  30 + */
  31 + private String username;
  32 +
  33 + /**
  34 + * 用户登陆密码
  35 + */
  36 + private String password;
  37 +
  38 + /**
  39 + * 所属服务器id
  40 + */
  41 + private String serverId;
  42 +
  43 + /**
  44 + * 所属服务器名称
  45 + */
  46 + private String serverName;
  47 +
  48 + /**
  49 + * 对应虚拟主机的id
  50 + */
  51 + private String virtualHostId;
  52 +
  53 + /**
  54 + * 对应虚拟主机的名称
  55 + */
  56 + private String virtualHostName;
  57 +
  58 + /**
  59 + * 用户的姓名(备用字段)
  60 + */
  61 + private String realName;
  62 +
  63 + /**
  64 + * 用户相关描述
  65 + */
  66 + private String description;
  67 +
  68 + /**
  69 + * 用户信息创建时间
  70 + */
  71 + private Date gmtCreate;
  72 +
  73 + /**
  74 + * 用户信息修改时间
  75 + */
  76 + private Date gmtModified;
  77 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import lombok.AllArgsConstructor;
  4 +import lombok.Builder;
  5 +import lombok.Data;
  6 +import lombok.NoArgsConstructor;
  7 +
  8 +import java.io.Serializable;
  9 +import java.util.Date;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:账户信息绑定配置表
  14 + * 时间:2020/7/15 10:37
  15 + */
  16 +@Data
  17 +@Builder
  18 +@AllArgsConstructor
  19 +@NoArgsConstructor
  20 +public class UserMessageBinding implements Serializable {
  21 +
  22 + private static final long serialVersionUID = 1036230195492305641L;
  23 +
  24 + /**
  25 + * 账户信息绑定配置表的ID
  26 + */
  27 + private String id;
  28 +
  29 + /**
  30 + * 用户的ID
  31 + */
  32 + private String userId;
  33 +
  34 + /**
  35 + * 所属用户登陆名称
  36 + */
  37 + private String username;
  38 +
  39 + /**
  40 + * 所属服务器的ID
  41 + */
  42 + private String serverId;
  43 +
  44 + /**
  45 + * 所属服务器名称
  46 + */
  47 + private String serverName;
  48 +
  49 + /**
  50 + * 所属虚拟主机的ID
  51 + */
  52 + private String virtualHostId;
  53 +
  54 + /**
  55 + * 所属虚拟主机名称
  56 + */
  57 + private String virtualHostName;
  58 +
  59 + /**
  60 + * 所属交换机的ID
  61 + */
  62 + private String exchangeId;
  63 +
  64 + /**
  65 + * 所属交换机名称
  66 + */
  67 + private String exchangeName;
  68 +
  69 + /**
  70 + * 所属队列的ID
  71 + */
  72 + private String queueId;
  73 +
  74 + /**
  75 + * 所属队列名称
  76 + */
  77 + private String queueName;
  78 +
  79 + /**
  80 + * 所属路由键的ID
  81 + */
  82 + private String routingKeyId;
  83 +
  84 + /**
  85 + * 所属路由键的名称
  86 + */
  87 + private String routingKeyName;
  88 +
  89 + /**
  90 + * 订阅者
  91 + */
  92 + private String subscriber;
  93 +
  94 + /**
  95 + * 相关描述
  96 + */
  97 + private String description;
  98 +
  99 + /**
  100 + * 创建时间
  101 + */
  102 + private Date gmtCreate;
  103 +
  104 + /**
  105 + * 修改时间
  106 + */
  107 + private Date gmtModified;
  108 +
  109 + /**
  110 + * 自定义有参构造器,封装 UserMessageBindingController 的查询参数
  111 + *
  112 + * @param username 用户名称
  113 + * @param serverName 服务器名称
  114 + * @param virtualHostName 虚拟主机名称
  115 + * @param exchangeName 交换机名称
  116 + * @param queueName 队列名称
  117 + * @param routingKeyName 路由键名称
  118 + * @param subscriber 订阅者
  119 + */
  120 + public UserMessageBinding(String username, String serverName, String virtualHostName, String exchangeName, String queueName, String routingKeyName, String subscriber) {
  121 + this.username = username;
  122 + this.serverName = serverName;
  123 + this.virtualHostName = virtualHostName;
  124 + this.exchangeName = exchangeName;
  125 + this.queueName = queueName;
  126 + this.routingKeyName = routingKeyName;
  127 + this.subscriber = subscriber;
  128 + }
  129 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +import java.util.Date;
  11 +
  12 +/**
  13 + * @author 子诚
  14 + * Description:用户、服务器、虚拟机信息绑定关系表
  15 + * 时间:2020/7/2 11:35
  16 + */
  17 +
  18 +@Data
  19 +@Builder
  20 +@AllArgsConstructor
  21 +@NoArgsConstructor
  22 +public class UserServerVirtualHost implements Serializable {
  23 +
  24 + private static final long serialVersionUID = -7376053283857221145L;
  25 +
  26 + /**
  27 + * 用户、服务器、虚拟机信息绑定关系的ID
  28 + */
  29 + private String id;
  30 +
  31 + /**
  32 + * 所属用户登陆名称
  33 + */
  34 + private String username;
  35 +
  36 + /**
  37 + * 所属服务器ID
  38 + */
  39 + private String serverId;
  40 +
  41 + /**
  42 + * 所属虚拟主机ID
  43 + */
  44 + private String virtualHostId;
  45 +
  46 + /**
  47 + * 创建时间
  48 + */
  49 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  50 + private Date gmtCreate;
  51 +
  52 + /**
  53 + * 修改时间
  54 + */
  55 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  56 + private Date gmtModified;
  57 +
  58 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +import java.util.Date;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * @author 子诚
  15 + * Description:MQ虚拟主机名称表
  16 + * 时间:2020/6/29 16:36
  17 + */
  18 +@Data
  19 +@Builder
  20 +@AllArgsConstructor
  21 +@NoArgsConstructor
  22 +public class VirtualHost implements Serializable {
  23 +
  24 + private static final long serialVersionUID = -3174914872904776153L;
  25 +
  26 + /**
  27 + * 虚拟主机ID
  28 + */
  29 + private String id;
  30 +
  31 + /**
  32 + * 虚拟主机名称
  33 + */
  34 + private String virtualHostName;
  35 +
  36 + /**
  37 + * 所属服务器ID
  38 + */
  39 + private String serverId;
  40 +
  41 + /**
  42 + * 虚拟主机相关描述
  43 + */
  44 + private String description;
  45 +
  46 + /**
  47 + * 虚拟主机创建时间
  48 + */
  49 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  50 + private Date gmtCreate;
  51 +
  52 + /**
  53 + * 虚拟主机修改时间
  54 + */
  55 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  56 + private Date gmtModified;
  57 +
  58 + /**
  59 + * 虚拟主机名称的别名
  60 + */
  61 + private String aliasName;
  62 +
  63 + /**
  64 + * 一个虚拟主机对应一个服务器
  65 + */
  66 + private BusServer busServer;
  67 +
  68 + /**
  69 + * 一个虚拟主机对应多个交换机
  70 + */
  71 + private List<BusExchange> busExchanges;
  72 +
  73 + /**
  74 + * 对应的多个交换机的别名,前端特殊使用,误删
  75 + */
  76 + private List<BusExchange> aliasList;
  77 +
  78 + /**
  79 + * 定义有参构造器
  80 + * 封装 VirtualHostController 的查询参数
  81 + *
  82 + * @param serverId 所属服务器ID
  83 + * @param virtualHostName 虚拟机名称
  84 + */
  85 + public VirtualHost(String virtualHostName, String serverId) {
  86 + this.virtualHostName = virtualHostName;
  87 + this.serverId = serverId;
  88 + }
  89 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +import java.util.Date;
  11 +// 报文模板,如下
  12 +/*
  13 + <?xml version="1.0" encoding="UTF-8"?>
  14 + <MSG>
  15 + <META>
  16 + <SNDR> 消息发送者账号 </SNDR>
  17 + <RCVR> 指定接受者 </RCVR>
  18 + <DDTM> 发送报文时间 </DDTM>
  19 + <TYPE> 大类型--交换机名称 </TYPE>
  20 + <STYP> 子类型--路由键名称 </STYP>
  21 + <SEQN> 序列号(唯一) </SEQN>
  22 + <TOKN> token值 </TOKN>
  23 + <VSHT> 虚拟机名称 </VSHT>
  24 + <SERV> MQ服务器名称 </SERV>
  25 + </META>
  26 + <BODY>
  27 + 发送内容
  28 + </BODY>
  29 + </MSG>
  30 + */
  31 +
  32 +/**
  33 + * @author 子诚
  34 + * Description:
  35 + * 时间:2020/7/28 10:30
  36 + */
  37 +@Data
  38 +@Builder
  39 +@NoArgsConstructor
  40 +@AllArgsConstructor
  41 +public class XmlData implements Serializable {
  42 +
  43 + private static final long serialVersionUID = -2539052741259114774L;
  44 +
  45 + /**
  46 + * 对应:根标签 MSG ->报文
  47 + */
  48 + private String message;
  49 +
  50 + /**
  51 + * 对应:标签 BODY -> 发送内容
  52 + */
  53 + private String sendContent;
  54 +
  55 + /**
  56 + * 对应:标签 META -> 报文的头部信息
  57 + */
  58 + private String meta;
  59 +
  60 + /**
  61 + * 对应:标签 SNDR -> 报文发送者(用户)
  62 + */
  63 + private String sender;
  64 +
  65 + /**
  66 + * 接收者
  67 + */
  68 + private String receiver;
  69 +
  70 + /**
  71 + * 对应:标签 RCVR -> 指定接收者(队列名称)
  72 + */
  73 + private String queueName;
  74 +
  75 + /**
  76 + * 对应:标签 DDTM -> 发送报文时间
  77 + */
  78 + private String sendTime;
  79 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
  80 + private Date sendDateTime;
  81 + /**
  82 + * 对应:标签 TYPE -> (一级)交换机名称
  83 + */
  84 + private String exchangeName;
  85 +
  86 + /**
  87 + * 对应:标签 STYP -> (二级)路由键名称
  88 + */
  89 + private String routingKeyName;
  90 +
  91 + /**
  92 + * 对应:标签 SEQN -> 序列(唯一)
  93 + */
  94 + private String sequence;
  95 +
  96 + /**
  97 + * 对应:标签 TOKN -> JWT生成的 token 值
  98 + */
  99 + private String token;
  100 +
  101 + /**
  102 + * 对应:标签 VSHT -> 指定的虚拟主机
  103 + */
  104 + private String virtualHostName;
  105 +
  106 + /**
  107 + * 对应:标签 SERV -> 指定的服务器
  108 + */
  109 + private String serverName;
  110 +
  111 + /**
  112 + * 普通用户的密码
  113 + */
  114 + private String password;
  115 +
  116 + /**
  117 + * 服务器ip地址
  118 + */
  119 + private String serverIp;
  120 +
  121 + /**
  122 + * 服务器端口号
  123 + */
  124 + private Integer serverPort;
  125 +
  126 + /**
  127 + * 超级用户名称
  128 + */
  129 + private String superUsername;
  130 +
  131 + /**
  132 + * 超级用户的密码
  133 + */
  134 + private String superPassword;
  135 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain.view;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonProperty;
  4 +import com.rabbitmq.http.client.domain.ExchangeInfo;
  5 +import com.rabbitmq.http.client.domain.ExchangeMessageStats;
  6 +import lombok.AllArgsConstructor;
  7 +import lombok.Builder;
  8 +import lombok.Data;
  9 +import lombok.NoArgsConstructor;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:
  14 + * 时间:2020/8/31 14:38
  15 + */
  16 +@Data
  17 +@Builder
  18 +@AllArgsConstructor
  19 +@NoArgsConstructor
  20 +public class TempExchangeInfo extends ExchangeInfo {
  21 + @JsonProperty("message_stats")
  22 + private ExchangeMessageStats messageStats;
  23 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain.view;
  2 +
  3 +import com.rabbitmq.http.client.domain.ExchangeMessageStats;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:自定义MQ返回信息
  14 + * 时间:2020/8/27 16:11
  15 + */
  16 +@Data
  17 +@Builder
  18 +@AllArgsConstructor
  19 +@NoArgsConstructor
  20 +public class ViewExchangeInfo implements Serializable {
  21 + private static final long serialVersionUID = -3353890396017709770L;
  22 + private String serverName;
  23 + private TempExchangeInfo tempExchangeInfo;
  24 +
  25 + public long getPublishIn()
  26 + {
  27 + TempExchangeInfo tempExchangeInfo = getTempExchangeInfo();
  28 + ExchangeMessageStats messageStats = tempExchangeInfo.getMessageStats();
  29 + if (messageStats == null) {
  30 + return 0;
  31 + }
  32 + return messageStats.getPublishIn();
  33 + }
  34 +}
  1 +package com.sunyo.wlpt.message.bus.service.domain.view;
  2 +
  3 +import com.rabbitmq.http.client.domain.QueueInfo;
  4 +import lombok.AllArgsConstructor;
  5 +import lombok.Builder;
  6 +import lombok.Data;
  7 +import lombok.NoArgsConstructor;
  8 +
  9 +import java.io.Serializable;
  10 +
  11 +/**
  12 + * @author 子诚
  13 + * Description:
  14 + * 时间:2020/8/27 14:29
  15 + */
  16 +@Data
  17 +@Builder
  18 +@AllArgsConstructor
  19 +@NoArgsConstructor
  20 +public class ViewQueueInfo implements Serializable {
  21 + private static final long serialVersionUID = -1016067862213381683L;
  22 + private String serverName;
  23 + private QueueInfo queueInfo;
  24 +
  25 + /**
  26 + * 排序参数,消息挤压数量
  27 + *
  28 + * @return
  29 + */
  30 + public long getMessageReady()
  31 + {
  32 + return queueInfo.getMessagesReady();
  33 + }
  34 +
  35 + /**
  36 + * 排序参数,消息总数量
  37 + *
  38 + * @return
  39 + */
  40 + public long getTotalMessages()
  41 + {
  42 + return queueInfo.getTotalMessages();
  43 + }
  44 +}
  1 +package com.sunyo.wlpt.message.bus.service.elasticsearch.dao;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.MessageNote;
  4 +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
  5 +
  6 +/**
  7 + * @author 子诚
  8 + * Description:
  9 + * 时间:2020/8/5 14:43
  10 + */
  11 +public interface MessageNoteRepository extends ElasticsearchRepository<MessageNote, String> {
  12 +
  13 +}
  1 +package com.sunyo.wlpt.message.bus.service.exception;
  2 +
  3 +/**
  4 + * @author 子诚
  5 + * Description:
  6 + * 时间:2020/7/17 16:43
  7 + */
  8 +public class CustomException extends RuntimeException {
  9 + private static final long serialVersionUID = 6098063244016154220L;
  10 +
  11 + /**
  12 + * 异常错误编码
  13 + */
  14 + private String code;
  15 +
  16 + /**
  17 + * 异常信息
  18 + */
  19 + private String message;
  20 +
  21 + public CustomException(CustomExceptionType exceptionTypeEnum, String message) {
  22 + this.code = exceptionTypeEnum.getCode();
  23 + this.message = message;
  24 + }
  25 +
  26 + public CustomException(CustomExceptionType exceptionTypeEnum) {
  27 + this.code = exceptionTypeEnum.getCode();
  28 + this.message = exceptionTypeEnum.getMsg();
  29 + }
  30 +
  31 + public String getCode() {
  32 + return code;
  33 + }
  34 +
  35 + @Override
  36 + public String getMessage() {
  37 + return message;
  38 + }
  39 +
  40 +}
  1 +package com.sunyo.wlpt.message.bus.service.exception;
  2 +
  3 +/**
  4 + * @author 子诚
  5 + * Description:枚举,定制异常类型
  6 + * 时间:2020/7/17 16:27
  7 + */
  8 +
  9 +public enum CustomExceptionType {
  10 + MESSAGE_SUCCESS("10200", "消息发送成功"),
  11 + RECEIVE_SUCCESS("20200", "接收消息,成功!"),
  12 +
  13 + RECEIVE_SERVER_EXCEPTION("20500", "服务器异常,接收消息失败!请联系管理员处理"),
  14 + SERVER_EXCEPTION("10500", "服务器异常,发送消息失败!"),
  15 + CLIENT_EXCEPTION("10400", "报文格式错误,请检查报文格式!"),
  16 +
  17 + BINDING_ERROR("10501", "配置信息,未进行绑定!"),
  18 + SENDER_ERROR("10401", "报文格式错误,发送者不能为空!"),
  19 + CONTENT_ERROR("10402", "报文格式错误,消息内容不能为空!"),
  20 + SERVER_ERROR("10403", "报文格式错误,服务器名称不能为空!"),
  21 + HOST_ERROR("10404", "报文格式错误,虚拟主机名称不能为空!"),
  22 + EXCHANGE_ERROR("10405", "报文格式错误,交换机名称不能为空!"),
  23 + ROUTING_KEY_ERROR("10406", "报文格式错误,路由键名称不能为空!"),
  24 + SEQUENCE_ERROR("10407", "报文格式错误,序列不能为空!"),
  25 + TOKEN_ERROR("10408", "报文格式错误,token不能为空!"),
  26 +
  27 + SENDER_NO_EXIST("20401", "报文数据错误,发送者不存在!"),
  28 + SERVER_NO_EXIST("20403", "报文数据错误,服务器不存在!"),
  29 + HOST_NO_EXIST("20404", "报文数据错误,虚拟主机不存在!"),
  30 + EXCHANGE_NO_EXIST("20405", "报文数据错误,交换机不存在!"),
  31 + ROUTING_KEY_NO_EXIST("20406", "报文数据错误,路由键不存在!"),
  32 +
  33 + RECEIVE_RECEIVER_ERROR("30401", "请仔细检查,接收者不存在!"),
  34 + RECEIVE_SERVER_ERROR("30402", "参数错误,服务器名称不存在!"),
  35 + RECEIVE_HOST_ERROR("30403", "参数错误,虚拟主机名称不存在!"),
  36 + RECEIVE_QUEUE_ERROR("30404", "参数错误,队列名称不存在!"),
  37 + RECEIVE_SERVER_HOST_ERROR("30405", "请仔细检查,该虚拟主机不属于该MQ服务器!"),
  38 + RECEIVE_HOST_QUEUE_ERROR("30406", "请仔细检查,该队列不属于该虚拟主机!"),
  39 + RECEIVE_USER_SERVER_HOST_ERROR("30407", "请仔细检查,该用户无权操作此虚拟主机"),
  40 + RECEIVE_USER_QUEUE_ERROR("30408", "请仔细检查,该用户无权操作此队列"),
  41 +
  42 + RECEIVE_RECEIVER_NO_EXIST("30411", "请仔细检查,接收者不能为空!"),
  43 + RECEIVE_PASSWORD_NO_EXIST("30412", "请仔细检查,接收者不能为空!"),
  44 + RECEIVE_SERVER_NO_EXIST("30413", "参数错误,服务器名称不能为空!"),
  45 + RECEIVE_HOST_NO_EXIST("30414", "参数错误,虚拟主机名称不能为空!"),
  46 + RECEIVE_QUEUE_NO_EXIST("30415", "参数错误,队列名称不能为空!"),
  47 +
  48 +
  49 + CLIENT_ERROR("400", "客户端异常"),
  50 + SYSTEM_ERROR("500", "系统服务异常"),
  51 + OTHER_ERROR("999", "其他未知异常");
  52 +
  53 + /**
  54 + * 响应业务状态
  55 + */
  56 + private String code;
  57 + /**
  58 + * 响应消息
  59 + */
  60 + private String msg;
  61 +
  62 + CustomExceptionType(String code, String msg)
  63 + {
  64 + this.code = code;
  65 + this.msg = msg;
  66 + }
  67 +
  68 + public String getCode()
  69 + {
  70 + return code;
  71 + }
  72 +
  73 + public String getMsg()
  74 + {
  75 + return msg;
  76 + }
  77 +
  78 +}
  1 +package com.sunyo.wlpt.message.bus.service.exception;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.response.ResultJson;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import org.springframework.web.bind.annotation.ExceptionHandler;
  7 +import org.springframework.web.bind.annotation.ResponseBody;
  8 +
  9 +/**
  10 + * @author 子诚
  11 + * Description:自定义全局异常处理类
  12 + * 时间:2020/7/17 17:44
  13 + */
  14 +//@ControllerAdvice
  15 +public class GlobalExceptionHandler {
  16 + private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
  17 +
  18 + //处理程序员主动转换的自定义异常
  19 + @ExceptionHandler(CustomException.class)
  20 + @ResponseBody
  21 + public ResultJson customerException(CustomException e) {
  22 + if(e.getCode() == CustomExceptionType.SYSTEM_ERROR.getCode()){
  23 + //400异常不需要持久化,将异常信息以友好的方式告知用户就可以
  24 +
  25 + //TODO 将500异常信息持久化处理,方便运维人员处理
  26 + logger.error("");
  27 + }
  28 + return ResultJson.error(e);
  29 + }
  30 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.BusExchange;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * @author 子诚
  10 + * Description:
  11 + * 时间:2020/7/1 10:08
  12 + */
  13 +@Mapper
  14 +public interface BusExchangeMapper {
  15 +
  16 + /**
  17 + * 删除,根据主键
  18 + *
  19 + * @param id primaryKey
  20 + * @return deleteCount
  21 + */
  22 + int deleteByPrimaryKey(String id);
  23 +
  24 + /**
  25 + * 根据虚拟主机删除交换机
  26 + *
  27 + * @param virtualHostId 虚拟主机id
  28 + * @return
  29 + */
  30 + int deleteByVirtualHostId(String virtualHostId);
  31 + /**
  32 + * 新增
  33 + *
  34 + * @param record the record
  35 + * @return insert count
  36 + */
  37 + int insert(BusExchange record);
  38 +
  39 + /**
  40 + * 新增,选择性
  41 + *
  42 + * @param record the record
  43 + * @return insert count
  44 + */
  45 + int insertSelective(BusExchange record);
  46 +
  47 + /**
  48 + * 查询,根据主键
  49 + *
  50 + * @param id primary key
  51 + * @return object by primary key
  52 + */
  53 + BusExchange selectByPrimaryKey(String id);
  54 +
  55 + /**
  56 + * 查询,根据交换机名称
  57 + *
  58 + * @param exchangeName 交换机名称
  59 + * @return
  60 + */
  61 + BusExchange selectByExchangeName(String exchangeName);
  62 +
  63 + /**
  64 + * 更新,选择性,根据主键
  65 + *
  66 + * @param record the updated record
  67 + * @return update count
  68 + */
  69 + int updateByPrimaryKeySelective(BusExchange record);
  70 +
  71 + /**
  72 + * 更新,根据主键
  73 + *
  74 + * @param record the updated record
  75 + * @return update count
  76 + */
  77 + int updateByPrimaryKey(BusExchange record);
  78 +
  79 + /**
  80 + * 查询交换机列表,选择性
  81 + *
  82 + * @param busExchange 交换机以及参数
  83 + * @return 交换机列表
  84 + */
  85 + List<BusExchange> selectBusExchangeList(BusExchange busExchange);
  86 +
  87 + /**
  88 + * 校验该服务器信息是否存在
  89 + *
  90 + * @param busExchange {@link BusExchange}
  91 + * @return List<BusExchange>
  92 + */
  93 + List<BusExchange> validateBusExchange(BusExchange busExchange);
  94 +
  95 + /**
  96 + * 仅,查询交换机列表
  97 + *
  98 + * @param busExchange {@link BusExchange}
  99 + * @return List<BusExchange>
  100 + */
  101 + List<BusExchange> getExchangeList(BusExchange busExchange);
  102 +
  103 + /**
  104 + * 检验交换机是否存在
  105 + *
  106 + * @param exchange {@link BusExchange}
  107 + * @return List<BusExchange>
  108 + */
  109 + List<BusExchange> selectExchangeExist(BusExchange exchange);
  110 +
  111 + /**
  112 + * 查询交换机列表,根据虚拟主机id
  113 + *
  114 + * @param virtualHostId 虚拟主机
  115 + * @return
  116 + */
  117 + List<BusExchange> selectByVirtualHostId(String virtualHostId);
  118 +
  119 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.BusQueue;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * @author 子诚
  11 + * Description:
  12 + * 时间:2020/7/23 17:16
  13 + */
  14 +@Mapper
  15 +public interface BusQueueMapper {
  16 + /**
  17 + * delete by primary key
  18 + *
  19 + * @param id primaryKey
  20 + * @return deleteCount
  21 + */
  22 + int deleteByPrimaryKey(String id);
  23 +
  24 + /**
  25 + * 删除队列,根据虚拟主机id
  26 + *
  27 + * @param virtualHostId 虚拟主机id
  28 + * @return
  29 + */
  30 + int deleteByVirtualHostId(String virtualHostId);
  31 +
  32 + /**
  33 + * insert record to table
  34 + *
  35 + * @param record the record
  36 + * @return insert count
  37 + */
  38 + int insert(BusQueue record);
  39 +
  40 + /**
  41 + * insert record to table selective
  42 + *
  43 + * @param record the record
  44 + * @return insert count
  45 + */
  46 + int insertSelective(BusQueue record);
  47 +
  48 + /**
  49 + * select by primary key
  50 + *
  51 + * @param id primary key
  52 + * @return object by primary key
  53 + */
  54 + BusQueue selectByPrimaryKey(String id);
  55 +
  56 + /**
  57 + * 根据虚拟主机id,查询队列列表
  58 + *
  59 + * @param virtualHostId 虚拟主机id
  60 + * @return
  61 + */
  62 + List<BusQueue> selectByVirtualHostId(String virtualHostId);
  63 +
  64 + /**
  65 + * update record selective
  66 + *
  67 + * @param record the updated record
  68 + * @return update count
  69 + */
  70 + int updateByPrimaryKeySelective(BusQueue record);
  71 +
  72 + /**
  73 + * update record
  74 + *
  75 + * @param record the updated record
  76 + * @return update count
  77 + */
  78 + int updateByPrimaryKey(BusQueue record);
  79 +
  80 + /**
  81 + * 查询,消息队列列表,选择性
  82 + *
  83 + * @param busQueue 消息队列 {@link BusQueue}
  84 + * @return List<BusQueue>
  85 + */
  86 + List<BusQueue> selectBusQueueList(BusQueue busQueue);
  87 +
  88 + /**
  89 + * 校验-消息队列,是否已存在
  90 + *
  91 + * @param busQueue {@link BusQueue}
  92 + * @return List<BusQueue>
  93 + */
  94 + List<BusQueue> validateBusQueue(BusQueue busQueue);
  95 +
  96 + /**
  97 + * 校验队列是否存在,根据用户名以及队列名称
  98 + *
  99 + * @param username 用户名称
  100 + * @param queueName 队列名称
  101 + * @return
  102 + */
  103 + List<BusQueue> validateByUserNameAndQueueName(@Param("username") String username, @Param("queueName") String queueName);
  104 +
  105 + /**
  106 + * 仅,查询队列列表
  107 + *
  108 + * @param busQueue {@link BusQueue}
  109 + * @return
  110 + */
  111 + List<BusQueue> getQueueList(BusQueue busQueue);
  112 +
  113 + /**
  114 + * 根据用户名称查询队列信息
  115 + *
  116 + * @param username 用户名称
  117 + * @return
  118 + */
  119 + List<BusQueue> selectByUsername(String username);
  120 +
  121 + /**
  122 + * 根据用户名查询队列信息
  123 + *
  124 + * @param queueName 队列名称
  125 + * @return
  126 + */
  127 + BusQueue selectByQueueName(@Param("queueName") String queueName);
  128 +
  129 + /**
  130 + * 根据用户名称和虚拟主机Id查询队列信息
  131 + *
  132 + * @param username 用户名称
  133 + * @param virtualHostId 虚拟主机Id
  134 + * @return
  135 + */
  136 + List<BusQueue> selectByUsernameAndHostId(@Param("username") String username, @Param("virtualHostId") String virtualHostId);
  137 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.BusServer;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * @author 子诚
  11 + * Description:
  12 + * 时间:2020/8/12 14:07
  13 + */
  14 +@Mapper
  15 +public interface BusServerMapper {
  16 + /**
  17 + * delete by primary key
  18 + *
  19 + * @param id primaryKey
  20 + * @return deleteCount
  21 + */
  22 + int deleteByPrimaryKey(String id);
  23 +
  24 + /**
  25 + * insert record to table
  26 + *
  27 + * @param record the record
  28 + * @return insert count
  29 + */
  30 + int insert(BusServer record);
  31 +
  32 + /**
  33 + * insert record to table selective
  34 + *
  35 + * @param record the record
  36 + * @return insert count
  37 + */
  38 + int insertSelective(BusServer record);
  39 +
  40 + /**
  41 + * select by primary key
  42 + *
  43 + * @param id primary key
  44 + * @return object by primary key
  45 + */
  46 + BusServer selectByPrimaryKey(String id);
  47 +
  48 + /**
  49 + * update record selective
  50 + *
  51 + * @param record the updated record
  52 + * @return update count
  53 + */
  54 + int updateByPrimaryKeySelective(BusServer record);
  55 +
  56 + /**
  57 + * update record
  58 + *
  59 + * @param record the updated record
  60 + * @return update count
  61 + */
  62 + int updateByPrimaryKey(BusServer record);
  63 +
  64 + /**
  65 + * 查询,根据服务器名称
  66 + *
  67 + * @param serverName 服务器名称
  68 + * @return
  69 + */
  70 + BusServer selectByServerName(String serverName);
  71 +
  72 + /**
  73 + * 查询服务器列表,选择性
  74 + *
  75 + * @param busServer 服务器以及参数
  76 + * @return 服务器列表
  77 + */
  78 + List<BusServer> selectBusServerList(BusServer busServer);
  79 +
  80 + /**
  81 + * 查询服务器列表(不包含密码)
  82 + *
  83 + * @return 服务器列表
  84 + */
  85 + List<BusServer> selectServerList();
  86 +
  87 + /**
  88 + * 先校验该服务器名称是否存在
  89 + *
  90 + * @param busServer {@link BusServer}
  91 + * @return List<BusServer>
  92 + */
  93 + List<BusServer> validateServerName(BusServer busServer);
  94 +
  95 + /**
  96 + * 校验该服务器名称是否存在
  97 + *
  98 + * @param serverName 服务器名称
  99 + * @return
  100 + */
  101 + List<BusServer> validateByServerName(@Param("serverName") String serverName);
  102 +
  103 + /**
  104 + * 校验该服务器信息是否存在
  105 + *
  106 + * @param busServer {@link BusServer}
  107 + * @return List<BusServer>
  108 + */
  109 + List<BusServer> validateBusServer(BusServer busServer);
  110 +
  111 + /**
  112 + * 查询服务器列表(包含密码)
  113 + *
  114 + * @return 服务器列表
  115 + */
  116 + List<BusServer> getServerList();
  117 +
  118 + /**
  119 + * 查询,服务器(1:n虚拟主机)的基本信息
  120 + *
  121 + * @return List<BusServer>
  122 + */
  123 + List<BusServer> getServerAndHostList(BusServer busServer);
  124 +
  125 + /**
  126 + * 服务器与虚拟主机是1:n的关系
  127 + * 虚拟主机与交换机是1: n的关系
  128 + * 查询,服务器列表(包含虚拟机、交换机)
  129 + *
  130 + * @return List<BusServer>
  131 + */
  132 + List<BusServer> getServerAndHostAndExchangeList();
  133 +
  134 + /**
  135 + * 检验用户名是否存在
  136 + *
  137 + * @param serverName 服务器名称
  138 + * @return List<BusServer>
  139 + */
  140 + List<BusServer> selectServerExist(@Param("serverName") String serverName);
  141 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.ExchangeQueueRouting;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +
  6 +/**
  7 + * @author 子诚
  8 + * Description:
  9 + * 时间:2020/7/2 16:47
  10 + */
  11 +@Mapper
  12 +public interface ExchangeQueueRoutingMapper {
  13 + /**
  14 + * 删除,根据主键
  15 + *
  16 + * @param id primaryKey
  17 + * @return deleteCount
  18 + */
  19 + int deleteByPrimaryKey(String id);
  20 +
  21 + /**
  22 + * 新增
  23 + *
  24 + * @param record the record
  25 + * @return insert count
  26 + */
  27 + int insert(ExchangeQueueRouting record);
  28 +
  29 + /**
  30 + * 新增,选择性
  31 + *
  32 + * @param record the record
  33 + * @return insert count
  34 + */
  35 + int insertSelective(ExchangeQueueRouting record);
  36 +
  37 + /**
  38 + * 查询,根据主键
  39 + *
  40 + * @param id primary key
  41 + * @return object by primary key
  42 + */
  43 + ExchangeQueueRouting selectByPrimaryKey(String id);
  44 +
  45 + /**
  46 + * 更新,根据主键,选择性
  47 + *
  48 + * @param record the updated record
  49 + * @return update count
  50 + */
  51 + int updateByPrimaryKeySelective(ExchangeQueueRouting record);
  52 +
  53 + /**
  54 + * 更新,根据主键
  55 + *
  56 + * @param record the updated record
  57 + * @return update count
  58 + */
  59 + int updateByPrimaryKey(ExchangeQueueRouting record);
  60 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.MessageNote;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * @author 子诚
  11 + * Description:
  12 + * 时间:2020/7/15 10:45
  13 + */
  14 +@Mapper
  15 +public interface MessageNoteMapper {
  16 + /**
  17 + * delete by primary key
  18 + *
  19 + * @param id primaryKey
  20 + * @return deleteCount
  21 + */
  22 + int deleteByPrimaryKey(String id);
  23 +
  24 + /**
  25 + * insert record to table
  26 + *
  27 + * @param record the record
  28 + * @return insert count
  29 + */
  30 + int insert(MessageNote record);
  31 +
  32 + /**
  33 + * insert record to table selective
  34 + *
  35 + * @param record the record
  36 + * @return insert count
  37 + */
  38 + int insertSelective(MessageNote record);
  39 +
  40 + /**
  41 + * select by primary key
  42 + *
  43 + * @param id primary key
  44 + * @return object by primary key
  45 + */
  46 + MessageNote selectByPrimaryKey(String id);
  47 +
  48 + /**
  49 + * update record selective
  50 + *
  51 + * @param record the updated record
  52 + * @return update count
  53 + */
  54 + int updateByPrimaryKeySelective(MessageNote record);
  55 +
  56 + /**
  57 + * update record
  58 + *
  59 + * @param record the updated record
  60 + * @return update count
  61 + */
  62 + int updateByPrimaryKey(MessageNote record);
  63 +
  64 + /**
  65 + * 获取,消息收发记录-列表
  66 + *
  67 + * @param messageNote {@link MessageNote}
  68 + * @return List<MessageNote>
  69 + */
  70 + List<MessageNote> selectMessageNoteList(MessageNote messageNote);
  71 +
  72 + /**
  73 + * 自动删除消息收发记录
  74 + *
  75 + * @param deleteTime 删除的时间
  76 + */
  77 + void autoDelete(@Param("deleteTime") Integer deleteTime);
  78 +
  79 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.RoutingKey;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import java.util.List;
  8 +
  9 +/**
  10 + * @author 子诚
  11 + * Description:
  12 + * 时间:2020/6/29 16:45
  13 + */
  14 +@Mapper
  15 +public interface RoutingKeyMapper {
  16 +
  17 + /**
  18 + * 删除,根据主键
  19 + *
  20 + * @param id primaryKey
  21 + * @return deleteCount
  22 + */
  23 + int deleteByPrimaryKey(String id);
  24 +
  25 + /**
  26 + * 新增
  27 + *
  28 + * @param record the record
  29 + * @return insert count
  30 + */
  31 + int insert(RoutingKey record);
  32 +
  33 + /**
  34 + * 新增,选择性
  35 + *
  36 + * @param record the record
  37 + * @return insert count
  38 + */
  39 + int insertSelective(RoutingKey record);
  40 +
  41 + /**
  42 + * 查询,根据主键
  43 + *
  44 + * @param id primary key
  45 + * @return object by primary key
  46 + */
  47 + RoutingKey selectByPrimaryKey(String id);
  48 +
  49 + /**
  50 + * 查询,根据路由键名称
  51 + *
  52 + * @param routingKeyName 路由键名称
  53 + * @return
  54 + */
  55 + RoutingKey selectByRoutingKeyName(String routingKeyName);
  56 +
  57 + /**
  58 + * 更新,选择性,根据主键
  59 + *
  60 + * @param record the updated record
  61 + * @return update count
  62 + */
  63 + int updateByPrimaryKeySelective(RoutingKey record);
  64 +
  65 + /**
  66 + * 更新,根据主键
  67 + *
  68 + * @param record the updated record
  69 + * @return update count
  70 + */
  71 + int updateByPrimaryKey(RoutingKey record);
  72 +
  73 + /**
  74 + * 查询,路由键列表,选择性
  75 + *
  76 + * @param routingKey 路由键参数类
  77 + * @return List<RoutingKey> {@link RoutingKey}
  78 + */
  79 + List<RoutingKey> selectRoutingKeyList(RoutingKey routingKey);
  80 +
  81 + /**
  82 + * 校验,路由键是否已存在
  83 + *
  84 + * @param routingKey 路由键 {@link RoutingKey}
  85 + * @return List<RoutingKey>
  86 + */
  87 + List<RoutingKey> validateRoutingKey(RoutingKey routingKey);
  88 +
  89 + /**
  90 + * 仅,查询路由键列表
  91 + *
  92 + * @param routingKey 路由键 {@link RoutingKey}
  93 + * @return List<RoutingKey>
  94 + */
  95 + List<RoutingKey> getRoutingKeyList(RoutingKey routingKey);
  96 +
  97 + /**
  98 + * 根据exchangeID查询路由键
  99 + *
  100 + * @param exchangeId 交换机id
  101 + * @return
  102 + */
  103 + List<RoutingKey> selectByExchangeId(@Param("exchangeId") String exchangeId);
  104 +
  105 + /**
  106 + * 检验路由键是否存在,根据交换机id和路由键名称
  107 + *
  108 + * @param routingKey 路由键
  109 + * @return List<RoutingKey>
  110 + */
  111 + List<RoutingKey> selectRoutingKeyExist(RoutingKey routingKey);
  112 +
  113 + /**
  114 + * 根据交换机id,删除路由键信息
  115 + *
  116 + * @param exchangeId 交换机id
  117 + * @return
  118 + */
  119 + int deleteByExchangeId(String exchangeId);
  120 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.SchedulingDelete;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +/**
  8 + * @author 子诚
  9 + * Description:
  10 + * 时间:2020/7/15 10:28
  11 + */
  12 +@Mapper
  13 +public interface SchedulingDeleteMapper {
  14 + /**
  15 + * delete by primary key
  16 + *
  17 + * @param id primaryKey
  18 + * @return deleteCount
  19 + */
  20 + int deleteByPrimaryKey(String id);
  21 +
  22 + /**
  23 + * insert record to table
  24 + *
  25 + * @param record the record
  26 + * @return insert count
  27 + */
  28 + int insert(SchedulingDelete record);
  29 +
  30 + /**
  31 + * insert record to table selective
  32 + *
  33 + * @param record the record
  34 + * @return insert count
  35 + */
  36 + int insertSelective(SchedulingDelete record);
  37 +
  38 + /**
  39 + * select by primary key
  40 + *
  41 + * @param id primary key
  42 + * @return object by primary key
  43 + */
  44 + SchedulingDelete selectByPrimaryKey(String id);
  45 +
  46 + /**
  47 + * update record selective
  48 + *
  49 + * @param record the updated record
  50 + * @return update count
  51 + */
  52 + int updateByPrimaryKeySelective(SchedulingDelete record);
  53 +
  54 + /**
  55 + * update record
  56 + *
  57 + * @param record the updated record
  58 + * @return update count
  59 + */
  60 + int updateByPrimaryKey(SchedulingDelete record);
  61 +
  62 + /**
  63 + * 获取时间设置表
  64 + *
  65 + * @param deleteType 删除的类型
  66 + * @return {@link SchedulingDelete}
  67 + */
  68 + SchedulingDelete selectByType(@Param("deleteType") String deleteType);
  69 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.BusQueue;
  4 +import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
  5 +import org.apache.ibatis.annotations.Mapper;
  6 +import org.apache.ibatis.annotations.Param;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * @author 子诚
  12 + * Description:
  13 + * 时间:2020/8/10 17:44
  14 + */
  15 +@Mapper
  16 +public interface UserInfoMapper {
  17 +
  18 + /**
  19 + * delete by primary key
  20 + *
  21 + * @param id primaryKey
  22 + * @return deleteCount
  23 + */
  24 + int deleteByPrimaryKey(String id);
  25 +
  26 + /**
  27 + * insert record to table
  28 + *
  29 + * @param record the record
  30 + * @return insert count
  31 + */
  32 + int insert(UserInfo record);
  33 +
  34 + /**
  35 + * insert record to table selective
  36 + *
  37 + * @param record the record
  38 + * @return insert count
  39 + */
  40 + int insertSelective(UserInfo record);
  41 +
  42 + /**
  43 + * select by primary key
  44 + *
  45 + * @param id primary key
  46 + * @return object by primary key
  47 + */
  48 + UserInfo selectByPrimaryKey(String id);
  49 +
  50 + /**
  51 + * update record selective
  52 + *
  53 + * @param record the updated record
  54 + * @return update count
  55 + */
  56 + int updateByPrimaryKeySelective(UserInfo record);
  57 +
  58 + /**
  59 + * update record
  60 + *
  61 + * @param record the updated record
  62 + * @return update count
  63 + */
  64 + int updateByPrimaryKey(UserInfo record);
  65 +
  66 + /**
  67 + * 查询,根据用户名称
  68 + *
  69 + * @param username 用户登录名称
  70 + * @return {@link UserInfo}
  71 + */
  72 + List<UserInfo> selectByUsername(String username);
  73 +
  74 + /**
  75 + * 仅,查询用户列表
  76 + *
  77 + * @return 用户信息集合
  78 + */
  79 + List<UserInfo> getUserInfoList();
  80 +
  81 + /**
  82 + * 判断该用户名是否存在
  83 + *
  84 + * @param username 用户登录名
  85 + * @return 用户列表
  86 + */
  87 + List<UserInfo> selectUserExist(@Param("username") String username);
  88 +
  89 + /**
  90 + * 分页查询用户信息
  91 + *
  92 + * @param userInfo 用户信息 {@link UserInfo}
  93 + * @return
  94 + */
  95 + List<UserInfo> selectUserInfoList(UserInfo userInfo);
  96 +
  97 + /**
  98 + * 校验用户信息
  99 + *
  100 + * @param userInfo 用户信息 {@link UserInfo}
  101 + * @return
  102 + */
  103 + List<UserInfo> validateUserInfo(UserInfo userInfo);
  104 +
  105 + /**
  106 + * 校验用户信息
  107 + *
  108 + * @param username 用户名称
  109 + * @param serverName 服务器名称
  110 + * @param virtualHostName 虚拟主机名称
  111 + * @return
  112 + */
  113 + List<UserInfo> validateUserInfoByParams(@Param("username") String username,
  114 + @Param("serverName") String serverName,
  115 + @Param("virtualHostName") String virtualHostName);
  116 +
  117 + /**
  118 + * 根据队列中的用户名,虚拟主机名称和虚拟主机id,查询用户关系
  119 + *
  120 + * @param busQueue {@link BusQueue}
  121 + * @return
  122 + */
  123 + List<UserInfo> selectByBusQueue(BusQueue busQueue);
  124 +
  125 + /**
  126 + * 根据用户名称删除用户信息
  127 + *
  128 + * @param username
  129 + * @return
  130 + */
  131 + int deleteByUsername(String username);
  132 +
  133 + /**
  134 + * 根据用户名称和服务器名称删除用户信息
  135 + *
  136 + * @param username 用户名称
  137 + * @param serverName 服务器名称
  138 + * @return
  139 + */
  140 + int deleteByUsernameAndServerName(@Param("username") String username, @Param("serverName") String serverName);
  141 +
  142 + /**
  143 + * 根据服务器名称,删除用户关系
  144 + *
  145 + * @param serverName 服务器名称
  146 + * @return
  147 + */
  148 + int deleteByServerName(String serverName);
  149 +
  150 + /**
  151 + * 根据虚拟主机名称,删除用户关系
  152 + *
  153 + * @param hostName 虚拟主机名称
  154 + * @return
  155 + */
  156 + int deleteByHostName(String hostName);
  157 +
  158 + /**
  159 + * 根据用户名称和服务器名称,查询用户信息
  160 + *
  161 + * @param username 用户名称
  162 + * @param serverName 服务器名称
  163 + * @return
  164 + */
  165 + List<UserInfo> selectByUsernameAndServerName(@Param("username") String username, @Param("serverName") String serverName);
  166 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.MessageNote;
  4 +import com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding;
  5 +import com.sunyo.wlpt.message.bus.service.domain.XmlData;
  6 +import org.apache.ibatis.annotations.Mapper;
  7 +
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * @author 子诚
  12 + * Description:
  13 + * 时间:2020/7/15 10:37
  14 + */
  15 +@Mapper
  16 +public interface UserMessageBindingMapper {
  17 + /**
  18 + * delete by primary key
  19 + *
  20 + * @param id primaryKey
  21 + * @return deleteCount
  22 + */
  23 + int deleteByPrimaryKey(String id);
  24 +
  25 + /**
  26 + * 根据交换机id删除配置关系
  27 + *
  28 + * @param exchangeId 交换机id
  29 + * @return 删除成功
  30 + */
  31 + int deleteByExchangeId(String exchangeId);
  32 +
  33 + /**
  34 + * 根据队列Id,删除绑定关系
  35 + *
  36 + * @param queueId 队列id
  37 + * @return
  38 + */
  39 + int deleteByQueueId(String queueId);
  40 +
  41 + /**
  42 + * 根据路由键id删除配置关系
  43 + *
  44 + * @param routingKeyId 路由键id
  45 + * @return 删除成功
  46 + */
  47 + int deleteByRoutingKeyId(String routingKeyId);
  48 +
  49 + /**
  50 + * 删除配置关系
  51 + *
  52 + * @param virtualHostId 虚拟主机id
  53 + * @return
  54 + */
  55 + int deleteByVirtualHostId(String virtualHostId);
  56 +
  57 + /**
  58 + * 根据服务器id,删除绑定关系
  59 + *
  60 + * @param serverId 服务器id
  61 + * @return
  62 + */
  63 + int deleteByServerId(String serverId);
  64 +
  65 + /**
  66 + * insert record to table
  67 + *
  68 + * @param record the record
  69 + * @return insert count
  70 + */
  71 + int insert(UserMessageBinding record);
  72 +
  73 + /**
  74 + * insert record to table selective
  75 + *
  76 + * @param record the record
  77 + * @return insert count
  78 + */
  79 + int insertSelective(UserMessageBinding record);
  80 +
  81 + /**
  82 + * select by primary key
  83 + *
  84 + * @param id primary key
  85 + * @return object by primary key
  86 + */
  87 + UserMessageBinding selectByPrimaryKey(String id);
  88 +
  89 + /**
  90 + * 根据路由键id
  91 + *
  92 + * @param routingKeyId 路由键id
  93 + * @return
  94 + */
  95 + List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId);
  96 +
  97 + /**
  98 + * 根据虚拟主机id,查询配置关系列表
  99 + *
  100 + * @param virtualHostId 虚拟主机id
  101 + * @return List<UserMessageBinding>
  102 + */
  103 + List<UserMessageBinding> selectByVirtualHostId(String virtualHostId);
  104 +
  105 + /**
  106 + * 根据服务器id,查询配置关系列表
  107 + *
  108 + * @param serverId 服务器id
  109 + * @return List<UserMessageBinding>
  110 + */
  111 + List<UserMessageBinding> selectByServerId(String serverId);
  112 +
  113 + /**
  114 + * update record selective
  115 + *
  116 + * @param record the updated record
  117 + * @return update count
  118 + */
  119 + int updateByPrimaryKeySelective(UserMessageBinding record);
  120 +
  121 + /**
  122 + * update record
  123 + *
  124 + * @param record the updated record
  125 + * @return update count
  126 + */
  127 + int updateByPrimaryKey(UserMessageBinding record);
  128 +
  129 + /**
  130 + * 分页查询,获取账户信息绑定配置列表
  131 + *
  132 + * @param userMessageBinding {@link UserMessageBinding}
  133 + * @return List<UserMessageBinding>
  134 + */
  135 + List<UserMessageBinding> selectUserMessageBindingList(UserMessageBinding userMessageBinding);
  136 +
  137 + /**
  138 + * 在执行填充和添加之前先校验一下是否存在?
  139 + *
  140 + * @param userMessageBinding {@link UserMessageBinding}
  141 + * @return 判断校验是否通过
  142 + */
  143 + List<UserMessageBinding> validateBinding(UserMessageBinding userMessageBinding);
  144 +
  145 + /**
  146 + * 发送信息之前的检验配置是否存在
  147 + *
  148 + * @param messageNote {@link MessageNote}
  149 + * @return 判断校验是否通过
  150 + */
  151 + List<UserMessageBinding> validateNote(MessageNote messageNote);
  152 +
  153 +
  154 + /**
  155 + * 校验报文配置与否?
  156 + *
  157 + * @param xmlData {@link XmlData}
  158 + * @return 判断校验是否通过
  159 + */
  160 + List<UserMessageBinding> validateXmlBinding(XmlData xmlData);
  161 +
  162 + /**
  163 + * 进行校验该MQ上的绑定关系,是否存在
  164 + *
  165 + * @param userMessageBinding {@link UserMessageBinding}
  166 + * @return 配置关系,集合
  167 + */
  168 + List<UserMessageBinding> validateRabbitBinding(UserMessageBinding userMessageBinding);
  169 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.UserServerVirtualHost;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +
  6 +/**
  7 + * @author 子诚
  8 + * Description:
  9 + * 时间:2020/7/2 11:35
  10 + */
  11 +@Mapper
  12 +public interface UserServerVirtualHostMapper {
  13 + /**
  14 + * 删除,根据主键
  15 + *
  16 + * @param id primaryKey
  17 + * @return deleteCount
  18 + */
  19 + int deleteByPrimaryKey(String id);
  20 +
  21 + /**
  22 + * 新增
  23 + *
  24 + * @param record the record
  25 + * @return insert count
  26 + */
  27 + int insert(UserServerVirtualHost record);
  28 +
  29 + /**
  30 + * 新增,选择性
  31 + *
  32 + * @param record the record
  33 + * @return insert count
  34 + */
  35 + int insertSelective(UserServerVirtualHost record);
  36 +
  37 + /**
  38 + * 查询,根据主键
  39 + *
  40 + * @param id primary key
  41 + * @return object by primary key
  42 + */
  43 + UserServerVirtualHost selectByPrimaryKey(String id);
  44 +
  45 + /**
  46 + * 更新,选择性,根据主键
  47 + *
  48 + * @param record the updated record
  49 + * @return update count
  50 + */
  51 + int updateByPrimaryKeySelective(UserServerVirtualHost record);
  52 +
  53 + /**
  54 + * 更新,根据主键
  55 + *
  56 + * @param record the updated record
  57 + * @return update count
  58 + */
  59 + int updateByPrimaryKey(UserServerVirtualHost record);
  60 +}
  1 +package com.sunyo.wlpt.message.bus.service.mapper;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.VirtualHost;
  4 +import org.apache.ibatis.annotations.Mapper;
  5 +
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * @author 子诚
  10 + * Description:
  11 + * 时间:2020/6/29 16:36
  12 + */
  13 +@Mapper
  14 +public interface VirtualHostMapper {
  15 +
  16 + /**
  17 + * 删除,根据主键
  18 + *
  19 + * @param id primaryKey
  20 + * @return deleteCount
  21 + */
  22 + int deleteByPrimaryKey(String id);
  23 +
  24 + /**
  25 + * 根据服务器id,删除虚拟主机
  26 + *
  27 + * @param serverId 服务器id
  28 + * @return
  29 + */
  30 + int deleteByServerId(String serverId);
  31 +
  32 + /**
  33 + * 新增
  34 + *
  35 + * @param record the record
  36 + * @return insert count
  37 + */
  38 + int insert(VirtualHost record);
  39 +
  40 + /**
  41 + * 新增,选择性
  42 + *
  43 + * @param record the record
  44 + * @return insert count
  45 + */
  46 + int insertSelective(VirtualHost record);
  47 +
  48 + /**
  49 + * 查询,根据主键
  50 + *
  51 + * @param id primary key
  52 + * @return object by primary key
  53 + */
  54 + VirtualHost selectByPrimaryKey(String id);
  55 +
  56 + /**
  57 + * 查询,根据虚拟主机名称
  58 + *
  59 + * @param virtualHostName 虚拟主机名称
  60 + * @return
  61 + */
  62 + VirtualHost selectByVirtualHostName(String virtualHostName);
  63 +
  64 + /**
  65 + * 根据服务器id,查询虚拟主机列表
  66 + *
  67 + * @param serverId 服务器id
  68 + * @return
  69 + */
  70 + List<VirtualHost> selectByServerId(String serverId);
  71 +
  72 + /**
  73 + * 更新,选择性,根据主键
  74 + *
  75 + * @param record the updated record
  76 + * @return update count
  77 + */
  78 + int updateByPrimaryKeySelective(VirtualHost record);
  79 +
  80 + /**
  81 + * 更新,根据主键
  82 + *
  83 + * @param record the updated record
  84 + * @return update count
  85 + */
  86 + int updateByPrimaryKey(VirtualHost record);
  87 +
  88 + /**
  89 + * 查询虚拟主机列表,选择性
  90 + *
  91 + * @param virtualHost 虚拟主机,参数
  92 + * @return 虚拟主机列表
  93 + */
  94 + List<VirtualHost> selectVirtualHostList(VirtualHost virtualHost);
  95 +
  96 + /**
  97 + * 校验该服务器信息是否存在
  98 + *
  99 + * @param virtualHost {@link VirtualHost}
  100 + * @return List<VirtualHost>
  101 + */
  102 + List<VirtualHost> validateVirtualHost(VirtualHost virtualHost);
  103 +
  104 + /**
  105 + * 查询虚拟主机列表
  106 + *
  107 + * @param virtualHost {@link VirtualHost}
  108 + * @return 虚拟主机列表
  109 + */
  110 + List<VirtualHost> getVirtualHostList(VirtualHost virtualHost);
  111 +
  112 + /**
  113 + * 检验是否存在
  114 + * @param virtualHost {@link VirtualHost}
  115 + * @return List<VirtualHost>
  116 + */
  117 + List<VirtualHost> selectVirtualHostExist(VirtualHost virtualHost);
  118 +}
  1 +package com.sunyo.wlpt.message.bus.service.rabbit.utils;
  2 +
  3 +import com.sunyo.wlpt.message.bus.service.domain.BusExchange;
  4 +import com.sunyo.wlpt.message.bus.service.domain.BusQueue;
  5 +import com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import org.springframework.amqp.core.*;
  8 +import org.springframework.amqp.rabbit.core.RabbitTemplate;
  9 +import org.springframework.cloud.context.config.annotation.RefreshScope;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import javax.annotation.Resource;
  13 +
  14 +/**
  15 + * @author 子诚
  16 + * Description:
  17 + * 时间:2020/7/16 16:32
  18 + */
  19 +@Slf4j
  20 +@RefreshScope
  21 +@Component
  22 +public class BootRabbitUtils {
  23 + @Resource
  24 + private AmqpAdmin amqpAdmin;
  25 +
  26 + @Resource
  27 + private RabbitTemplate rabbitTemplate;
  28 +
  29 + /**
  30 + * 创建交换机(交换机名称,是否持久化,是否删除)
  31 + *
  32 + * @param busExchange {@link BusExchange}
  33 + */
  34 + public void createExchange(BusExchange busExchange) {
  35 +
  36 + // 类型-直连路由
  37 + String type_direct = "direct";
  38 + // 类型-动态路由
  39 + String type_topic = "topic";
  40 + // 类型-广播
  41 + String type_fanout = "fanout";
  42 + // 类型-头部
  43 + String type_headers = "headers";
  44 +
  45 + // 创建交换机,直连接类型
  46 + if (type_direct.equals(busExchange.getExchangeType())) {
  47 + amqpAdmin.declareExchange(
  48 + new DirectExchange(busExchange.getExchangeName(), busExchange.getDurability(), busExchange.getAutoDelete())
  49 + );
  50 + log.info("创建了交换机:{};类型:{};", busExchange.getExchangeType(), type_direct);
  51 + }
  52 + // 创建交换机,扇形交换机
  53 + if (type_topic.equals(busExchange.getExchangeType())) {
  54 + amqpAdmin.declareExchange(
  55 + new TopicExchange(busExchange.getExchangeName(), busExchange.getDurability(), busExchange.getAutoDelete())
  56 + );
  57 + log.info("创建了交换机:{};类型:{};", busExchange.getExchangeType(), type_topic);
  58 + }
  59 + // 创建交换机,广播(主题)交换机
  60 + if (type_fanout.equals(busExchange.getExchangeType())) {
  61 + amqpAdmin.declareExchange(
  62 + new FanoutExchange(busExchange.getExchangeName(), busExchange.getDurability(), busExchange.getAutoDelete())
  63 + );
  64 + log.info("创建了交换机:{};类型:{};", busExchange.getExchangeType(), type_fanout);
  65 + }
  66 + // 创建交换机,首部交换机
  67 + if (type_headers.equals(busExchange.getExchangeType())) {
  68 + amqpAdmin.declareExchange(
  69 + new HeadersExchange(busExchange.getExchangeName(), busExchange.getDurability(), busExchange.getAutoDelete())
  70 + );
  71 + log.info("创建了交换机:{};类型:{};", busExchange.getExchangeType(), type_headers);
  72 + }
  73 + }
  74 +
  75 + /**
  76 + * 创建交换机,通过 exchangeName 创建
  77 + */
  78 + public void createExchange(String exchangeName) {
  79 + amqpAdmin.declareExchange(
  80 + new DirectExchange(exchangeName)
  81 + );
  82 + log.info("创建了交换机:{};类型:{};", exchangeName, "DirectExchange");
  83 + }
  84 +
  85 + /**
  86 + * 根据交换机名称,删除虚拟机
  87 + *
  88 + * @param exchangeName 交换机名称
  89 + */
  90 + public void deleteExchange(String exchangeName) {
  91 + boolean flag = amqpAdmin.deleteExchange(exchangeName);
  92 + }
  93 +
  94 + /**
  95 + * 创建队列
  96 + *
  97 + * @param busQueue {@link BusQueue}
  98 + */
  99 + public void createQueue(BusQueue busQueue) {
  100 + amqpAdmin.declareQueue(
  101 + new Queue(busQueue.getQueueName(), busQueue.getDurability(), false, busQueue.getAutoDelete())
  102 + );
  103 + log.info("创建了队列,队列名称->{}", busQueue.getQueueName());
  104 + }
  105 +
  106 + /**
  107 + * 创建队列
  108 + *
  109 + * @param queueName 队列名称
  110 + */
  111 + public void createQueue(String queueName) {
  112 + amqpAdmin.declareQueue(
  113 + new Queue(queueName)
  114 + );
  115 + log.info("创建了队列,队列名称->{}", queueName);
  116 + }
  117 +
  118 + /**
  119 + * 删除队列,根据队列名称
  120 + *
  121 + * @param queueName 队列名称
  122 + */
  123 + public void deleteQueue(String queueName) {
  124 + boolean flag = amqpAdmin.deleteQueue(queueName);
  125 + }
  126 +
  127 + /**
  128 + * 创建绑定关系
  129 + *
  130 + * @param userMessageBinding {@link UserMessageBinding}
  131 + */
  132 + public void createBing(UserMessageBinding userMessageBinding) {
  133 + amqpAdmin.declareBinding(
  134 + new Binding(userMessageBinding.getQueueName(), Binding.DestinationType.QUEUE, userMessageBinding.getExchangeName(), userMessageBinding.getRoutingKeyName(), null)
  135 + );
  136 + log.info("创建了绑定关系,交换机->{};队列->{};路由键->{}", userMessageBinding.getQueueName(), userMessageBinding.getExchangeName(), userMessageBinding.getRoutingKeyName());
  137 + }
  138 +
  139 + /**
  140 + * 创建绑定关系
  141 + *
  142 + * @param exchangeName 交换机名称
  143 + * @param queueName 队列名称
  144 + * @param routingKeyName 路由键名称
  145 + */
  146 + public void createBing(String exchangeName, String queueName, String routingKeyName) {
  147 + amqpAdmin.declareBinding(
  148 + new Binding(queueName, Binding.DestinationType.QUEUE, exchangeName, routingKeyName, null)
  149 + );
  150 + log.info("创建了绑定关系,交换机->{};队列->{};路由键->{}", exchangeName, queueName, routingKeyName);
  151 + }
  152 +}
  1 +package com.sunyo.wlpt.message.bus.service.rabbit.utils;
  2 +
  3 +import com.rabbitmq.http.client.Client;
  4 +import com.rabbitmq.http.client.domain.ExchangeInfo;
  5 +import com.rabbitmq.http.client.domain.ExchangeMessageStats;
  6 +import com.rabbitmq.http.client.domain.QueueInfo;
  7 +import com.rabbitmq.http.client.domain.UserPermissions;
  8 +import com.sunyo.wlpt.message.bus.service.domain.BusServer;
  9 +import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
  10 +import com.sunyo.wlpt.message.bus.service.domain.VirtualHost;
  11 +import com.sunyo.wlpt.message.bus.service.domain.view.TempExchangeInfo;
  12 +import com.sunyo.wlpt.message.bus.service.domain.view.ViewExchangeInfo;
  13 +import com.sunyo.wlpt.message.bus.service.domain.view.ViewQueueInfo;
  14 +import com.sunyo.wlpt.message.bus.service.utils.AESUtils;
  15 +import org.apache.ibatis.reflection.MetaObject;
  16 +import org.apache.ibatis.reflection.SystemMetaObject;
  17 +
  18 +import java.io.IOException;
  19 +import java.net.URISyntaxException;
  20 +import java.util.ArrayList;
  21 +import java.util.List;
  22 +
  23 +/**
  24 + * @author 子诚
  25 + * Description:com.rabbitmq.http.client的封装类
  26 + * 时间:2020/8/13 17:57
  27 + */
  28 +public class ClientUtils {
  29 +
  30 + public static Client connectClient(BusServer busServer) throws IOException, URISyntaxException
  31 + {
  32 + // 服务器的IP地址
  33 + String host = busServer.getServerIp();
  34 + // 该服务器超级用户的用户名称
  35 + String superUsername = busServer.getSuperUsername();
  36 + // 该服务器超级用户的用户密码
  37 + String superPassword = AESUtils.decrypt(busServer.getSuperPassword());
  38 +
  39 + // 服务器的客户端端口号
  40 + String clientPort = busServer.getClientPort().toString();
  41 + // 访问客户端的url
  42 + String url = "http://" + host + ":" + clientPort + "/api";
  43 + Client client = new Client(url, superUsername, superPassword);
  44 + return client;
  45 + }
  46 +
  47 + /**
  48 + * 创建MQ用户
  49 + *
  50 + * @param userInfo 用户信息
  51 + * @param busServer {@link BusServer}
  52 + * @param password 新增用户的密码
  53 + */
  54 + public static void addRabbitUser(UserInfo userInfo, BusServer busServer, String password) throws IOException, URISyntaxException
  55 + {
  56 + // 新增用户的用户名称
  57 + String username = userInfo.getUsername();
  58 +
  59 + // 与客户端建立连接
  60 + Client client = connectClient(busServer);
  61 + ArrayList<String> list = new ArrayList<>();
  62 + // 创建用户,权限为none
  63 + client.createUser(username, password.toCharArray(), list);
  64 + }
  65 +
  66 + /**
  67 + * 用户与虚拟主机建立联系
  68 + *
  69 + * @param userInfo 用户信息
  70 + * @param busServer 服务器信息
  71 + * @throws IOException
  72 + * @throws URISyntaxException
  73 + */
  74 + public static void userRelation(UserInfo userInfo, BusServer busServer) throws IOException, URISyntaxException
  75 + {
  76 + String username = userInfo.getUsername();
  77 + String virtualHostName = userInfo.getVirtualHostName();
  78 + Client client = connectClient(busServer);
  79 +
  80 + UserPermissions p = new UserPermissions();
  81 + p.setConfigure(username + ".*");
  82 + p.setRead(username + ".*");
  83 + p.setWrite(username + ".*");
  84 + client.updatePermissions(virtualHostName, username, p);
  85 +
  86 +// TopicPermissions topicPermissions = new TopicPermissions();
  87 +// topicPermissions.setVhost(virtualHostName);
  88 +// topicPermissions.setExchange("");
  89 +// topicPermissions.setRead(".*");
  90 +// topicPermissions.setWrite(".*");
  91 +// client.updateTopicPermissions(virtualHostName, username, topicPermissions);
  92 + }
  93 +
  94 + /**
  95 + * 删除用户
  96 + */
  97 + public static void deleteMQUser(UserInfo userInfo, BusServer busServer) throws IOException, URISyntaxException
  98 + {
  99 + String username = userInfo.getUsername();
  100 + Client client = connectClient(busServer);
  101 + client.deleteUser(username);
  102 + }
  103 +
  104 + /**
  105 + * 删除用户
  106 + */
  107 + public static void deleteMQUser(String username, BusServer busServer) throws IOException, URISyntaxException
  108 + {
  109 + Client client = connectClient(busServer);
  110 + client.deleteUser(username);
  111 + }
  112 +
  113 + /**
  114 + * 修改MQ的用户密码
  115 + */
  116 + public static void updatePassword(BusServer busServer, String username, String password) throws IOException, URISyntaxException
  117 + {
  118 + char[] newPassword = password.toCharArray();
  119 + Client client = connectClient(busServer);
  120 + ArrayList<String> tags = new ArrayList<>();
  121 + client.updateUser(username, newPassword, tags);
  122 + }
  123 +
  124 + /**
  125 + * 创建虚拟主机
  126 + */
  127 + public static void createVirtualHost(BusServer busServer, String vHost) throws IOException, URISyntaxException
  128 + {
  129 + Client client = connectClient(busServer);
  130 + client.createVhost(vHost);
  131 + }
  132 +
  133 + /**
  134 + * 创建虚拟主机
  135 + */
  136 + public static void createVirtualHost(BusServer busServer, VirtualHost vHost) throws IOException, URISyntaxException
  137 + {
  138 + Client client = connectClient(busServer);
  139 + client.createVhost(vHost.getVirtualHostName(), vHost.getDescription());
  140 + }
  141 +
  142 + /**
  143 + * 删除虚拟主机
  144 + */
  145 + public static void deleteVirtualHost(BusServer busServer, String vHost) throws IOException, URISyntaxException
  146 + {
  147 + Client client = connectClient(busServer);
  148 + client.deleteVhost(vHost);
  149 + }
  150 +
  151 + /**
  152 + * 清楚用户与虚拟主机之间的关系
  153 + */
  154 + public static void clearPermissions(BusServer busServer, String vHost, String username) throws IOException, URISyntaxException
  155 + {
  156 + Client client = connectClient(busServer);
  157 + client.clearPermissions(vHost, username);
  158 + client.clearTopicPermissions(vHost, username);
  159 + }
  160 +
  161 + /**
  162 + * 获取MQ界面的队列信息,重载
  163 + *
  164 + * @param busServer MQ服务器
  165 + * @return
  166 + * @throws IOException
  167 + * @throws URISyntaxException
  168 + */
  169 + public static List<ViewQueueInfo> getViewQueues(BusServer busServer) throws IOException, URISyntaxException
  170 + {
  171 + Client client = connectClient(busServer);
  172 + List<QueueInfo> queues = client.getQueues();
  173 + return reformatQueueInfo(busServer.getServerName(), queues);
  174 + }
  175 +
  176 + /**
  177 + * 队列信息,重新格式化
  178 + *
  179 + * @param serverName MQ服务器名称
  180 + * @param queues 队列信息 {@link QueueInfo}
  181 + * @return
  182 + */
  183 + public static List<ViewQueueInfo> reformatQueueInfo(String serverName, List<QueueInfo> queues)
  184 + {
  185 + List<ViewQueueInfo> list = new ArrayList<>();
  186 + // 将获取到的队列信息,拼接一个属性,服务器名称
  187 + for (QueueInfo queueInfo : queues) {
  188 + ViewQueueInfo viewQueueInfo = ViewQueueInfo.builder().queueInfo(queueInfo).serverName(serverName).build();
  189 + list.add(viewQueueInfo);
  190 + }
  191 + return list;
  192 + }
  193 +
  194 + /**
  195 + * 获取MQ界面的队列信息,重载
  196 + *
  197 + * @param busServer MQ服务器
  198 + * @param vHostName 虚拟主机名称
  199 + * @return
  200 + * @throws IOException
  201 + * @throws URISyntaxException
  202 + */
  203 + public static List<ViewQueueInfo> getViewQueues(BusServer busServer, String vHostName) throws IOException, URISyntaxException
  204 + {
  205 + Client client = connectClient(busServer);
  206 + List<QueueInfo> queues = client.getQueues(vHostName);
  207 + return reformatQueueInfo(busServer.getServerName(), queues);
  208 + }
  209 +
  210 + /**
  211 + * 获取MQ界面的队列信息,重载
  212 + *
  213 + * @param busServer MQ服务器信息
  214 + * @param vHostName 虚拟主机
  215 + * @param queueName 队列名称
  216 + * @return
  217 + * @throws IOException
  218 + * @throws URISyntaxException
  219 + */
  220 + public ViewQueueInfo getViewQueues(BusServer busServer, String vHostName, String queueName) throws IOException, URISyntaxException
  221 + {
  222 + Client client = connectClient(busServer);
  223 + QueueInfo queue = client.getQueue(vHostName, queueName);
  224 + ViewQueueInfo viewQueueInfo = ViewQueueInfo.builder().serverName(busServer.getServerName()).queueInfo(queue).build();
  225 + return viewQueueInfo;
  226 + }
  227 +
  228 + /**
  229 + * 获取MQ界面的交换机信息,重载
  230 + *
  231 + * @param busServer MQ服务器信息
  232 + * @return
  233 + * @throws IOException
  234 + * @throws URISyntaxException
  235 + */
  236 + public static List<ViewExchangeInfo> getViewExchanges(BusServer busServer) throws IOException, URISyntaxException
  237 + {
  238 + Client client = connectClient(busServer);
  239 + List<ExchangeInfo> exchanges = client.getExchanges();
  240 + List<ViewExchangeInfo> viewExchangeInfos = reformatExchangeInfo(busServer.getServerName(), exchanges);
  241 + return viewExchangeInfos;
  242 + }
  243 +
  244 + public static List<ViewExchangeInfo> reformatExchangeInfo(String serverName, List<ExchangeInfo> exchanges)
  245 + {
  246 + List<ViewExchangeInfo> list = new ArrayList<>();
  247 + // 将获取到的队列信息,拼接一个属性,服务器名称
  248 + for (ExchangeInfo exchangeInfo : exchanges) {
  249 + TempExchangeInfo tempExchangeInfo = exchangeInfoToTemp(exchangeInfo);
  250 + ViewExchangeInfo viewExchangeInfo = ViewExchangeInfo.builder().serverName(serverName).tempExchangeInfo(tempExchangeInfo).build();
  251 + list.add(viewExchangeInfo);
  252 + }
  253 + return list;
  254 + }
  255 +
  256 + /**
  257 + * mybatis封装的反射(根据属性名和对象,获取属性的值)
  258 + *
  259 + * @param fieldName 属性名
  260 + * @param object 对象
  261 + * @return
  262 + */
  263 + private static Object getFieldValueByFieldName(String fieldName, Object object)
  264 + {
  265 + MetaObject metaObject = SystemMetaObject.forObject(object);
  266 + Object value = metaObject.getValue(fieldName);
  267 + return value;
  268 + }
  269 +
  270 + /**
  271 + * 将ExchangeInfo转换成TempExchangeInfo
  272 + *
  273 + * @param exchangeInfo ExchangeInfo
  274 + * @return
  275 + */
  276 + private static TempExchangeInfo exchangeInfoToTemp(ExchangeInfo exchangeInfo)
  277 + {
  278 + ExchangeMessageStats messageStats = (ExchangeMessageStats) getFieldValueByFieldName("messageStats", exchangeInfo);
  279 + TempExchangeInfo temp = new TempExchangeInfo();
  280 + temp.setVhost(exchangeInfo.getVhost());
  281 + temp.setName(exchangeInfo.getName());
  282 + temp.setType(exchangeInfo.getType());
  283 + temp.setDurable(exchangeInfo.isDurable());
  284 + temp.setAutoDelete(exchangeInfo.isAutoDelete());
  285 + temp.setInternal(exchangeInfo.isInternal());
  286 + temp.setArguments(exchangeInfo.getArguments());
  287 + temp.setMessageStats(messageStats);
  288 + return temp;
  289 + }
  290 +
  291 +
  292 + /**
  293 + * 获取MQ界面的交换机信息,重载
  294 + *
  295 + * @param busServer MQ服务器信息
  296 + * @param vHostName 虚拟主机
  297 + * @return
  298 + * @throws IOException
  299 + * @throws URISyntaxException
  300 + */
  301 + public static List<ViewExchangeInfo> getViewExchanges(BusServer busServer, String vHostName) throws IOException, URISyntaxException
  302 + {
  303 + Client client = connectClient(busServer);
  304 + List<ExchangeInfo> exchanges = client.getExchanges(vHostName);
  305 + List<ViewExchangeInfo> viewExchangeInfos = reformatExchangeInfo(busServer.getServerName(), exchanges);
  306 + return viewExchangeInfos;
  307 + }
  308 +
  309 + /**
  310 + * 获取MQ界面的交换机信息,重载
  311 + *
  312 + * @param busServer MQ服务器信息
  313 + * @param vHostName 虚拟主机
  314 + * @param exchangeName 交换机名称
  315 + * @return
  316 + * @throws IOException
  317 + * @throws URISyntaxException
  318 + */
  319 + public static ViewExchangeInfo getViewExchanges(BusServer busServer, String vHostName, String exchangeName) throws IOException, URISyntaxException
  320 + {
  321 + Client client = connectClient(busServer);
  322 + ExchangeInfo exchangeInfo = client.getExchange(vHostName, exchangeName);
  323 + TempExchangeInfo tempExchangeInfo = exchangeInfoToTemp(exchangeInfo);
  324 + ViewExchangeInfo viewExchangeInfo = ViewExchangeInfo.builder().serverName(busServer.getServerName()).tempExchangeInfo(tempExchangeInfo).build();
  325 + return viewExchangeInfo;
  326 + }
  327 +
  328 +}
  1 +package com.sunyo.wlpt.message.bus.service.rabbit.utils;
  2 +
  3 +import com.rabbitmq.client.*;
  4 +import com.sunyo.wlpt.message.bus.service.domain.XmlData;
  5 +import com.sunyo.wlpt.message.bus.service.exception.CustomExceptionType;
  6 +import com.sunyo.wlpt.message.bus.service.response.ResultJson;
  7 +import com.sunyo.wlpt.message.bus.service.utils.AESUtils;
  8 +import com.sunyo.wlpt.message.bus.service.utils.IdUtils;
  9 +import io.netty.util.internal.StringUtil;
  10 +import lombok.extern.slf4j.Slf4j;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.data.redis.core.StringRedisTemplate;
  13 +import org.springframework.stereotype.Component;
  14 +
  15 +import java.io.IOException;
  16 +import java.util.ArrayList;
  17 +import java.util.List;
  18 +import java.util.concurrent.TimeUnit;
  19 +import java.util.concurrent.TimeoutException;
  20 +
  21 +/**
  22 + * @author 子诚
  23 + * Description:
  24 + * 时间:2020/7/21 9:32
  25 + */
  26 +@Slf4j
  27 +@Component
  28 +public class DirectUtils {
  29 +
  30 + @Autowired
  31 + private StringRedisTemplate redisTemplate;
  32 +
  33 + /**
  34 + * 链接 RabbitMQ
  35 + *
  36 + * @param hostIp mq服务器Ip地址
  37 + * @param hostPort mq服务器端口号
  38 + * @param vHostName VirtualHost名称
  39 + * @param userName 登录账号
  40 + * @param password 登录密码
  41 + * @return 返回链接
  42 + * @throws Exception
  43 + */
  44 + public static Connection getConnection(String hostIp, int hostPort, String vHostName, String userName, String password) throws IOException, TimeoutException
  45 + {
  46 + //定义连接工厂
  47 + ConnectionFactory factory = new ConnectionFactory();
  48 + //设置服务地址
  49 + factory.setHost(hostIp);
  50 + //端口
  51 + factory.setPort(hostPort);
  52 + //设置账号信息,用户名、密码、vhost
  53 + factory.setVirtualHost(vHostName);
  54 + factory.setUsername(userName);
  55 + factory.setPassword(AESUtils.decrypt(password));
  56 + // 通过工程获取连接
  57 + return factory.newConnection();
  58 + }
  59 +
  60 + /**
  61 + * 关闭通道和关闭连接的工具方法
  62 + *
  63 + * @param channel 通道
  64 + * @param conn 连接
  65 + */
  66 + public static void closeConnectionAndChanel(Channel channel, Connection conn)
  67 + {
  68 + try {
  69 + if (channel != null) {
  70 + channel.close();
  71 + }
  72 + if (conn != null) {
  73 + conn.close();
  74 + }
  75 + } catch (Exception e) {
  76 + e.printStackTrace();
  77 + }
  78 + }
  79 +
  80 + public ResultJson sendMessage(XmlData xmlData) throws IOException, TimeoutException
  81 + {
  82 + /**
  83 + * 可以在这里根据类型的不同,进行不同的消息发送
  84 + */
  85 + return directProducer(xmlData);
  86 + }
  87 +
  88 + /**
  89 + * 发送消息,使用中
  90 + *
  91 + * @param xmlData {@link XmlData}
  92 + * @return
  93 + * @throws Exception
  94 + */
  95 + public ResultJson directProducer(XmlData xmlData) throws IOException, TimeoutException
  96 + {
  97 + // 1、创建Connection
  98 + Connection connection = getConnection(xmlData.getServerIp(), xmlData.getServerPort(),
  99 + xmlData.getVirtualHostName(), xmlData.getSuperUsername(), xmlData.getSuperPassword());
  100 + // 2、 通过Connection创建一个新的Channel
  101 + Channel channel = connection.createChannel();
  102 + // 3、开启消息的确认机制(confirm:保证消息能够发送到 exchange)
  103 + channel.confirmSelect();
  104 + // 4、避免消息被重复消费
  105 + AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder()
  106 + // 指定消息是否需要持久化,2:持久化;1.非持久化
  107 + .deliveryMode(2)
  108 + // 设置全局唯一消息机制id(雪花id)
  109 + .messageId(IdUtils.generateId())
  110 + .build();
  111 + // 5、开启 return 机制(保证消息,从 Exchange 分发到 Queue )
  112 + channel.addReturnListener(new ReturnListener() {
  113 + @Override
  114 + public void handleReturn(int replyCode, String replyText, String exchange, String routingKey, AMQP.BasicProperties properties, byte[] body) throws IOException
  115 + {
  116 + // 当消息没有从 Exchange 分发到 Queue 时,才会执行
  117 + log.error(new String(body, "UTF8") + "->没有从 Exchange 分发到Queue中");
  118 + }
  119 + });
  120 +
  121 + // 6、发送消息,并指定 mandatory 参数为true
  122 + channel.basicPublish(xmlData.getExchangeName(), xmlData.getRoutingKeyName(), true, properties,
  123 + xmlData.getSendContent().getBytes());
  124 +
  125 + log.info("消息生产者,目标交换机:{};路由键:{};发送信息:{}", xmlData.getExchangeName(), xmlData.getRoutingKeyName(),
  126 + xmlData.getSendContent().getBytes());
  127 + // 7、添加一个异步 confirm 确认监听,用于发送消息到Broker端之后,回送消息的监听
  128 + channel.addConfirmListener(new ConfirmListener() {
  129 + // 发送成功
  130 + @Override
  131 + public void handleAck(long deliveryTag, boolean multiple) throws IOException
  132 + {
  133 + log.info("消息发送成功,标识:{};是否是批量:{}", deliveryTag, multiple);
  134 + }
  135 +
  136 + // 发送失败
  137 + @Override
  138 + public void handleNack(long deliveryTag, boolean multiple) throws IOException
  139 + {
  140 + log.error("消息发送失败,标识:{};是否是批量:{}", deliveryTag, multiple);
  141 + }
  142 + });
  143 + // finally,关闭连接
  144 + closeConnectionAndChanel(channel, connection);
  145 + return ResultJson.success(CustomExceptionType.MESSAGE_SUCCESS);
  146 + }
  147 +
  148 + /**
  149 + * byte字节数组 转 String
  150 + *
  151 + * @param byteArray 字节数组
  152 + * @return
  153 + */
  154 + public static String byteArrayToStr(byte[] byteArray)
  155 + {
  156 + if (byteArray == null) {
  157 + return null;
  158 + }
  159 + String str = new String(byteArray);
  160 + return str;
  161 + }
  162 +
  163 + /**
  164 + * DirectExchange的 消息消费者(推模式)
  165 + *
  166 + * @throws IOException IO异常
  167 + * @throws TimeoutException 超时异常
  168 + */
  169 + public List<String> directConsumerByPush(XmlData xmlData) throws IOException, TimeoutException
  170 + {
  171 + List<String> list = new ArrayList<>();
  172 +
  173 + // 1、创建ConnectionFactory
  174 + Connection connection = getConnection(xmlData.getServerIp(), xmlData.getServerPort(),
  175 + xmlData.getVirtualHostName(), xmlData.getSuperUsername(), xmlData.getSuperPassword());
  176 +
  177 + // 2、 通过Connection创建一个新的Channel
  178 + Channel channel = connection.createChannel();
  179 +
  180 + // 一次只接受一条未确认的消息
  181 + channel.basicQos(1);
  182 +
  183 + // 4、开启监听Queue
  184 + DefaultConsumer consumer = new DefaultConsumer(channel) {
  185 + @Override
  186 + public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException
  187 + {
  188 + try {
  189 + // 0、获取出全局唯一的 信息业务id(messageId)
  190 + String messageId = properties.getMessageId();
  191 +
  192 + // 必须保证 messageId 不为空,避免空指针异常
  193 + if (redisTemplate.opsForValue().setIfAbsent(messageId, "0", 10, TimeUnit.MINUTES)) {
  194 +
  195 + // 消费成功,将redis中的 messageId 对应的value修改为 1
  196 + redisTemplate.opsForValue().set(messageId, "1", 1, TimeUnit.MINUTES);
  197 + // 手动ack
  198 + channel.basicAck(envelope.getDeliveryTag(), false);
  199 + log.info("接收到消息:" + new String(body, "UTF-8"));
  200 + String message = new String(body, "UTF-8");
  201 + list.add(message);
  202 + } else {
  203 + // 获取redis中的value,如果是1,就手动ack。如果是0,就什么也不做(是0代表着,正在被消费中)
  204 + if ("1".equalsIgnoreCase(redisTemplate.opsForValue().get(messageId))) {
  205 + // 手动ack
  206 + channel.basicAck(envelope.getDeliveryTag(), false);
  207 + }
  208 + }
  209 + } catch (Exception e) {
  210 + // 手动ack
  211 + channel.basicAck(envelope.getDeliveryTag(), false);
  212 + log.error("接收消息发送错误:" + e.getMessage());
  213 + }
  214 + }
  215 + };
  216 + // 消费消息
  217 + channel.basicConsume(xmlData.getQueueName(), false, consumer);
  218 + return list;
  219 + }
  220 +
  221 + /**
  222 + * DirectExchange的 消息消费者(拉模式)
  223 + *
  224 + * @throws IOException IO异常
  225 + * @throws TimeoutException 超时异常
  226 + */
  227 + public ResultJson directConsumerByPull(XmlData xmlData) throws IOException, TimeoutException
  228 + {
  229 + List<String> list = new ArrayList<>();
  230 +
  231 + Connection connection = getConnection(xmlData.getServerIp(), xmlData.getServerPort(), xmlData.getVirtualHostName(), xmlData.getSuperUsername(), xmlData.getSuperPassword());
  232 + Channel channel = connection.createChannel();
  233 + channel.basicQos(1);
  234 +
  235 + GetResponse response = channel.basicGet(xmlData.getQueueName(), false);
  236 + if (response != null && response.getMessageCount() >= 0) {
  237 + String messageId = response.getProps().getMessageId();
  238 + if (redisTemplate.opsForValue().setIfAbsent(messageId, "0", 1, TimeUnit.MINUTES)) {
  239 + redisTemplate.opsForValue().set(messageId, "1", 1, TimeUnit.MINUTES);
  240 + String data = byteArrayToStr(response.getBody());
  241 + list.add(data);
  242 + channel.basicAck(response.getEnvelope().getDeliveryTag(), false);
  243 + } else {
  244 + if ("1".equalsIgnoreCase(redisTemplate.opsForValue().get(messageId))) {
  245 + channel.basicAck(response.getEnvelope().getDeliveryTag(), false);
  246 + }
  247 + }
  248 + }
  249 + String message = list.get(0);
  250 + return StringUtil.isNullOrEmpty(message)
  251 + ? ResultJson.error(CustomExceptionType.RECEIVE_SERVER_EXCEPTION)
  252 + : ResultJson.success(CustomExceptionType.RECEIVE_SUCCESS, message);
  253 + }
  254 +
  255 + /**
  256 + * DirectExchange的 消息消费者(拉模式、批量拉取)
  257 + */
  258 + public ResultJson directConsumerByPullMore(XmlData xmlData, Integer count) throws IOException, TimeoutException
  259 + {
  260 + List<String> list = new ArrayList<>();
  261 + String serverIp = xmlData.getServerIp();
  262 + Integer serverPort = xmlData.getServerPort();
  263 + String virtualHostName = xmlData.getVirtualHostName();
  264 + String superUsername = xmlData.getSuperUsername();
  265 + String superPassword = xmlData.getSuperPassword();
  266 +
  267 + Connection connection = getConnection(serverIp, serverPort, virtualHostName, superUsername, superPassword);
  268 + Channel channel = connection.createChannel();
  269 + channel.basicQos(1);
  270 +
  271 + while (list.size() < count) {
  272 + GetResponse response = channel.basicGet(xmlData.getQueueName(), false);
  273 + if (response != null) {
  274 + if (response.getMessageCount() >= 0) {
  275 + String messageId = response.getProps().getMessageId();
  276 + if (redisTemplate.opsForValue().setIfAbsent(messageId, "0", 1, TimeUnit.MINUTES)) {
  277 + redisTemplate.opsForValue().set(messageId, "1", 1, TimeUnit.MINUTES);
  278 + String data = byteArrayToStr(response.getBody());
  279 + list.add(data);
  280 + channel.basicAck(response.getEnvelope().getDeliveryTag(), false);
  281 + } else {
  282 + if ("1".equalsIgnoreCase(redisTemplate.opsForValue().get(messageId))) {
  283 + channel.basicAck(response.getEnvelope().getDeliveryTag(), false);
  284 + }
  285 + }
  286 + }
  287 + } else {
  288 + break;
  289 + }
  290 + }
  291 +
  292 + int size = list.size();
  293 + if (0 < size && size < count) {
  294 + return new ResultJson<>("20200", "接收消息,成功!但是,该队列内只有" + size + "条消息", list);
  295 + }
  296 + return size > 0
  297 + ? ResultJson.success(CustomExceptionType.RECEIVE_SUCCESS, list)
  298 + : ResultJson.error(CustomExceptionType.RECEIVE_SERVER_EXCEPTION);
  299 + }
  300 +
  301 +}
  302 +
  303 +