Commit 4e31d204 authored by Arlo O'Keeffe's avatar Arlo O'Keeffe Committed by Stephane Nicoll

Make RabbitTemplate exchange and routingKey configurable

See gh-10978
parent 4eda29a4
...@@ -188,6 +188,9 @@ public class RabbitAutoConfiguration { ...@@ -188,6 +188,9 @@ public class RabbitAutoConfiguration {
if (templateProperties.getReplyTimeout() != null) { if (templateProperties.getReplyTimeout() != null) {
rabbitTemplate.setReplyTimeout(templateProperties.getReplyTimeout()); rabbitTemplate.setReplyTimeout(templateProperties.getReplyTimeout());
} }
rabbitTemplate.setExchange(templateProperties.getExchange());
rabbitTemplate.setRoutingKey(templateProperties.getRoutingKey());
rabbitTemplate.setChannelTransacted(templateProperties.isChannelTransacted());
return rabbitTemplate; return rabbitTemplate;
} }
......
...@@ -703,6 +703,21 @@ public class RabbitProperties { ...@@ -703,6 +703,21 @@ public class RabbitProperties {
*/ */
private Long replyTimeout; private Long replyTimeout;
/**
* Name of the default exchange to use for send operations.
*/
private String exchange = "";
/**
* Value of a default routing key to use for send operations.
*/
private String routingKey = "";
/**
* Enable transactional channels.
*/
private boolean channelTransacted;
public Retry getRetry() { public Retry getRetry() {
return this.retry; return this.retry;
} }
...@@ -731,6 +746,30 @@ public class RabbitProperties { ...@@ -731,6 +746,30 @@ public class RabbitProperties {
this.replyTimeout = replyTimeout; this.replyTimeout = replyTimeout;
} }
public String getExchange() {
return this.exchange;
}
public void setExchange(String exchange) {
this.exchange = exchange;
}
public String getRoutingKey() {
return this.routingKey;
}
public void setRoutingKey(String routingKey) {
this.routingKey = routingKey;
}
public boolean isChannelTransacted() {
return this.channelTransacted;
}
public void setChannelTransacted(boolean channelTransacted) {
this.channelTransacted = channelTransacted;
}
} }
public static class Retry { public static class Retry {
......
...@@ -103,6 +103,21 @@ public class RabbitAutoConfigurationTests { ...@@ -103,6 +103,21 @@ public class RabbitAutoConfigurationTests {
}); });
} }
@Test
public void testDefaultRabbitTemplateConfiguration() {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
.run((context) -> {
RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
RabbitTemplate defaultRabbitTemplate = new RabbitTemplate();
assertThat(rabbitTemplate.getRoutingKey())
.isEqualTo(defaultRabbitTemplate.getRoutingKey());
assertThat(rabbitTemplate.getExchange())
.isEqualTo(defaultRabbitTemplate.getExchange());
assertThat(rabbitTemplate.isChannelTransacted())
.isEqualTo(defaultRabbitTemplate.isChannelTransacted());
});
}
@Test @Test
public void testConnectionFactoryWithOverrides() { public void testConnectionFactoryWithOverrides() {
this.contextRunner.withUserConfiguration(TestConfiguration.class) this.contextRunner.withUserConfiguration(TestConfiguration.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment