Polish "Add properties for JmsTemplate session's ack mode and transacted flag"

See gh-37500
pull/37603/head
Andy Wilkinson 1 year ago
parent 5ba4e2793d
commit 3adc70fd40

@ -89,10 +89,9 @@ public class JmsAutoConfiguration {
private void mapTemplateProperties(Template properties, JmsTemplate template) { private void mapTemplateProperties(Template properties, JmsTemplate template) {
PropertyMapper map = PropertyMapper.get(); PropertyMapper map = PropertyMapper.get();
map.from(properties::getAcknowledgeMode) map.from(properties.getSession()::getAcknowledgeMode)
.whenNonNull()
.to((acknowledgeMode) -> template.setSessionAcknowledgeMode(acknowledgeMode.getMode())); .to((acknowledgeMode) -> template.setSessionAcknowledgeMode(acknowledgeMode.getMode()));
map.from(properties::getSessionTransacted).whenNonNull().to(template::setSessionTransacted); map.from(properties.getSession()::isTransacted).to(template::setSessionTransacted);
map.from(properties::getDefaultDestination).whenNonNull().to(template::setDefaultDestinationName); map.from(properties::getDefaultDestination).whenNonNull().to(template::setDefaultDestinationName);
map.from(properties::getDeliveryDelay).whenNonNull().as(Duration::toMillis).to(template::setDeliveryDelay); map.from(properties::getDeliveryDelay).whenNonNull().as(Duration::toMillis).to(template::setDeliveryDelay);
map.from(properties::determineQosEnabled).to(template::setExplicitQosEnabled); map.from(properties::determineQosEnabled).to(template::setExplicitQosEnabled);

@ -228,16 +228,6 @@ public class JmsProperties {
public static class Template { 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 * Default destination to use on send and receive operations that do not have a
* destination parameter. * destination parameter.
@ -278,21 +268,7 @@ public class JmsProperties {
*/ */
private Duration receiveTimeout; private Duration receiveTimeout;
public AcknowledgeMode getAcknowledgeMode() { private final Session session = new Session();
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() { public String getDefaultDestination() {
return this.defaultDestination; return this.defaultDestination;
@ -357,6 +333,40 @@ public class JmsProperties {
this.receiveTimeout = receiveTimeout; 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", "name": "spring.jersey.type",
"defaultValue": "servlet" "defaultValue": "servlet"
}, },
{
"name": "spring.jms.template.session.acknowledge-mode",
"defaultValue": "auto"
},
{ {
"name": "spring.jpa.hibernate.use-new-id-generator-mappings", "name": "spring.jpa.hibernate.use-new-id-generator-mappings",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",

@ -253,8 +253,8 @@ class JmsAutoConfigurationTests {
@Test @Test
void testJmsTemplateFullCustomization() { void testJmsTemplateFullCustomization() {
this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class) this.contextRunner.withUserConfiguration(MessageConvertersConfiguration.class)
.withPropertyValues("spring.jms.template.acknowledge-mode=client", .withPropertyValues("spring.jms.template.session.acknowledge-mode=client",
"spring.jms.template.session-transacted=true", "spring.jms.template.default-destination=testQueue", "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.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.priority=6", "spring.jms.template.time-to-live=6000",
"spring.jms.template.receive-timeout=2000") "spring.jms.template.receive-timeout=2000")

Loading…
Cancel
Save