Browse Source

Merge pull request #13930 from ayudovin:make-rabbitTemplate-default-receive-queue-configurable

* pr/13930:
  Polish "Make RabbitTemplate default receive queue configurable"
  Make RabbitTemplate default receive queue configurable
pull/13966/head
Stephane Nicoll 8 years ago
parent
commit
3aef6016e2
  1. 2
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java
  2. 15
      spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java
  3. 12
      spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java
  4. 1
      spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

2
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; @@ -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 { @@ -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;
}

15
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; @@ -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 { @@ -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 { @@ -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 {

12
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; @@ -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 { @@ -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)

1
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. @@ -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.

Loading…
Cancel
Save