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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user