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:
@@ -144,6 +144,10 @@ When the JMS infrastructure is present, any bean can be annotated with `@JmsList
|
||||
If no `JmsListenerContainerFactory` has been defined, a default one is configured automatically.
|
||||
If a `DestinationResolver`, a `MessageConverter`, or a `jakarta.jms.ExceptionListener` beans are defined, they are associated automatically with the default factory.
|
||||
|
||||
In most scenarios, message listener containers should be configured against the native `ConnectionFactory`.
|
||||
This way each listener container has its own connection and this gives full responsibility to it in terms of local recovery.
|
||||
The auto-configuration uses `ConnectionFactoryUnwrapper` to unwrap the native connection factory from the auto-configured one.
|
||||
|
||||
By default, the default factory is transactional.
|
||||
If you run in an infrastructure where a `JtaTransactionManager` is present, it is associated to the listener container by default.
|
||||
If not, the `sessionTransacted` flag is enabled.
|
||||
@@ -163,6 +167,8 @@ For instance, the following example exposes another factory that uses a specific
|
||||
|
||||
include-code::custom/MyJmsConfiguration[]
|
||||
|
||||
NOTE: In the example above, the customization uses `ConnectionFactoryUnwrapper` to associate the native connection factory to the message listener container the same way the auto-configured factory does.
|
||||
|
||||
Then you can use the factory in any `@JmsListener`-annotated method as follows:
|
||||
|
||||
include-code::custom/MyBean[]
|
||||
|
||||
Reference in New Issue
Block a user