activemq artemis - Closing JMSContext on failed connection - Stack Overflow

I have a Java SE application (jms client) that works with Artemis ActiveMQ. In the ActiveMQInitialConte

I have a Java SE application (jms client) that works with Artemis ActiveMQ. In the ActiveMQInitialContextFactory configuration, I have set reconnectAttempts = -1 so that, when the connection to the server is dropped, the connection is automatically reestablished.

Everything works fine and the connection is restored as expected. However, I noticed that when I try to call JMSContext::stop() / JMSContext::close() while the connection is broken (i.e., the client is in reconnect mode), the call blocks until the client manages to connect.

If I stop the application without calling JMSContext::stop() / JMSContext::close() when the connection is broken, it stops cleanly (apparently the implementation uses daemon threads) but this approach does not work for me, the service is used in a dialog and I want to release the occupied resources when it is closed.

this roughly illustrates the problem

java.naming.factory.initial=.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
connectionFactory.ConnectionFactory=tcp://192.168.0.1:1883?retryInterval=200&reconnectAttempts=-1
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");

JMSContext jmsContext = cf.createContext();
jmsContext.setExceptionListener(this::handleJMSException);

Topic topic = jmsContext.createTopic("topicName");
jmsContext.createConsumer(topic).setMessageListener(this::onMessage);

...

setOnCloseRequest(dialogEvent -> {
    if(jmsContext != null) {
        jmsContext.close();
    }
});

I have a Java SE application (jms client) that works with Artemis ActiveMQ. In the ActiveMQInitialContextFactory configuration, I have set reconnectAttempts = -1 so that, when the connection to the server is dropped, the connection is automatically reestablished.

Everything works fine and the connection is restored as expected. However, I noticed that when I try to call JMSContext::stop() / JMSContext::close() while the connection is broken (i.e., the client is in reconnect mode), the call blocks until the client manages to connect.

If I stop the application without calling JMSContext::stop() / JMSContext::close() when the connection is broken, it stops cleanly (apparently the implementation uses daemon threads) but this approach does not work for me, the service is used in a dialog and I want to release the occupied resources when it is closed.

this roughly illustrates the problem

java.naming.factory.initial=.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
connectionFactory.ConnectionFactory=tcp://192.168.0.1:1883?retryInterval=200&reconnectAttempts=-1
ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");

JMSContext jmsContext = cf.createContext();
jmsContext.setExceptionListener(this::handleJMSException);

Topic topic = jmsContext.createTopic("topicName");
jmsContext.createConsumer(topic).setMessageListener(this::onMessage);

...

setOnCloseRequest(dialogEvent -> {
    if(jmsContext != null) {
        jmsContext.close();
    }
});
Share Improve this question asked Nov 19, 2024 at 11:10 mr mcwolfmr mcwolf 2,8792 gold badges17 silver badges33 bronze badges 2
  • The ClientConsumerImpl close method has a timeout of 10 seconds, could you confirm that the JMSContext::close() method returns after 10 seconds when the connection is broken? – Domenico Francesco Bruscino Commented Nov 19, 2024 at 14:23
  • @DomenicoFrancescoBruscino, No, if there is a timeout, it is in minutes (I waited a few minutes to see if the timeout would work, but it didn't). I don't know if it matters, but I'm testing on Linux (I'm using artemis-jms-client version 2.31.0 but I also tested with 2.38.0 and the behavior is the same) – mr mcwolf Commented Nov 19, 2024 at 15:05
Add a comment  | 

1 Answer 1

Reset to default 2

ActiveMQ Artemis JMS client tries to send a closing message to the server for every active consumer, producer and session and waits for a closing message response. After the callTimeout the client gives up but during a reconnect attempt it also waits for the callFailoverTimeout.

The default value for the callTimeout and callFailoverTimeout is 30000 milliseconds. Reducing it speeds up the context closure but also increases the risk of getting an error during a network glitch.

connectionFactory.ConnectionFactory=tcp://192.168.0.1:1883?retryInterval=200&reconnectAttempts=-1&callTimeout=5000&callFailoverTimeout=5000

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745565262a4633355.html

相关推荐

  • activemq artemis - Closing JMSContext on failed connection - Stack Overflow

    I have a Java SE application (jms client) that works with Artemis ActiveMQ. In the ActiveMQInitialConte

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信