Closed as not planned
Description
I'm trying to simulate a reconnect with this scenario:
- Client 1 connects to ActiveMQ
- Client 2 connects to ActiveMQ with failover/reconnection with same clientId as client 1 - expected to throw already connected error
- Kill client 1 (doesn't call close or properly clean up the connection)
- Expect that client 2 reconnects after awhile
Client 2 somehow cannot reconnect and leaves a dead connection to the broker. Rerunning client 1 or 2 after the scenario throws already connected error too.
Client 1 test case:
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "guest", "guest",
"tcp://localhost:61616" );
connectionFactory.setClientID( "guest" );
Connection connection = connectionFactory.createConnection();
connection.start();
Thread.sleep( Long.MAX_VALUE );
Client 2 test case:
String clientId = "guest";
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "guest", "guest",
"failover:(tcp://localhost:61616)" );
connectionFactory.setClientID( clientId );
SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory( connectionFactory );
singleConnectionFactory.setClientId( clientId );
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory( singleConnectionFactory );
container.setDestinationName( "topic://test" );
container.afterPropertiesSet();
container.start();
Thread.sleep( Long.MAX_VALUE );
Both clients connect to the same broker and has a maxInactivityDuration
set to 10000
. I expect ActiveMQ to clean up client 1 after 10s with this parameter set but doesn't work too.
Exception thrown by client 2:
30/05/19 10:23:11.735 INFO [DefaultMessageListenerContainer] JMS message listener invoker needs to establish shared Connection
30/05/19 10:23:11.746 ERROR [DefaultMessageListenerContainer] Could not refresh JMS Connection for destination 'topic://test' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Broker: localhost - Client: guest already connected from tcp://127.0.0.1:64437
30/05/19 10:23:16.753 ERROR [DefaultMessageListenerContainer] Could not refresh JMS Connection for destination 'topic://test' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: Broker: localhost - Client: guest already connected from tcp://127.0.0.1:64455
30/05/19 10:23:21.761 ERROR [DefaultMessageListenerContainer] Could not refresh JMS Connection for destination 'topic://test' - retrying using FixedBackOff{interval=5000, currentAttempts=2, maxAttempts=unlimited}. Cause: Broker: localhost - Client: guest already connected from tcp://127.0.0.1:64455
... (and so on)
Observations:
- If client 2 uses a
SingleConnectionFactory/CachingConnectionFactory
, it cannot reconnect. - If client 2 uses
ActiveMQConnectionFactory
on its container, it's able to reconnect. (showedSuccessfully refreshed JMS Connection
) - Based on the exception log, it first says that client 1 is connected - port:64437, after stopping client 1, it says that there is another client connected - port:64455
Spring version: 4.3.24.RELEASE
ActiveMQ JMS client library version: 5.15.9
ActiveMQ broker version: 5.15.9