diff --git a/springboot-rabbitmq/README.md b/springboot-rabbitmq/README.md index 3a6af79..85ac190 100644 --- a/springboot-rabbitmq/README.md +++ b/springboot-rabbitmq/README.md @@ -2,7 +2,14 @@ 消息队列RabbitMQ的使用例子,演示Direct模式和广播发送模式。 -测试用例:`com.xncoding.service.SenderServiceTest.java` +## 测试步骤 + +1. 先安装rabbitmq并初始化spring用户 +2. 配置application.yml里面的连接信息 +3. 启动程序 + +有两种测试方式,一种是通过编写AfterStartRunner来直接看启动效果。 +另外一种是运行测试用例:`com.xncoding.service.SenderServiceTest.java` ## 许可证 diff --git a/springboot-rabbitmq/pom.xml b/springboot-rabbitmq/pom.xml index ede55fe..da7dfc3 100644 --- a/springboot-rabbitmq/pom.xml +++ b/springboot-rabbitmq/pom.xml @@ -29,6 +29,11 @@ org.springframework.boot spring-boot-starter-amqp + + com.fasterxml.jackson.core + jackson-databind + 2.9.6 + org.springframework.boot diff --git a/springboot-rabbitmq/src/main/java/com/xncoding/pos/Application.java b/springboot-rabbitmq/src/main/java/com/xncoding/Application.java similarity index 91% rename from springboot-rabbitmq/src/main/java/com/xncoding/pos/Application.java rename to springboot-rabbitmq/src/main/java/com/xncoding/Application.java index adc4c48..2a00aac 100644 --- a/springboot-rabbitmq/src/main/java/com/xncoding/pos/Application.java +++ b/springboot-rabbitmq/src/main/java/com/xncoding/Application.java @@ -1,4 +1,4 @@ -package com.xncoding.pos; +package com.xncoding; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/springboot-rabbitmq/src/main/java/com/xncoding/pos/AfterStartRunner.java b/springboot-rabbitmq/src/main/java/com/xncoding/pos/AfterStartRunner.java new file mode 100644 index 0000000..478dcb4 --- /dev/null +++ b/springboot-rabbitmq/src/main/java/com/xncoding/pos/AfterStartRunner.java @@ -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 --> 定点消息"); + } +} diff --git a/springboot-rabbitmq/src/main/resources/application.yml b/springboot-rabbitmq/src/main/resources/application.yml index d0c83af..2d72cb6 100644 --- a/springboot-rabbitmq/src/main/resources/application.yml +++ b/springboot-rabbitmq/src/main/resources/application.yml @@ -34,5 +34,5 @@ logging: ROOT: INFO com: xncoding: DEBUG - file: E:/logs/app.log + file: D:/logs/app.log diff --git a/springboot-rabbitmq/src/test/java/com/xncoding/service/SenderServiceTest.java b/springboot-rabbitmq/src/test/java/com/xncoding/service/SenderServiceTest.java index 554293e..a7404ad 100644 --- a/springboot-rabbitmq/src/test/java/com/xncoding/service/SenderServiceTest.java +++ b/springboot-rabbitmq/src/test/java/com/xncoding/service/SenderServiceTest.java @@ -1,6 +1,6 @@ package com.xncoding.service; -import com.xncoding.pos.Application; +import com.xncoding.Application; import com.xncoding.pos.service.SenderService; import org.junit.Test; import org.junit.runner.RunWith;