admin管理员组文章数量:1023025
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
1 Answer
Reset to default 2ActiveMQ 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
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
1 Answer
Reset to default 2ActiveMQ 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
本文标签: activemq artemisClosing JMSContext on failed connectionStack Overflow
版权声明:本文标题:activemq artemis - Closing JMSContext on failed connection - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745565261a2156410.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论