Use native connection factory with message listener containers

This commit updates the auto-configuration to use the native connection
factory for configuring message listener containers. Previously, the
connection factory that could have been wrapped in a caching connection
factory was used.

While using a caching connection factory is suitable for sending
messages (i.e. JmsTemplate usage), it isn't for message listeners as
they need to own the connection for local recovery purposes.

Closes gh-39816
This commit is contained in:
Stéphane Nicoll
2024-07-12 16:05:33 +02:00
parent 369cfc4c4c
commit fc2890d1cd
10 changed files with 172 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2024 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.
@@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.jms.ConnectionFactoryUnwrapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
@@ -89,7 +90,7 @@ class JmsAnnotationDrivenConfiguration {
DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
DefaultJmsListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, connectionFactory);
configurer.configure(factory, ConnectionFactoryUnwrapper.unwrap(connectionFactory));
return factory;
}

View File

@@ -137,7 +137,7 @@ class JmsAutoConfigurationTests {
DefaultMessageListenerContainer container = containerFactory.createListenerContainer(jmsListenerEndpoint);
assertThat(container.getClientId()).isNull();
assertThat(container.getConcurrentConsumers()).isEqualTo(1);
assertThat(container.getConnectionFactory()).isSameAs(connectionFactory);
assertThat(container.getConnectionFactory()).isSameAs(connectionFactory.getTargetConnectionFactory());
assertThat(container.getMaxConcurrentConsumers()).isEqualTo(1);
assertThat(container.getSessionAcknowledgeMode()).isEqualTo(Session.AUTO_ACKNOWLEDGE);
assertThat(container.isAutoStartup()).isTrue();