Skip to content

Back-off for DefaultMessageListenerContainer is not applied consistently in case of listener setup failure #36143

@joshdcu

Description

@joshdcu

Description

A BackOff policy can be configured for the JMS message listener container using the setBackOff(BackOff backOff) method (ref-1, ref-2). However, this policy is not applied consistently when a JMSException is encountered and the listener tries to recover.

Reproduction

The reproduction is based on the JMS messaging guide on the Spring Boot documentation website with the following changes:

  • no use of custom Email class for simplicity
  • the listener container factory is configured with a fixed backoff policy of 3 maximum attempts with 1s between each attempt
  • Artemis is used in the native mode to reproduce the issue
  1. Ensure Java 21, a recent version of Maven, and Docker/Podman are installed on your machine.
  2. Download the project ZIP (demo.zip) to your machine and extract it.
  3. Build the app by running mvn clean package at the root of the project.
  4. Launch Artemis as a container:
podman run -d --name artemis -p 61616:61616 docker.io/apache/activemq-artemis:2.44.0-alpine
  1. Create a test user in Artemis:
podman exec artemis /var/lib/artemis-instance/bin/artemis user add --user artemis --password artemis --user-command-user test-user --user-command-password test-pswd --role test-role

Sample output:

Connection brokerURL = tcp://localhost:61616
test-user added successfully.

Expected Behaviour 1

Run the app and see that the message is sent and received successfully:

java -jar target/demo-0.0.1-SNAPSHOT.jar

Sample output:

2026-01-14T13:07:44.256+05:30  INFO 3644 --- [demo] [           main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT using Java 21.0.9 with PID 3644 (C:\Users\USERNAME\Desktop\demo\target\demo-0.0.1-SNAPSHOT.jar started by USERNAME in C:\Users\USERNAME\Desktop\demo\demo)
2026-01-14T13:07:44.274+05:30  INFO 3644 --- [demo] [           main] com.example.demo.DemoApplication         : No active profile set, falling back to 1 default profile: "default"
2026-01-14T13:07:45.704+05:30  INFO 3644 --- [demo] [           main] com.example.demo.DemoApplication         : Started DemoApplication in 1.846 seconds (process running for 2.323)
Sending an email message.
Received <Hello from the other side>

Expected Behaviour 2

Run the app with the backoff Spring profile activated and observe that the listener is stopped as per the configured backoff policy:

java -Dspring.profiles.active=backoff -jar target/demo-0.0.1-SNAPSHOT.jar

In this scenario, a non-existent user is used to connect to Artemis.

Sample output:

2026-01-14T13:14:08.461+05:30 ERROR 35416 --- [demo] [ntContainer#0-1] o.s.j.l.DefaultMessageListenerContainer  : Could not refresh JMS Connection for destination 'mailbox' - retrying using FixedBackOff{interval=1000, currentAttempts=0, maxAttempts=3}. Cause: AMQ229031: Unable to validate user from 127.0.0.1:36414. Username: fake-user; SSL certificate subject DN: unavailable
2026-01-14T13:14:09.485+05:30  INFO 35416 --- [demo] [ntContainer#0-1] o.s.j.c.CachingConnectionFactory         : Encountered a JMSException - resetting the underlying JMS Connection

jakarta.jms.JMSSecurityException: AMQ229031: Unable to validate user from 127.0.0.1:41736. Username: fake-user; SSL certificate subject DN: unavailable      
        at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:580) ~[artemis-core-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:464) ~[artemis-core-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:456) ~[artemis-core-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQClientProtocolManager.createSessionContext(ActiveMQClientProtocolManager.java:305) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQClientProtocolManager.createSessionContext(ActiveMQClientProtocolManager.java:253) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createSessionChannel(ClientSessionFactoryImpl.java:1473) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createSessionInternal(ClientSessionFactoryImpl.java:834) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryImpl.createSession(ClientSessionFactoryImpl.java:348) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.jms.client.ActiveMQConnection.authorize(ActiveMQConnection.java:631) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]      
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:951) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:313) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:308) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]
        at org.springframework.jms.connection.SingleConnectionFactory.doCreateConnection(SingleConnectionFactory.java:475) ~[spring-jms-6.2.15.jar!/:6.2.15]   
        at org.springframework.jms.connection.SingleConnectionFactory.initConnection(SingleConnectionFactory.java:434) ~[spring-jms-6.2.15.jar!/:6.2.15]       
        at org.springframework.jms.connection.SingleConnectionFactory.getConnection(SingleConnectionFactory.java:340) ~[spring-jms-6.2.15.jar!/:6.2.15]        
        at org.springframework.jms.connection.SingleConnectionFactory.createConnection(SingleConnectionFactory.java:245) ~[spring-jms-6.2.15.jar!/:6.2.15]     
        at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:210) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.AbstractJmsListeningContainer.createSharedConnection(AbstractJmsListeningContainer.java:439) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.AbstractJmsListeningContainer.refreshSharedConnection(AbstractJmsListeningContainer.java:421) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.DefaultMessageListenerContainer.refreshConnectionUntilSuccessful(DefaultMessageListenerContainer.java:1147) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.DefaultMessageListenerContainer.recoverAfterListenerSetupFailure(DefaultMessageListenerContainer.java:1121) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1321) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
