Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,6 +32,7 @@
*
* @author Stephane Nicoll
* @author Eddú Meléndez
* @author Vedran Pavic
* @since 1.3.3
*/
public final class DefaultJmsListenerContainerFactoryConfigurer {
Expand Down Expand Up @@ -101,12 +102,16 @@ public void configure(DefaultJmsListenerContainerFactory factory, ConnectionFact
Assert.notNull(connectionFactory, "ConnectionFactory must not be null");
factory.setConnectionFactory(connectionFactory);
factory.setPubSubDomain(this.jmsProperties.isPubSubDomain());
JmsProperties.Listener listener = this.jmsProperties.getListener();
if (this.transactionManager != null) {
factory.setTransactionManager(this.transactionManager);
}
else {
else if (listener.getSessionTransacted() == null) {
factory.setSessionTransacted(true);
}
if (listener.getSessionTransacted() != null) {
factory.setSessionTransacted(listener.getSessionTransacted());
}
if (this.destinationResolver != null) {
factory.setDestinationResolver(this.destinationResolver);
}
Expand All @@ -116,7 +121,6 @@ public void configure(DefaultJmsListenerContainerFactory factory, ConnectionFact
if (this.exceptionListener != null) {
factory.setExceptionListener(this.exceptionListener);
}
JmsProperties.Listener listener = this.jmsProperties.getListener();
factory.setAutoStartup(listener.isAutoStartup());
if (listener.getAcknowledgeMode() != null) {
factory.setSessionAcknowledgeMode(listener.getAcknowledgeMode().getMode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Greg Turnquist
* @author Phillip Webb
* @author Stephane Nicoll
* @author Vedran Pavic
* @since 1.0.0
*/
@ConfigurationProperties(prefix = "spring.jms")
Expand Down Expand Up @@ -146,6 +147,11 @@ public static class Listener {
*/
private AcknowledgeMode acknowledgeMode;

/**
* Whether the container should use transacted JMS sessions.
*/
private Boolean sessionTransacted;

/**
* Minimum number of concurrent consumers. When max-concurrency is not specified
* the minimum will also be used as the maximum.
Expand Down Expand Up @@ -180,6 +186,14 @@ public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) {
this.acknowledgeMode = acknowledgeMode;
}

public Boolean getSessionTransacted() {
return this.sessionTransacted;
}

public void setSessionTransacted(Boolean sessionTransacted) {
this.sessionTransacted = sessionTransacted;
}

@DeprecatedConfigurationProperty(replacement = "spring.jms.listener.min-concurrency", since = "3.2.0")
@Deprecated(since = "3.2.0", forRemoval = true)
public Integer getConcurrency() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* @author Stephane Nicoll
* @author Aurélien Leboulanger
* @author Eddú Meléndez
* @author Vedran Pavic
*/
class JmsAutoConfigurationTests {

Expand Down Expand Up @@ -143,15 +144,16 @@ void jmsListenerContainerFactoryWhenMultipleConnectionFactoryBeansShouldBackOff(
void testJmsListenerContainerFactoryWithCustomSettings() {
this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
.withPropertyValues("spring.jms.listener.autoStartup=false", "spring.jms.listener.acknowledgeMode=client",
"spring.jms.listener.minConcurrency=2", "spring.jms.listener.receiveTimeout=2s",
"spring.jms.listener.maxConcurrency=10")
"spring.jms.listener.sessionTransacted=false", "spring.jms.listener.minConcurrency=2",
"spring.jms.listener.receiveTimeout=2s", "spring.jms.listener.maxConcurrency=10")
.run(this::testJmsListenerContainerFactoryWithCustomSettings);
}

private void testJmsListenerContainerFactoryWithCustomSettings(AssertableApplicationContext loaded) {
DefaultMessageListenerContainer container = getContainer(loaded, "jmsListenerContainerFactory");
assertThat(container.isAutoStartup()).isFalse();
assertThat(container.getSessionAcknowledgeMode()).isEqualTo(Session.CLIENT_ACKNOWLEDGE);
assertThat(container.isSessionTransacted()).isFalse();
assertThat(container.getConcurrentConsumers()).isEqualTo(2);
assertThat(container.getMaxConcurrentConsumers()).isEqualTo(10);
assertThat(container).hasFieldOrPropertyWithValue("receiveTimeout", 2000L);
Expand Down Expand Up @@ -179,6 +181,18 @@ void testDefaultContainerFactoryWithJtaTransactionManager() {
});
}

@Test
void testDefaultContainerFactoryWithJtaTransactionManagerAndSessionTransactedEnabled() {
this.contextRunner.withUserConfiguration(TestConfiguration7.class, EnableJmsConfiguration.class)
.withPropertyValues("spring.jms.listener.sessionTransacted=true")
.run((context) -> {
DefaultMessageListenerContainer container = getContainer(context, "jmsListenerContainerFactory");
assertThat(container.isSessionTransacted()).isTrue();
assertThat(container).hasFieldOrPropertyWithValue("transactionManager",
context.getBean(JtaTransactionManager.class));
});
}

@Test
void testDefaultContainerFactoryNonJtaTransactionManager() {
this.contextRunner.withUserConfiguration(TestConfiguration8.class, EnableJmsConfiguration.class)
Expand All @@ -198,6 +212,17 @@ void testDefaultContainerFactoryNoTransactionManager() {
});
}

@Test
void testDefaultContainerFactoryNoTransactionManagerAndSessionTransactedDisabled() {
this.contextRunner.withUserConfiguration(EnableJmsConfiguration.class)
.withPropertyValues("spring.jms.listener.sessionTransacted=false")
.run((context) -> {
DefaultMessageListenerContainer container = getContainer(context, "jmsListenerContainerFactory");
assertThat(container.isSessionTransacted()).isFalse();
assertThat(container).hasFieldOrPropertyWithValue("transactionManager", null);
});
}

@Test
void testDefaultContainerFactoryWithMessageConverters() {
this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class, EnableJmsConfiguration.class)
Expand Down