Merge pull request #37500 from vpavic

* gh-37500:
  Polish "Add properties for JmsTemplate session's ack mode and transacted flag"
  Add properties for JmsTemplate session's ack mode and transacted flag

Closes gh-37500
pull/37603/head
Andy Wilkinson 1 year ago
commit 1cb4941a16

@ -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,9 @@ public class JmsAutoConfiguration {
private void mapTemplateProperties(Template properties, JmsTemplate template) {
PropertyMapper map = PropertyMapper.get();
map.from(properties.getSession()::getAcknowledgeMode)
.to((acknowledgeMode) -> template.setSessionAcknowledgeMode(acknowledgeMode.getMode()));
map.from(properties.getSession()::isTransacted).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);

@ -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")
@ -267,6 +268,8 @@ public class JmsProperties {
*/
private Duration receiveTimeout;
private final Session session = new Session();
public String getDefaultDestination() {
return this.defaultDestination;
}
@ -330,6 +333,40 @@ public class JmsProperties {
this.receiveTimeout = receiveTimeout;
}
public Session getSession() {
return this.session;
}
public static class Session {
/**
* Acknowledge mode used when creating sessions.
*/
private AcknowledgeMode acknowledgeMode = AcknowledgeMode.AUTO;
/**
* Whether to use transacted sessions.
*/
private boolean transacted = false;
public AcknowledgeMode getAcknowledgeMode() {
return this.acknowledgeMode;
}
public void setAcknowledgeMode(AcknowledgeMode acknowledgeMode) {
this.acknowledgeMode = acknowledgeMode;
}
public boolean isTransacted() {
return this.transacted;
}
public void setTransacted(boolean transacted) {
this.transacted = transacted;
}
}
}
/**

@ -1571,6 +1571,10 @@
"name": "spring.jersey.type",
"defaultValue": "servlet"
},
{
"name": "spring.jms.template.session.acknowledge-mode",
"defaultValue": "auto"
},
{
"name": "spring.jpa.hibernate.use-new-id-generator-mappings",
"type": "java.lang.Boolean",

@ -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.session.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();

Loading…
Cancel
Save