0
votes

I am trying to introduce a timeout on my producer when sending messages to ActiveMQ Artemis broker 2.17.0. I use the following code for this purpose

@Bean
public ConnectionFactory jmsConnectionFactoryOnline() {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(brokerUrl,username,password);
    connectionFactory.setCallTimeout(5000);
    return connectionFactory;
}

@Bean
public JmsPoolConnectionFactory pooledConnectionFactory() {
    JmsPoolConnectionFactory poolingFactory = new JmsPoolConnectionFactory();
    poolingFactory.setConnectionFactory(jmsConnectionFactoryOnline());
    poolingFactory.setMaxConnections(MAX_CONNECTIONS);
    poolingFactory.setMaxSessionsPerConnection(MAX_SESSIONS_PER_CONNECTION);
    poolingFactory.setConnectionIdleTimeout(0);

    return poolingFactory;
}

When I simulate losing network on the ActiveMQ Artemis node using iptables -A INPUT -s ip_producer -j DROP I can see on producer side that current connections honor the timeout of 5sec initially set.

Unfortunately following requests (new connections) seem to ignore it since I can observe producer waiting for the next calls up to Connection timeout interval (60sec) before declaring the request broken.

Can you guide me how to resolve this, or point to me what am I doing wrong and I cannot set a timeout on my producer?

1
Do you have any thread dumps which demonstrate where the new connections are waiting for 60 seconds? This sounds like a possible bug or it could be that the code is in an area where the call timeout doesn't apply. - Justin Bertram
Actually, I would like to clarify if callTimeout is about also acquiring connections because first time it fails Timed out after waiting 5,000 ms for response when sending packet 45 [code=CONNECTION_TIMEDOUT] and then I suppose it has no longer a connection with the broker (or the broker closes it). Then the second time it is called as I can now understand it tries to acquire a new one and it fails after it expires the connection timeout set and not immediately after 5sec as I had set on ConnectionFactory callTimeout (still no network available). Is that a correct assumption? - ypanag
This is also what I was attempting to clarify which is why I asked for the thread dump. I wanted to see exactly where the code was waiting so I could look at the code and determine if the call timeout applies there. Without such detail it will be hard to answer your question conclusively. - Justin Bertram
Also, the broker won't close the connection because the client timed out its call. The broker doesn't know or care about such client timeouts. However, Spring might close the connection itself upon receiving the Exception generated by the timeout. - Justin Bertram
Justin thanks for the response, I'll try to extract some logs hopefully soon and I hope they shall be helpful - ypanag

1 Answers

0
votes

The ConnectionTTL attribute of ActiveMQConnectionFactory determines how long a connection will be keep alive in the absence of any data arriving and its default value is 60 seconds.

Seting the ConnectionTTL attribute with a value lower than 60000 will reduce the connection timeout.