完成springboot-rabbitmq升级重构
This commit is contained in:
parent
6aa09ccc11
commit
1c339ec836
@ -2,7 +2,14 @@
|
|||||||
|
|
||||||
消息队列RabbitMQ的使用例子,演示Direct模式和广播发送模式。
|
消息队列RabbitMQ的使用例子,演示Direct模式和广播发送模式。
|
||||||
|
|
||||||
测试用例:`com.xncoding.service.SenderServiceTest.java`
|
## 测试步骤
|
||||||
|
|
||||||
|
1. 先安装rabbitmq并初始化spring用户
|
||||||
|
2. 配置application.yml里面的连接信息
|
||||||
|
3. 启动程序
|
||||||
|
|
||||||
|
有两种测试方式,一种是通过编写AfterStartRunner来直接看启动效果。
|
||||||
|
另外一种是运行测试用例:`com.xncoding.service.SenderServiceTest.java`
|
||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
|
@ -29,6 +29,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.9.6</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.xncoding.pos;
|
package com.xncoding;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.xncoding.pos;
|
||||||
|
|
||||||
|
import com.xncoding.pos.service.SenderService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AfterStartRunner
|
||||||
|
*
|
||||||
|
* @author XiongNeng
|
||||||
|
* @version 1.0
|
||||||
|
* @since 2018/9/15
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Order(1)
|
||||||
|
public class AfterStartRunner implements CommandLineRunner {
|
||||||
|
@Autowired
|
||||||
|
private SenderService senderService;
|
||||||
|
@Override
|
||||||
|
public void run(String... args) throws Exception {
|
||||||
|
System.out.println("--------------start-------------");
|
||||||
|
Thread.sleep(2000L);
|
||||||
|
// 测试广播模式
|
||||||
|
senderService.broadcast("AfterStartRunner --> 同学们集合啦!");
|
||||||
|
// 测试Direct模式
|
||||||
|
senderService.direct("AfterStartRunner --> 定点消息");
|
||||||
|
}
|
||||||
|
}
|
@ -34,5 +34,5 @@ logging:
|
|||||||
ROOT: INFO
|
ROOT: INFO
|
||||||
com:
|
com:
|
||||||
xncoding: DEBUG
|
xncoding: DEBUG
|
||||||
file: E:/logs/app.log
|
file: D:/logs/app.log
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.xncoding.service;
|
package com.xncoding.service;
|
||||||
|
|
||||||
import com.xncoding.pos.Application;
|
import com.xncoding.Application;
|
||||||
import com.xncoding.pos.service.SenderService;
|
import com.xncoding.pos.service.SenderService;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
Loading…
Reference in New Issue
Block a user