diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java index b5610970b70..c9573b4fee5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java @@ -79,6 +79,7 @@ import org.springframework.context.annotation.Import; * @author Stephane Nicoll * @author Gary Russell * @author Phillip Webb + * @author Artsiom Yudovin */ @Configuration @ConditionalOnClass({ RabbitTemplate.class, Channel.class }) @@ -190,6 +191,7 @@ public class RabbitAutoConfiguration { .to(template::setReplyTimeout); map.from(properties::getExchange).to(template::setExchange); map.from(properties::getRoutingKey).to(template::setRoutingKey); + map.from(properties::getQueue).whenNonNull().to(template::setQueue); return template; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index abf24b7650a..02292ebeccb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -37,6 +37,7 @@ import org.springframework.util.StringUtils; * @author Andy Wilkinson * @author Josh Thornhill * @author Gary Russell + * @author Artsiom Yudovin */ @ConfigurationProperties(prefix = "spring.rabbitmq") public class RabbitProperties { @@ -713,6 +714,12 @@ public class RabbitProperties { */ private String routingKey = ""; + /** + * Name of the default queue to receive messages from when none is specified + * explicitly. + */ + private String queue; + public Retry getRetry() { return this.retry; } @@ -757,6 +764,14 @@ public class RabbitProperties { this.routingKey = routingKey; } + public String getQueue() { + return this.queue; + } + + public void setQueue(String queue) { + this.queue = queue; + } + } public static class Retry { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index b86deccb5be..37ef790aabf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -62,6 +62,7 @@ import org.springframework.retry.interceptor.MethodInvocationRecoverer; import org.springframework.retry.policy.NeverRetryPolicy; import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.retry.support.RetryTemplate; +import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.anyString; @@ -319,6 +320,17 @@ public class RabbitAutoConfigurationTests { }); } + @Test + public void testRabbitTemplateDefaultQueue() { + this.contextRunner.withUserConfiguration(TestConfiguration.class) + .withPropertyValues("spring.rabbitmq.template.queue:default-queue") + .run((context) -> { + RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class); + assertThat(ReflectionTestUtils.getField(rabbitTemplate, "queue")) + .isEqualTo("default-queue"); + }); + } + @Test public void testRabbitTemplateMandatory() { this.contextRunner.withUserConfiguration(TestConfiguration.class) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index a149580bdb6..f870f4385ab 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -1158,6 +1158,7 @@ content into your application. Rather, pick only the properties that you need. spring.rabbitmq.ssl.algorithm= # SSL algorithm to use. By default, configured by the Rabbit client library. spring.rabbitmq.template.exchange= # Name of the default exchange to use for send operations. spring.rabbitmq.template.mandatory= # Whether to enable mandatory messages. + spring.rabbitmq.template.queue= # Name of the default queue to receive messages from when none is specified explicitly. spring.rabbitmq.template.receive-timeout= # Timeout for `receive()` operations. spring.rabbitmq.template.reply-timeout= # Timeout for `sendAndReceive()` operations. spring.rabbitmq.template.retry.enabled=false # Whether publishing retries are enabled.