Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
KnowledgePlanet
road-map
xfg-dev-tech-rabbitmq
提交
7a2c1d22
xfg-dev-tech-rabbitmq
项目概览
KnowledgePlanet
/
road-map
/
xfg-dev-tech-rabbitmq
通知
107
Star
12
Fork
7
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
xfg-dev-tech-rabbitmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7a2c1d22
编写于
11月 29, 2023
作者:
小傅哥
⛹
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
小傅哥,feat:初始化测试工程
上级
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
672 addition
and
0 deletion
+672
-0
pom.xml
pom.xml
+111
-0
xfg-dev-tech-app/pom.xml
xfg-dev-tech-app/pom.xml
+112
-0
xfg-dev-tech-app/src/main/java/cn/bugstack/xfg/dev/tech/Application.java
...p/src/main/java/cn/bugstack/xfg/dev/tech/Application.java
+15
-0
xfg-dev-tech-app/src/main/resources/application-dev.yml
xfg-dev-tech-app/src/main/resources/application-dev.yml
+25
-0
xfg-dev-tech-app/src/main/resources/application-prod.yml
xfg-dev-tech-app/src/main/resources/application-prod.yml
+14
-0
xfg-dev-tech-app/src/main/resources/application-test.yml
xfg-dev-tech-app/src/main/resources/application-test.yml
+14
-0
xfg-dev-tech-app/src/main/resources/application.yml
xfg-dev-tech-app/src/main/resources/application.yml
+5
-0
xfg-dev-tech-app/src/main/resources/logback-spring.xml
xfg-dev-tech-app/src/main/resources/logback-spring.xml
+114
-0
xfg-dev-tech-app/src/test/java/cn/bugstack/xfg/dev/tech/test/ApiTest.java
.../src/test/java/cn/bugstack/xfg/dev/tech/test/ApiTest.java
+52
-0
xfg-dev-tech-trigger/pom.xml
xfg-dev-tech-trigger/pom.xml
+61
-0
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/Customer.java
...in/java/cn/bugstack/xfg/dev/tech/trigger/mq/Customer.java
+26
-0
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/FanoutCustomer.java
...a/cn/bugstack/xfg/dev/tech/trigger/mq/FanoutCustomer.java
+32
-0
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/RouteCustomer.java
...va/cn/bugstack/xfg/dev/tech/trigger/mq/RouteCustomer.java
+40
-0
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/TopicCustomer.java
...va/cn/bugstack/xfg/dev/tech/trigger/mq/TopicCustomer.java
+51
-0
未找到文件。
pom.xml
0 → 100644
浏览文件 @
7a2c1d22
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-dev-tech-rabbitmq
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
pom
</packaging>
<modules>
<module>
xfg-dev-tech-app
</module>
<module>
xfg-dev-tech-trigger
</module>
</modules>
<properties>
<java.version>
1.8
</java.version>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
<maven.compiler.source>
8
</maven.compiler.source>
<maven.compiler.target>
8
</maven.compiler.target>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-parent
</artifactId>
<version>
2.7.12
</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
2.0.28
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.9
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
32.1.2-jre
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-amqp -->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
<version>
3.2.0
</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>
xfg-dev-tech
</finalName>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.0
</version>
<configuration>
<source>
${java.version}
</source>
<target>
${java.version}
</target>
<encoding>
${project.build.sourceEncoding}
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-resources-plugin
</artifactId>
<version>
2.5
</version>
<configuration>
<encoding>
UTF-8
</encoding>
</configuration>
</plugin>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
versions-maven-plugin
</artifactId>
<version>
2.7
</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>
dev
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<properties>
<profileActive>
dev
</profileActive>
</properties>
</profile>
<profile>
<id>
test
</id>
<properties>
<profileActive>
test
</profileActive>
</properties>
</profile>
<profile>
<id>
prod
</id>
<properties>
<profileActive>
prod
</profileActive>
</properties>
</profile>
</profiles>
</project>
\ No newline at end of file
xfg-dev-tech-app/pom.xml
0 → 100644
浏览文件 @
7a2c1d22
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-dev-tech-rabbitmq
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<artifactId>
xfg-dev-tech-app
</artifactId>
<packaging>
jar
</packaging>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
io.micrometer
</groupId>
<artifactId>
micrometer-registry-prometheus
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
<dependency>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-dev-tech-trigger
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</dependency>
</dependencies>
<build>
<finalName>
xfg-dev-tech-app
</finalName>
<resources>
<resource>
<directory>
src/main/resources
</directory>
<filtering>
true
</filtering>
<includes>
<include>
**/**
</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>
src/test/resources
</directory>
<filtering>
true
</filtering>
<includes>
<include>
**/**
</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.6
</version>
<configuration>
<skipTests>
true
</skipTests>
<testFailureIgnore>
false
</testFailureIgnore>
<includes>
<include>
**/*Test.java
</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<configuration>
<mainClass>
cn.bugstack.xfg.dev.tech.Application
</mainClass>
<layout>
JAR
</layout>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
xfg-dev-tech-app/src/main/java/cn/bugstack/xfg/dev/tech/Application.java
0 → 100644
浏览文件 @
7a2c1d22
package
cn.bugstack.xfg.dev.tech
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@Slf4j
@SpringBootApplication
public
class
Application
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
Application
.
class
);
}
}
xfg-dev-tech-app/src/main/resources/application-dev.yml
0 → 100644
浏览文件 @
7a2c1d22
server
:
port
:
8091
tomcat
:
max-connections
:
20
threads
:
max
:
20
min-spare
:
10
accept-count
:
10
spring
:
# RabbitMQ 配置
rabbitmq
:
addresses
:
127.0.0.1
port
:
5672
username
:
admin
password
:
admin
listener
:
simple
:
prefetch
:
1
# 每次投递n个消息,消费完在投递n个
logging
:
level
:
root
:
info
config
:
classpath:logback-spring.xml
\ No newline at end of file
xfg-dev-tech-app/src/main/resources/application-prod.yml
0 → 100644
浏览文件 @
7a2c1d22
server
:
port
:
8091
tomcat
:
max-connections
:
20
threads
:
max
:
20
min-spare
:
10
accept-count
:
10
logging
:
level
:
root
:
info
config
:
classpath:logback-spring.xml
\ No newline at end of file
xfg-dev-tech-app/src/main/resources/application-test.yml
0 → 100644
浏览文件 @
7a2c1d22
server
:
port
:
8091
tomcat
:
max-connections
:
20
threads
:
max
:
20
min-spare
:
10
accept-count
:
10
logging
:
level
:
root
:
info
config
:
classpath:logback-spring.xml
\ No newline at end of file
xfg-dev-tech-app/src/main/resources/application.yml
0 → 100644
浏览文件 @
7a2c1d22
spring
:
config
:
name
:
xfg-dev-tech
profiles
:
active
:
dev
xfg-dev-tech-app/src/main/resources/logback-spring.xml
0 → 100644
浏览文件 @
7a2c1d22
<?xml version="1.0" encoding="UTF-8"?>
<!-- 日志级别从低到高分为TRACE < DEBUG < INFO < WARN < ERROR < FATAL,如果设置为WARN,则低于WARN的信息都不会输出 -->
<configuration
scan=
"true"
scanPeriod=
"10 seconds"
>
<contextName>
logback
</contextName>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
<springProperty
scope=
"context"
name=
"log.path"
source=
"logging.path"
/>
<!-- 日志格式 -->
<conversionRule
conversionWord=
"clr"
converterClass=
"org.springframework.boot.logging.logback.ColorConverter"
/>
<conversionRule
conversionWord=
"wex"
converterClass=
"org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"
/>
<conversionRule
conversionWord=
"wEx"
converterClass=
"org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"
/>
<!-- 输出到控制台 -->
<appender
name=
"CONSOLE"
class=
"ch.qos.logback.core.ConsoleAppender"
>
<!-- 此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息 -->
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
info
</level>
</filter>
<encoder>
<pattern>
%d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0}%X{ServiceId} -%X{trace-id} %m%n
</pattern>
<charset>
UTF-8
</charset>
</encoder>
</appender>
<!--输出到文件-->
<!-- 时间滚动输出 level为 INFO 日志 -->
<appender
name=
"INFO_FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!-- 正在记录的日志文件的路径及文件名 -->
<file>
./data/log/log_info.log
</file>
<!--日志文件输出格式-->
<encoder>
<pattern>
%d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0}%X{ServiceId} -%X{trace-id} %m%n
</pattern>
<charset>
UTF-8
</charset>
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<!-- 每天日志归档路径以及格式 -->
<fileNamePattern>
./data/log/log-info-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<maxFileSize>
100MB
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>
15
</maxHistory>
<totalSizeCap>
10GB
</totalSizeCap>
</rollingPolicy>
</appender>
<!-- 时间滚动输出 level为 ERROR 日志 -->
<appender
name=
"ERROR_FILE"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<!-- 正在记录的日志文件的路径及文件名 -->
<file>
./data/log/log_error.log
</file>
<!--日志文件输出格式-->
<encoder>
<pattern>
%d{yy-MM-dd.HH:mm:ss.SSS} [%-16t] %-5p %-22c{0}%X{ServiceId} -%X{trace-id} %m%n
</pattern>
<charset>
UTF-8
</charset>
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy
class=
"ch.qos.logback.core.rolling.TimeBasedRollingPolicy"
>
<fileNamePattern>
./data/log/log-error-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"
>
<maxFileSize>
100MB
</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- 日志文件保留天数【根据服务器预留,可自行调整】 -->
<maxHistory>
7
</maxHistory>
<totalSizeCap>
5GB
</totalSizeCap>
</rollingPolicy>
<!-- WARN 级别及以上 -->
<filter
class=
"ch.qos.logback.classic.filter.ThresholdFilter"
>
<level>
WARN
</level>
</filter>
</appender>
<!-- 异步输出 -->
<appender
name=
"ASYNC_FILE_INFO"
class=
"ch.qos.logback.classic.AsyncAppender"
>
<!-- 队列剩余容量小于discardingThreshold,则会丢弃TRACT、DEBUG、INFO级别的日志;默认值-1,为queueSize的20%;0不丢失日志 -->
<discardingThreshold>
0
</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>
8192
</queueSize>
<!-- neverBlock:true 会丢失日志,但业务性能不受影响 -->
<neverBlock>
true
</neverBlock>
<!--是否提取调用者数据-->
<includeCallerData>
false
</includeCallerData>
<appender-ref
ref=
"INFO_FILE"
/>
</appender>
<appender
name=
"ASYNC_FILE_ERROR"
class=
"ch.qos.logback.classic.AsyncAppender"
>
<!-- 队列剩余容量小于discardingThreshold,则会丢弃TRACT、DEBUG、INFO级别的日志;默认值-1,为queueSize的20%;0不丢失日志 -->
<discardingThreshold>
0
</discardingThreshold>
<!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
<queueSize>
1024
</queueSize>
<!-- neverBlock:true 会丢失日志,但业务性能不受影响 -->
<neverBlock>
true
</neverBlock>
<!--是否提取调用者数据-->
<includeCallerData>
false
</includeCallerData>
<appender-ref
ref=
"ERROR_FILE"
/>
</appender>
<!-- 开发环境:控制台打印 -->
<springProfile
name=
"dev"
>
<logger
name=
"com.nmys.view"
level=
"debug"
/>
</springProfile>
<root
level=
"info"
>
<appender-ref
ref=
"CONSOLE"
/>
<!-- 异步日志-INFO -->
<appender-ref
ref=
"ASYNC_FILE_INFO"
/>
<!-- 异步日志-ERROR -->
<appender-ref
ref=
"ASYNC_FILE_ERROR"
/>
</root>
</configuration>
\ No newline at end of file
xfg-dev-tech-app/src/test/java/cn/bugstack/xfg/dev/tech/test/ApiTest.java
0 → 100644
浏览文件 @
7a2c1d22
package
cn.bugstack.xfg.dev.tech.test
;
import
lombok.extern.slf4j.Slf4j
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.concurrent.CountDownLatch
;
@Slf4j
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
public
class
ApiTest
{
@Autowired
private
RabbitTemplate
rabbitTemplate
;
@Test
public
void
test_product
()
throws
InterruptedException
{
// 发送消息
rabbitTemplate
.
convertAndSend
(
"testQueue"
,
"基本消息"
);
// 等待
new
CountDownLatch
(
1
).
await
();
}
@Test
public
void
test_product_fanout
()
throws
InterruptedException
{
rabbitTemplate
.
convertAndSend
(
"fanoutExchange"
,
""
,
"广播消息"
);
// 等待
new
CountDownLatch
(
1
).
await
();
}
@Test
public
void
test_product_route
()
throws
InterruptedException
{
rabbitTemplate
.
convertAndSend
(
"routeExchange"
,
"routeKey1"
,
"路由模式,消息1"
);
rabbitTemplate
.
convertAndSend
(
"routeExchange"
,
"routeKey2"
,
"路由模式,消息2"
);
// 等待
new
CountDownLatch
(
1
).
await
();
}
@Test
public
void
test_product_topic
()
throws
InterruptedException
{
rabbitTemplate
.
convertAndSend
(
"topicExchange"
,
"topic.x"
,
"通配符模式,消息1"
);
rabbitTemplate
.
convertAndSend
(
"topicExchange"
,
"topic.y.z"
,
"通配符模式,消息2"
);
// 等待
new
CountDownLatch
(
1
).
await
();
}
}
xfg-dev-tech-trigger/pom.xml
0 → 100644
浏览文件 @
7a2c1d22
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
cn.bugstack
</groupId>
<artifactId>
xfg-dev-tech-rabbitmq
</artifactId>
<version>
1.0-SNAPSHOT
</version>
</parent>
<artifactId>
xfg-dev-tech-trigger
</artifactId>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-context
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-tx
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
</dependencies>
<build>
<finalName>
xfg-dev-tech-trigger
</finalName>
<plugins>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<configuration>
<source>
${java.version}
</source>
<target>
${java.version}
</target>
<compilerVersion>
${java.version}
</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/Customer.java
0 → 100644
浏览文件 @
7a2c1d22
package
cn.bugstack.xfg.dev.tech.trigger.mq
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.rabbit.annotation.Queue
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.stereotype.Component
;
/**
* 基本模式
*/
@Slf4j
@Component
public
class
Customer
{
/**
* queuesToDeclare:支持多个队列,将队列绑定到默认交换机上,routeKey为队列名称。
*
* @param msg 接收到的消息
*/
@RabbitListener
(
queuesToDeclare
=
@Queue
(
value
=
"testQueue"
))
public
void
listener
(
String
msg
)
{
log
.
info
(
"接收消息:{}"
,
msg
);
// throw new RuntimeException("Err");
}
}
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/FanoutCustomer.java
0 → 100644
浏览文件 @
7a2c1d22
package
cn.bugstack.xfg.dev.tech.trigger.mq
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.ExchangeTypes
;
import
org.springframework.amqp.rabbit.annotation.Exchange
;
import
org.springframework.amqp.rabbit.annotation.Queue
;
import
org.springframework.amqp.rabbit.annotation.QueueBinding
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.stereotype.Component
;
/**
* 广播/扇出模式
* 一个生产者发送一条消息,可以同时被多个消费者所收到。
*/
@Slf4j
@Component
public
class
FanoutCustomer
{
@RabbitListener
(
bindings
=
@QueueBinding
(
value
=
@Queue
(
value
=
"fanoutCustomer"
),
exchange
=
@Exchange
(
value
=
"fanoutExchange"
,
type
=
ExchangeTypes
.
FANOUT
)
)
)
public
void
listener
(
String
msg
)
{
log
.
info
(
"接收消息【广播模式】:{}"
,
msg
);
}
}
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/RouteCustomer.java
0 → 100644
浏览文件 @
7a2c1d22
package
cn.bugstack.xfg.dev.tech.trigger.mq
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.ExchangeTypes
;
import
org.springframework.amqp.rabbit.annotation.Exchange
;
import
org.springframework.amqp.rabbit.annotation.Queue
;
import
org.springframework.amqp.rabbit.annotation.QueueBinding
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.stereotype.Component
;
/**
* 路由模式
*/
@Slf4j
@Component
public
class
RouteCustomer
{
@RabbitListener
(
bindings
=
@QueueBinding
(
value
=
@Queue
(
value
=
"routeQueue1"
),
exchange
=
@Exchange
(
value
=
"routeExchange"
,
type
=
ExchangeTypes
.
DIRECT
),
key
=
"routeKey1"
)
)
public
void
listener01
(
String
msg
)
{
log
.
info
(
"接收消息【路由模式】:{}"
,
msg
);
}
@RabbitListener
(
bindings
=
@QueueBinding
(
value
=
@Queue
(
value
=
"routeQueue2"
),
exchange
=
@Exchange
(
value
=
"routeExchange"
,
type
=
ExchangeTypes
.
DIRECT
),
key
=
"routeKey2"
)
)
public
void
listener02
(
String
msg
)
{
log
.
info
(
"接收消息【路由模式】:{}"
,
msg
);
}
}
xfg-dev-tech-trigger/src/main/java/cn/bugstack/xfg/dev/tech/trigger/mq/TopicCustomer.java
0 → 100644
浏览文件 @
7a2c1d22
package
cn.bugstack.xfg.dev.tech.trigger.mq
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.ExchangeTypes
;
import
org.springframework.amqp.rabbit.annotation.Exchange
;
import
org.springframework.amqp.rabbit.annotation.Queue
;
import
org.springframework.amqp.rabbit.annotation.QueueBinding
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.stereotype.Component
;
/**
* 通配符模式
*/
@Slf4j
@Component
public
class
TopicCustomer
{
@RabbitListener
(
bindings
=
@QueueBinding
(
value
=
@Queue
(
value
=
"topicQueue1"
),
exchange
=
@Exchange
(
value
=
"topicExchange"
,
type
=
ExchangeTypes
.
TOPIC
),
key
=
"topic.*"
// `*`:匹配一个单词,就只有一个单词
)
)
public
void
listener01
(
String
msg
)
{
log
.
info
(
"接收消息【通配符模式】listener01:{}"
,
msg
);
}
@RabbitListener
(
bindings
=
@QueueBinding
(
value
=
@Queue
(
value
=
"topicQueue2"
),
exchange
=
@Exchange
(
value
=
"topicExchange"
,
type
=
ExchangeTypes
.
TOPIC
),
key
=
"topic.#"
// `#`:匹配一个或多个词
)
)
public
void
listener02
(
String
msg
)
{
log
.
info
(
"接收消息【通配符模式】listener02:{}"
,
msg
);
}
@RabbitListener
(
bindings
=
@QueueBinding
(
value
=
@Queue
(
value
=
"topicQueue3"
),
exchange
=
@Exchange
(
value
=
"topicExchange"
,
type
=
ExchangeTypes
.
TOPIC
),
key
=
"topic.y.#"
// `#`:匹配一个或多个词
)
)
public
void
listener03
(
String
msg
)
{
log
.
info
(
"接收消息【通配符模式】listener03:{}"
,
msg
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录