背景:基于Springboot集成RabbitMQ(一)进行
每个新建队列(queue)都会自动绑定到默认交换机上,绑定的路由键(routingKey)名称与队列名称相同,工作方式类似于单播
1. 交换机和队列配置
package com.zsx.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class DirectRabbitConfig {
public final static String DIRECT_EXCHANGE = "directExchange";
public final static String DIRECT_QUEUE1 = "direct.queue1";
@Bean
public Queue directQueue1(){
return new Queue(DIRECT_QUEUE1);
}
@Bean
public DirectExchange directExchange(){
return new DirectExchange(DIRECT_EXCHANGE);
}
@Bean
public Binding binding(Queue directQueue1, DirectExchange directExchange){
return BindingBuilder.bind(directQueue1).to(directExchange).with(DIRECT_QUEUE1);
}
}
2. 消息的生产者
package com.zsx.service;
import com.zsx.config.DirectRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class DirectSender {
private final static Logger LOGGER = LoggerFactory.getLogger(DirectSender.class);
@Autowired
private AmqpTemplate amqpTemplate;
public void sendDirect() {
String msg = "directMsg";
LOGGER.info("DirectSender.sendDirect send content: " + msg);
amqpTemplate.convertAndSend(DirectRabbitConfig.DIRECT_QUEUE1, msg);
}
}
3. 消息的消费者
package com.zsx.service;
import com.zsx.config.DirectRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component
public class DirectReceiver {
private final static Logger LOGGER = LoggerFactory.getLogger(DirectReceiver.class);
@RabbitListener(queues = DirectRabbitConfig.DIRECT_QUEUE1)
public void receiveDirect(String msg) {
LOGGER.info("DirectReceiver.receiveDirect received content: " + msg);
}
}
将消息路由给绑定到它身上的所有队列,而不理会绑定的路由键(routingKey),工作方式类似于广播
1. 交换机和队列配置
package com.zsx.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FanoutRabbitConfig {
public final static String FANOUT_QUEUE1 = "fanout.Queue1";
public final static String FANOUT_QUEUE2 = "fanout.Queue2";
public final static String FANOUT_QUEUE3 = "fanout.Queue3";
public final static String FANOUT_EXCHANGE = "fanoutExchange";
@Bean
public Queue fanoutQueue1() {
return new Queue(FANOUT_QUEUE1);
}
@Bean
public Queue fanoutQueue2() {
return new Queue(FANOUT_QUEUE2);
}
@Bean
public Queue fanoutQueue3() {
return new Queue(FANOUT_QUEUE3);
}
@Bean
public FanoutExchange fanoutExchange() {
return new FanoutExchange(FANOUT_EXCHANGE);
}
@Bean
public Binding bindingExchange1(Queue fanoutQueue1, FanoutExchange fanoutExchange) {
return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
}
@Bean
public Binding bindingExchange2(Queue fanoutQueue2, FanoutExchange fanoutExchange) {
return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
}
@Bean
public Binding bindingExchange3(Queue fanoutQueue3, FanoutExchange fanoutExchange) {
return BindingBuilder.bind(fanoutQueue3).to(fanoutExchange);
}
}
2. 消息的生产者
package com.zsx.service;
import com.zsx.config.FanoutRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class FanoutSender {
private final static Logger LOGGER = LoggerFactory.getLogger(FanoutSender.class);
@Autowired
private AmqpTemplate amqpTemplate;
public void sendFanout() {
String msg = "fanoutMsg";
LOGGER.info("FanoutSender.sendFanout send content: " + msg);
amqpTemplate.convertAndSend(FanoutRabbitConfig.FANOUT_EXCHANGE, "", msg);
}
}
3. 消息的消费者
package com.zsx.service;
import com.zsx.config.FanoutRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component
public class FanoutReceiver {
private final static Logger LOGGER = LoggerFactory.getLogger(FanoutReceiver.class);
@RabbitListener(queues = FanoutRabbitConfig.FANOUT_QUEUE1)
public void receiveFanout1(String msg) {
LOGGER.info("FanoutReceiver.receiveFanout1 received content: " + msg);
}
@RabbitListener(queues = FanoutRabbitConfig.FANOUT_QUEUE2)
public void receiveFanout2(String msg) {
LOGGER.info("FanoutReceiver.receiveFanout2 received content: " + msg);
}
@RabbitListener(queues = FanoutRabbitConfig.FANOUT_QUEUE3)
public void receiveFanout3(String msg) {
LOGGER.info("FanoutReceiver.receiveFanout3 received content: " + msg);
}
}
通过对消息的路由键(routingKey)和队列到交换机的绑定模式之间的匹配,将消息路由给一个或多个队列,工作方式类似于多播
1. 交换机和队列配置
package com.zsx.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class TopicRabbitConfig {
public final static String TOPIC_EXCHANGE = "topicExchange";
public final static String TOPIC_QUEUE = "topic.queue";
public final static String TOPIC_DEV_QUEUE = "topic.dev.queue";
public final static String TOPIC_QUEUES = "topic.queues";
public final static String ROUTING_KEY1 = "topic.queue";
public final static String ROUTING_KEY2 = "#.queue";
public final static String ROUTING_KEYS = "topic.#";
@Bean
public Queue topicQueue() {
return new Queue(TOPIC_QUEUE);
}
@Bean
public Queue topicDevQueue() {
return new Queue(TOPIC_DEV_QUEUE);
}
@Bean
public Queue topicQueues() {
return new Queue(TOPIC_QUEUES);
}
@Bean
public TopicExchange topicExchange() {
return new TopicExchange(TOPIC_EXCHANGE);
}
@Bean
public Binding bindingExchangeMessage(Queue topicQueue, TopicExchange topicExchange) {
return BindingBuilder.bind(topicQueue).to(topicExchange).with(ROUTING_KEY1);
}
@Bean
public Binding bindingDevExchangeMessage(Queue topicDevQueue, TopicExchange topicExchange) {
return BindingBuilder.bind(topicDevQueue).to(topicExchange).with(ROUTING_KEY2);
}
@Bean
public Binding bindingExchangeMessages(Queue topicQueues, TopicExchange topicExchange) {
return BindingBuilder.bind(topicQueues).to(topicExchange).with(ROUTING_KEYS);
}
}
2. 消息的生产者
package com.zsx.service;
import com.zsx.config.TopicRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class TopicSender {
private final static Logger LOGGER = LoggerFactory.getLogger(TopicSender.class);
@Autowired
private AmqpTemplate amqpTemplate;
public void sendTopic() {
String msg = "topicMsg";
LOGGER.info("TopicSender.sendTopic send content: " + msg);
amqpTemplate.convertAndSend(TopicRabbitConfig.TOPIC_EXCHANGE, TopicRabbitConfig.ROUTING_KEY1, msg + "_1");
amqpTemplate.convertAndSend(TopicRabbitConfig.TOPIC_EXCHANGE, TopicRabbitConfig.ROUTING_KEY2, msg + "_2");
amqpTemplate.convertAndSend(TopicRabbitConfig.TOPIC_EXCHANGE, TopicRabbitConfig.ROUTING_KEYS, msg + "_s");
}
}
3. 消息的消费者
package com.zsx.service;
import com.zsx.config.TopicRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component
public class TopicReceiver {
private final static Logger LOGGER = LoggerFactory.getLogger(TopicReceiver.class);
@RabbitListener(queues = TopicRabbitConfig.TOPIC_QUEUE)
public void processTopic1(String msg) {
LOGGER.info("TopicReceiver.processTopic1 Received content: " + msg);
}
@RabbitListener(queues = TopicRabbitConfig.TOPIC_DEV_QUEUE)
public void processDevTopic(String msg) {
LOGGER.info("TopicReceiver.processDevTopic Received content: " + msg);
}
@RabbitListener(queues = TopicRabbitConfig.TOPIC_QUEUES)
public void processTopics(String msg) {
LOGGER.info("TopicReceiver.processTopics Received content: " + msg);
}
}
通过判断消息头的值能否与指定的绑定相匹配来确立路由规则,无视路由键(routingKey)
1. 交换机和队列配置
package com.zsx.config;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class HeaderRabbitConfig {
public final static String HEADERS_EXCHANGE = "headersExchange";
public final static String HEADERS_QUEUE1 = "headers.queue1";
@Bean
public HeadersExchange headersExchange(){
return new HeadersExchange(HEADERS_EXCHANGE);
}
@Bean
public Queue headerQueue() {
return new Queue(HEADERS_QUEUE1, true);
}
@Bean
public Binding headerBinding(Queue headerQueue, HeadersExchange headersExchange) {
Map map = new HashMap();
map.put("h1", "v1");
map.put("h2", "v2");
return BindingBuilder.bind(headerQueue).to(headersExchange).whereAll(map).match();
}
}
2. 消息的生产者
package com.zsx.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
@Component
public class HelloSender {
private final static Logger LOGGER = LoggerFactory.getLogger(HelloSender.class);
@Autowired
private AmqpTemplate amqpTemplate;
public void send() {
String context = "hello " + new Date();
LOGGER.info("HelloSender.send send content: " + context);
amqpTemplate.convertAndSend("hello", context);
}
}
3. 消息的消费者
package com.zsx.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component
@RabbitListener(queues = "hello")
public class HelloReceiver {
private final static Logger LOGGER = LoggerFactory.getLogger(HelloReceiver.class);
@RabbitHandler
public void process(String msg) {
LOGGER.info("HelloReceiver.process received content: " + msg);
}
}
五、测试类
package com.zsx.test;
import com.zsx.service.DirectSender;
import com.zsx.service.FanoutSender;
import com.zsx.service.HeaderSender;
import com.zsx.service.TopicSender;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class RabbitMQTest {
@Autowired
private DirectSender directSender;
@Autowired
private FanoutSender fanoutSender;
@Autowired
private TopicSender topicSender;
@Autowired
private HeaderSender headerSender;
@Test
void testContextLoads() {
directSender.sendDirect();
fanoutSender.sendFanout();
topicSender.sendTopic();
headerSender.sendHeader();
}
@Test
void testSendDirect() {
directSender.sendDirect();
}
@Test
void testSendFanout() {
fanoutSender.sendFanout();
}
@Test
void testSendTopic() {
topicSender.sendTopic();
}
@Test
void testSendHeader() {
headerSender.sendHeader();
}
}
5.1 测试运行测试方法,查看测试结果
C:\software\jdk-11.0.3\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\software\JetBrains\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar=23122:C:\software\JetBrains\IntelliJ IDEA 2019.1.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\software\JetBrains\IntelliJ IDEA 2019.1.3\lib\idea_rt.jar;C:\software\JetBrains\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit-rt.jar;C:\software\JetBrains\IntelliJ IDEA 2019.1.3\plugins\junit\lib\junit5-rt.jar;D:\repository\org\junit\vintage\junit-vintage-engine\5.3.2\junit-vintage-engine-5.3.2.jar;D:\repository\org\apiguardian\apiguardian-api\1.0.0\apiguardian-api-1.0.0.jar;D:\repository\org\junit\platform\junit-platform-engine\1.3.2\junit-platform-engine-1.3.2.jar;D:\repository\org\junit\platform\junit-platform-commons\1.3.2\junit-platform-commons-1.3.2.jar;D:\repository\org\opentest4j\opentest4j\1.1.1\opentest4j-1.1.1.jar;D:\repository\junit\junit\4.12\junit-4.12.jar;D:\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;F:\IdeaProjects\springboot\springboot-rabbitmq\target\test-classes;F:\IdeaProjects\springboot\springboot-rabbitmq\target\classes;D:\repository\org\springframework\boot\spring-boot-starter-amqp\2.1.7.RELEASE\spring-boot-starter-amqp-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter\2.1.7.RELEASE\spring-boot-starter-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot\2.1.7.RELEASE\spring-boot-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.7.RELEASE\spring-boot-autoconfigure-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-logging\2.1.7.RELEASE\spring-boot-starter-logging-2.1.7.RELEASE.jar;D:\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;D:\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;D:\repository\org\slf4j\jul-to-slf4j\1.7.26\jul-to-slf4j-1.7.26.jar;D:\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;D:\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;D:\repository\org\springframework\spring-messaging\5.1.9.RELEASE\spring-messaging-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-beans\5.1.9.RELEASE\spring-beans-5.1.9.RELEASE.jar;D:\repository\org\springframework\amqp\spring-rabbit\2.1.8.RELEASE\spring-rabbit-2.1.8.RELEASE.jar;D:\repository\org\springframework\amqp\spring-amqp\2.1.8.RELEASE\spring-amqp-2.1.8.RELEASE.jar;D:\repository\org\springframework\retry\spring-retry\1.2.4.RELEASE\spring-retry-1.2.4.RELEASE.jar;D:\repository\com\rabbitmq\amqp-client\5.4.3\amqp-client-5.4.3.jar;D:\repository\org\springframework\spring-context\5.1.9.RELEASE\spring-context-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-tx\5.1.9.RELEASE\spring-tx-5.1.9.RELEASE.jar;D:\repository\org\junit\platform\junit-platform-launcher\1.3.2\junit-platform-launcher-1.3.2.jar;D:\repository\org\junit\jupiter\junit-jupiter-engine\5.3.2\junit-jupiter-engine-5.3.2.jar;D:\repository\org\junit\jupiter\junit-jupiter-api\5.3.2\junit-jupiter-api-5.3.2.jar;D:\repository\org\springframework\boot\spring-boot-starter-web\2.1.7.RELEASE\spring-boot-starter-web-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-json\2.1.7.RELEASE\spring-boot-starter-json-2.1.7.RELEASE.jar;D:\repository\com\fasterxml\jackson\core\jackson-databind\2.9.9\jackson-databind-2.9.9.jar;D:\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;D:\repository\com\fasterxml\jackson\core\jackson-core\2.9.9\jackson-core-2.9.9.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.9\jackson-datatype-jdk8-2.9.9.jar;D:\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.9\jackson-datatype-jsr310-2.9.9.jar;D:\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.9\jackson-module-parameter-names-2.9.9.jar;D:\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.7.RELEASE\spring-boot-starter-tomcat-2.1.7.RELEASE.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.22\tomcat-embed-core-9.0.22.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.22\tomcat-embed-el-9.0.22.jar;D:\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.22\tomcat-embed-websocket-9.0.22.jar;D:\repository\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;D:\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;D:\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;D:\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;D:\repository\org\springframework\spring-web\5.1.9.RELEASE\spring-web-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-webmvc\5.1.9.RELEASE\spring-webmvc-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-aop\5.1.9.RELEASE\spring-aop-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-expression\5.1.9.RELEASE\spring-expression-5.1.9.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-starter-test\2.1.7.RELEASE\spring-boot-starter-test-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-test\2.1.7.RELEASE\spring-boot-test-2.1.7.RELEASE.jar;D:\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.1.7.RELEASE\spring-boot-test-autoconfigure-2.1.7.RELEASE.jar;D:\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;D:\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;D:\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;D:\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;D:\repository\org\slf4j\slf4j-api\1.7.26\slf4j-api-1.7.26.jar;D:\repository\org\assertj\assertj-core\3.11.1\assertj-core-3.11.1.jar;D:\repository\org\mockito\mockito-core\2.23.4\mockito-core-2.23.4.jar;D:\repository\net\bytebuddy\byte-buddy\1.9.16\byte-buddy-1.9.16.jar;D:\repository\net\bytebuddy\byte-buddy-agent\1.9.16\byte-buddy-agent-1.9.16.jar;D:\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;D:\repository\org\hamcrest\hamcrest-library\1.3\hamcrest-library-1.3.jar;D:\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;D:\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;D:\repository\org\springframework\spring-core\5.1.9.RELEASE\spring-core-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-jcl\5.1.9.RELEASE\spring-jcl-5.1.9.RELEASE.jar;D:\repository\org\springframework\spring-test\5.1.9.RELEASE\spring-test-5.1.9.RELEASE.jar;D:\repository\org\xmlunit\xmlunit-core\2.6.3\xmlunit-core-2.6.3.jar;D:\repository\org\glassfish\jaxb\jaxb-core\2.3.0.1\jaxb-core-2.3.0.1.jar;D:\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;D:\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;D:\repository\org\glassfish\jaxb\txw2\2.3.1\txw2-2.3.1.jar;D:\repository\com\sun\istack\istack-commons-runtime\3.0.5\istack-commons-runtime-3.0.5.jar;D:\repository\com\sun\xml\bind\jaxb-impl\2.3.2\jaxb-impl-2.3.2.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 com.zsx.test.RabbitMQTest,testContextLoads
14:46:48.578 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
14:46:48.590 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
14:46:48.608 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.zsx.test.RabbitMQTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
14:46:48.617 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.zsx.test.RabbitMQTest], using SpringBootContextLoader
14:46:48.619 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.RabbitMQTest]: class path resource [com/zsx/test/RabbitMQTest-context.xml] does not exist
14:46:48.620 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.RabbitMQTest]: class path resource [com/zsx/test/RabbitMQTestContext.groovy] does not exist
14:46:48.620 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.zsx.test.RabbitMQTest]: no resource found for suffixes {-context.xml, Context.groovy}.
14:46:48.620 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.zsx.test.RabbitMQTest]: RabbitMQTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
14:46:48.647 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.zsx.test.RabbitMQTest]
14:46:48.694 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [F:\IdeaProjects\springboot\springboot-rabbitmq\target\classes\com\zsx\RabbitMQApplication.class]
14:46:48.694 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.zsx.RabbitMQApplication for test class com.zsx.test.RabbitMQTest
14:46:48.756 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.zsx.test.RabbitMQTest]: using defaults.
14:46:48.756 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
14:46:48.767 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@25aca718, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@16fdec90, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@1afdd473, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@40238dd0, org.springframework.test.context.support.DirtiesContextTestExecutionListener@7776ab, org.springframework.test.context.transaction.TransactionalTestExecutionListener@79179359, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@dbd8e44, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@51acdf2e, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@6a55299e, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@2f1de2d6, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@4eb386df, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@79517588]
14:46:48.770 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@525575 testClass = RabbitMQTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@46dffdc3 testClass = RabbitMQTest, locations = '{}', classes = '{class com.zsx.RabbitMQApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@909217e, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@8458f04, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7ce69770, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@792b749c], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
14:46:48.788 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.7.RELEASE)
2019-08-27 14:46:49.106 INFO 11880 --- [ main] com.zsx.test.RabbitMQTest : Starting RabbitMQTest on zsx with PID 11880 (started by zhang in F:\IdeaProjects\springboot\springboot-rabbitmq)
2019-08-27 14:46:49.107 INFO 11880 --- [ main] com.zsx.test.RabbitMQTest : No active profile set, falling back to default profiles: default
2019-08-27 14:46:50.474 INFO 11880 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-27 14:46:50.738 INFO 11880 --- [ main] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [172.20.202.22:5672]
2019-08-27 14:46:50.771 INFO 11880 --- [ main] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory#66273da0:0/SimpleConnection@71179b6f [delegate=amqp://[email protected]:5672/, localPort= 23127]
2019-08-27 14:46:50.841 INFO 11880 --- [ main] com.zsx.test.RabbitMQTest : Started RabbitMQTest in 2.044 seconds (JVM running for 2.727)
2019-08-27 14:46:51.041 INFO 11880 --- [ main] com.zsx.service.DirectSender : DirectSender.sendDirect send content: directMsg
2019-08-27 14:46:51.045 INFO 11880 --- [ main] com.zsx.service.FanoutSender : FanoutSender.sendFanout send content: fanoutMsg
2019-08-27 14:46:51.046 INFO 11880 --- [ main] com.zsx.service.TopicSender : TopicSender.sendTopic send content: topicMsg
2019-08-27 14:46:51.047 INFO 11880 --- [ main] com.zsx.service.HeaderSender : HeaderSender.sendHeaders send content: headersMsg
2019-08-27 14:46:51.054 INFO 11880 --- [ntContainer#1-1] com.zsx.service.FanoutReceiver : FanoutReceiver.receiveFanout2 received content: fanoutMsg
2019-08-27 14:46:51.055 INFO 11880 --- [ntContainer#4-1] com.zsx.service.HeaderReceiver : HeaderReceiver.receiveHeaders received content: headersMsg
2019-08-27 14:46:51.056 INFO 11880 --- [ntContainer#7-1] com.zsx.service.TopicReceiver : TopicReceiver.processTopics Received content: topicMsg_1
2019-08-27 14:46:51.056 INFO 11880 --- [ntContainer#0-1] com.zsx.service.DirectReceiver : DirectReceiver.receiveDirect received content: directMsg
2019-08-27 14:46:51.056 INFO 11880 --- [ntContainer#6-1] com.zsx.service.TopicReceiver : TopicReceiver.processTopic1 Received content: topicMsg_1
2019-08-27 14:46:51.056 INFO 11880 --- [ntContainer#7-1] com.zsx.service.TopicReceiver : TopicReceiver.processTopics Received content: topicMsg_s
2019-08-27 14:46:51.055 INFO 11880 --- [ntContainer#3-1] com.zsx.service.FanoutReceiver : FanoutReceiver.receiveFanout3 received content: fanoutMsg
2019-08-27 14:46:51.056 INFO 11880 --- [ntContainer#8-1] com.zsx.service.TopicReceiver : TopicReceiver.processDevTopic Received content: topicMsg_1
2019-08-27 14:46:51.057 INFO 11880 --- [ntContainer#8-1] com.zsx.service.TopicReceiver : TopicReceiver.processDevTopic Received content: topicMsg_2
2019-08-27 14:46:51.055 INFO 11880 --- [ntContainer#2-1] com.zsx.service.FanoutReceiver : FanoutReceiver.receiveFanout1 received content: fanoutMsg
2019-08-27 14:46:51.061 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:52.066 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:52.070 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:53.060 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:53.063 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:54.062 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:54.064 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:55.064 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:55.067 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:56.064 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:56.068 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:56.832 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:56.835 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:57.064 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:57.068 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:58.066 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:58.069 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-08-27 14:46:59.066 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-08-27 14:46:59.074 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.074 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.074 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.075 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.075 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.075 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.075 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.075 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.075 INFO 11880 --- [ Thread-1] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-08-27 14:46:59.076 INFO 11880 --- [ Thread-1] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
Process finished with exit code 0