Caused by: ActiveMQSecurityException[errorType=SECURITY_EXCEPTION message=AMQ229031: Unable to validate user from 127.0.0.1:41736. Username: fake-user; SSL certificate subject DN: unavailable]
        ... 23 common frames omitted
# [REPEATS A COUPLE OF TIMES]
2026-01-14T13:14:11.537+05:30 ERROR 35416 --- [demo] [ntContainer#0-1] o.s.j.l.DefaultMessageListenerContainer  : Stopping container for destination 'mailbox': back-off policy does not allow for further attempts.

Inconsistent Behaviour

Run the app with the repro Spring profile activated and observe that the listener is not stopped as per the configured backoff policy and repeatedly tries to recover:

java -Dspring.profiles.active=repro -jar target/demo-0.0.1-SNAPSHOT.jar

In this scenario, a user without the required role/permission is used to connect to Artemis.

Sample output:

2026-01-14T13:25:44.290+05:30  INFO 35340 --- [demo] [ntContainer#0-8] o.s.j.c.CachingConnectionFactory         : Encountered a JMSException - resetting the underlying JMS Connection

jakarta.jms.JMSSecurityException: AMQ229213: User: test-user does not have permission='CONSUME' for queue mailbox on address mailbox
        at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:580) ~[artemis-core-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:464) ~[artemis-core-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.core.protocol.core.impl.ChannelImpl.sendBlocking(ChannelImpl.java:456) ~[artemis-core-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQSessionContext.createConsumer(ActiveMQSessionContext.java:414) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionImpl.internalCreateConsumer(ClientSessionImpl.java:1898) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:800) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.core.client.impl.ClientSessionImpl.createConsumer(ClientSessionImpl.java:750) ~[artemis-core-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.jms.client.ActiveMQSession.createClientConsumer(ActiveMQSession.java:1060) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]
        at org.apache.activemq.artemis.jms.client.ActiveMQSession.createConsumer(ActiveMQSession.java:927) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.jms.client.ActiveMQSession.createConsumer(ActiveMQSession.java:563) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]       
        at org.apache.activemq.artemis.jms.client.ActiveMQSession.createConsumer(ActiveMQSession.java:539) ~[artemis-jakarta-client-2.40.0.jar!/:2.40.0]       
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
        at org.springframework.jms.connection.CachingConnectionFactory$CachedSessionInvocationHandler.invoke(CachingConnectionFactory.java:422) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at jdk.proxy2/jdk.proxy2.$Proxy54.createConsumer(Unknown Source) ~[na:na]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.createConsumer(AbstractMessageListenerContainer.java:960) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:225) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1462) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1426) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1417) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1294) ~[spring-jms-6.2.15.jar!/:6.2.15]
        at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
Caused by: ActiveMQSecurityException[errorType=SECURITY_EXCEPTION message=AMQ229213: User: test-user does not have permission='CONSUME' for queue mailbox on address mailbox]
        ... 22 common frames omitted

2026-01-14T13:25:44.299+05:30  WARN 35340 --- [demo] [ntContainer#0-8] o.s.j.l.DefaultMessageListenerContainer  : Setup of JMS message listener invoker failed for destination 'mailbox' - trying to recover. Cause: AMQ229213: User: test-user does not have permission='CONSUME' for queue mailbox on address mailbox       
# [REPEATS CONTINUOUSLY]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions