Add boolean flag spring.rabbit.listener.useTransactionManager

If set *and* there is a transaction manager in the context, then the
listener container created by Spring Boot will use the transaction
manager to execute the listeners.

Fixes gh-3432 (by virtue of not requiring a JtaTransactionManager any
more).
pull/3630/head
Dave Syer 9 years ago
parent f6c395d0a6
commit 67933ab01f

@ -25,7 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
/**
* Configuration for Spring AMQP annotation driven endpoints.
@ -38,15 +38,16 @@ import org.springframework.transaction.jta.JtaTransactionManager;
class RabbitAnnotationDrivenConfiguration {
@Autowired(required = false)
private JtaTransactionManager transactionManager;
private PlatformTransactionManager transactionManager;
@Bean
@ConditionalOnMissingBean(name = "rabbitListenerContainerFactory")
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
ConnectionFactory connectionFactory) {
ConnectionFactory connectionFactory, RabbitProperties config) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
if (this.transactionManager != null) {
if (this.transactionManager != null
&& config.getListener().isUseTransactionManager()) {
factory.setTransactionManager(this.transactionManager);
}
return factory;

@ -91,7 +91,7 @@ public class RabbitAutoConfiguration {
@Bean
@ConditionalOnMissingBean(RabbitTemplate.class)
public RabbitTemplate rabbitTemplate() {
public RabbitTemplate rabbitTemplate(RabbitProperties config) {
return new RabbitTemplate(this.connectionFactory);
}

@ -62,6 +62,12 @@ public class RabbitProperties {
*/
private String addresses;
private Listener listener = new Listener();
public Listener getListener() {
return this.listener;
}
public String getHost() {
if (this.addresses == null) {
return this.host;
@ -156,4 +162,16 @@ public class RabbitProperties {
this.virtualHost = ("".equals(virtualHost) ? "/" : virtualHost);
}
public static class Listener {
private boolean useTransactionManager = false;
public boolean isUseTransactionManager() {
return this.useTransactionManager;
}
public void setUseTransactionManager(boolean useTransactionManager) {
this.useTransactionManager = useTransactionManager;
}
}
}

Loading…
Cancel
Save