diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java index e256a0a63d..21f6fd95a7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfiguration.java @@ -47,6 +47,7 @@ import org.springframework.jms.support.destination.DestinationResolver; * * @author Greg Turnquist * @author Stephane Nicoll + * @author Vedran Pavic * @since 1.0.0 */ @AutoConfiguration @@ -88,6 +89,10 @@ public class JmsAutoConfiguration { private void mapTemplateProperties(Template properties, JmsTemplate template) { PropertyMapper map = PropertyMapper.get(); + map.from(properties::getAcknowledgeMode) + .whenNonNull() + .to((acknowledgeMode) -> template.setSessionAcknowledgeMode(acknowledgeMode.getMode())); + map.from(properties::getSessionTransacted).whenNonNull().to(template::setSessionTransacted); map.from(properties::getDefaultDestination).whenNonNull().to(template::setDefaultDestinationName); map.from(properties::getDeliveryDelay).whenNonNull().as(Duration::toMillis).to(template::setDeliveryDelay); map.from(properties::determineQosEnabled).to(template::setExplicitQosEnabled); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java index a59218f85a..b5b4ec7d2e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JmsProperties.java @@ -27,6 +27,7 @@ import org.springframework.boot.context.properties.DeprecatedConfigurationProper * @author Greg Turnquist * @author Phillip Webb * @author Stephane Nicoll + * @author Vedran Pavic * @since 1.0.0 */ @ConfigurationProperties(prefix = "spring.jms") @@ -227,6 +228,16 @@ public class JmsProperties { public static class Template { + /** + * Acknowledgement mode used when creating JMS sessions to send a message. + */ + private AcknowledgeMode acknowledgeMode; + + /** + * Whether to use transacted JMS sessions. + */ + private Boolean sessionTransacted; + /** * Default destination to use on send and receive operations that do not have a * destination parameter. @@ -267,6 +278,22 @@ public class JmsProperties { */ private Duration receiveTimeout; + public AcknowledgeMode getAcknowledgeMode() { + return this.acknowledgeMode; + } + + public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) { + this.acknowledgeMode = acknowledgeMode; + } + + public Boolean getSessionTransacted() { + return this.sessionTransacted; + } + + public void setSessionTransacted(Boolean sessionTransacted) { + this.sessionTransacted = sessionTransacted; + } + public String getDefaultDestination() { return this.defaultDestination; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java index e89c071254..69071f2f13 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java @@ -253,7 +253,8 @@ class JmsAutoConfigurationTests { @Test void testJmsTemplateFullCustomization() { this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class) - .withPropertyValues("spring.jms.template.default-destination=testQueue", + .withPropertyValues("spring.jms.template.acknowledge-mode=client", + "spring.jms.template.session-transacted=true", "spring.jms.template.default-destination=testQueue", "spring.jms.template.delivery-delay=500", "spring.jms.template.delivery-mode=non-persistent", "spring.jms.template.priority=6", "spring.jms.template.time-to-live=6000", "spring.jms.template.receive-timeout=2000") @@ -261,6 +262,8 @@ class JmsAutoConfigurationTests { JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class); assertThat(jmsTemplate.getMessageConverter()).isSameAs(context.getBean("myMessageConverter")); assertThat(jmsTemplate.isPubSubDomain()).isFalse(); + assertThat(jmsTemplate.getSessionAcknowledgeMode()).isEqualTo(Session.CLIENT_ACKNOWLEDGE); + assertThat(jmsTemplate.isSessionTransacted()).isTrue(); assertThat(jmsTemplate.getDefaultDestinationName()).isEqualTo("testQueue"); assertThat(jmsTemplate.getDeliveryDelay()).isEqualTo(500); assertThat(jmsTemplate.getDeliveryMode()).isOne();