Make RabbitTemplate exchange and routingKey configurable
See gh-10978
This commit is contained in:
parent
4eda29a42e
commit
4e31d2041a
|
|
@ -188,6 +188,9 @@ public class RabbitAutoConfiguration {
|
|||
if (templateProperties.getReplyTimeout() != null) {
|
||||
rabbitTemplate.setReplyTimeout(templateProperties.getReplyTimeout());
|
||||
}
|
||||
rabbitTemplate.setExchange(templateProperties.getExchange());
|
||||
rabbitTemplate.setRoutingKey(templateProperties.getRoutingKey());
|
||||
rabbitTemplate.setChannelTransacted(templateProperties.isChannelTransacted());
|
||||
return rabbitTemplate;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -703,6 +703,21 @@ public class RabbitProperties {
|
|||
*/
|
||||
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() {
|
||||
return this.retry;
|
||||
}
|
||||
|
|
@ -731,6 +746,30 @@ public class RabbitProperties {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
public void testConnectionFactoryWithOverrides() {
|
||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||
|
|
|
|||
Loading…
Reference in New Issue