-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
I have an application that defines a JmsTemplate bean in the following way:
@Bean
JmsTemplate jmsTemplate(ConnectionFactory connectionFactory, JmsProperties jmsProperties) {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setDefaultDestinationName(jmsProperties.getTemplate().getDefaultDestination());
jmsTemplate.setReceiveTimeout(jmsProperties.getTemplate().getReceiveTimeout().toMillis());
jmsTemplate.setMessageConverter(new CustomMessageConverter());
jmsTemplate.setSessionTransacted(true);
return jmsTemplate;
}I would like to remove this bean definition and rely on the JmsTemplateConfiguration only:
Lines 60 to 106 in 83666d4
| protected static class JmsTemplateConfiguration { | |
| private final JmsProperties properties; | |
| private final ObjectProvider<DestinationResolver> destinationResolver; | |
| private final ObjectProvider<MessageConverter> messageConverter; | |
| public JmsTemplateConfiguration(JmsProperties properties, | |
| ObjectProvider<DestinationResolver> destinationResolver, | |
| ObjectProvider<MessageConverter> messageConverter) { | |
| this.properties = properties; | |
| this.destinationResolver = destinationResolver; | |
| this.messageConverter = messageConverter; | |
| } | |
| @Bean | |
| @ConditionalOnMissingBean(JmsOperations.class) | |
| @ConditionalOnSingleCandidate(ConnectionFactory.class) | |
| public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) { | |
| PropertyMapper map = PropertyMapper.get(); | |
| JmsTemplate template = new JmsTemplate(connectionFactory); | |
| template.setPubSubDomain(this.properties.isPubSubDomain()); | |
| map.from(this.destinationResolver::getIfUnique).whenNonNull().to(template::setDestinationResolver); | |
| map.from(this.messageConverter::getIfUnique).whenNonNull().to(template::setMessageConverter); | |
| mapTemplateProperties(this.properties.getTemplate(), template); | |
| return template; | |
| } | |
| private void mapTemplateProperties(Template properties, JmsTemplate template) { | |
| PropertyMapper map = PropertyMapper.get(); | |
| 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); | |
| map.from(properties::getDeliveryMode) | |
| .whenNonNull() | |
| .as(DeliveryMode::getValue) | |
| .to(template::setDeliveryMode); | |
| map.from(properties::getPriority).whenNonNull().to(template::setPriority); | |
| map.from(properties::getTimeToLive).whenNonNull().as(Duration::toMillis).to(template::setTimeToLive); | |
| map.from(properties::getReceiveTimeout) | |
| .whenNonNull() | |
| .as(Duration::toMillis) | |
| .to(template::setReceiveTimeout); | |
| } | |
| } |
but I wasn't able to configure the sessionTransacted property via the JmsProperties.
I could introduce a BeanPostProcessor to amend the property but it's not really my preference right now 🙂
The Javadoc of AcknowledgeMode mentions:
Lines 322 to 329 in 83666d4
| /** | |
| * Translate the acknowledge modes defined on the {@link jakarta.jms.Session}. | |
| * | |
| * <p> | |
| * {@link jakarta.jms.Session#SESSION_TRANSACTED} is not defined as we take care of | |
| * this already through a call to {@code setSessionTransacted}. | |
| */ | |
| public enum AcknowledgeMode { |
but I couldn't figure out where the call to setSessionTransacted actually happens, or in general how it's supposed to work.
If this property is indeed missing from JmsProperties, I would be happy to provide a PR to add it.
Otherwise, I would love to get some guidance 🙏