Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveMQ timeout at connection

Tags:

java

jms

activemq

I have the following problem: I try to connect to an ActiveMQ broker (which is now down) using the following piece of code

connectionFactory = new ActiveMQConnectionFactory(this.url + "?timeout=2000");
connection = connectionFactory.createConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
LOGGER.info("Connected to " + this.url);

The problem is that the timeout does not have any effect

connection.start()

is blocked forever. I inspected ActiveMQ log and found the following info:

2013-12-20 01:49:03,149 DEBUG [ActiveMQ Task-1] (FailoverTransport.java:786) - urlList connectionList:[tcp://localhost:61616?timeout=2000], from: [tcp://localhost:61616?timeout=2000]
2013-12-20 01:49:03,149 DEBUG [ActiveMQ Task-1] (FailoverTransport.java:1040) - Connect fail to: tcp://localhost:61616?timeout=2000, reason: java.lang.IllegalArgumentException: Invalid connect parameters: {timeout=2000}

The timeout parameter is specified here http://activemq.apache.org/cms/configuring.html

Has anybody any idea how to pass timeout argument to ActiveMQConnectionFactory? Or how to set a timeout for connection.start() ? Thank you!

Update: I found this on Stackoverflow: ActiveMQ - CreateSession failover timeout after a connection is resumed . I tried it but the following exception is thrown:

javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {transport.timeout=5000}
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)

I use ActiveMQ 5.8.0 from maven repo

like image 620
nucandrei Avatar asked Dec 20 '13 00:12

nucandrei


People also ask

How does ActiveMQ failover work?

The Failover transport randomly chooses one of the composite URIs and attempts to establish a connection to it. If it does not succeed, or if it subsequently fails, a new connection is established choosing one of the other URIs randomly from the list.

What is ActiveMQ connection?

ActiveMQ allows client applications to connect using a variety of protocols, but also allows other brokers to create communication channels and to build complex networks of ActiveMQ brokers. We start this chapter by explaining connector URIs, which are used to address the broker.

How do I change my ActiveMQ port number?

You can change the port for ActiveMQ in the activemq. xml file. Just do a find on 61616 and replace it with the port you would like to use (it should be in the <transportConnector> tag with the name openwire ). You do not have to install ActiveMQ, simply launch activemq.

What port does ActiveMQ use?

There are three ports used by activemq : 61616 , 8181 and a random port.


1 Answers

It appears that your url is invalid still in both cases when attempting to set the timeout property.

If you're trying to have a failover URL, which it looks like you are since it is getting in to the Failover code then you're probably looking for initialReconnectDelay (and possibly maxReconnectAttempts which would throw an exception if the server is still down after the number of attempts is reached).

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("failover://(tcp://localhost:61616)?initialReconnectDelay=2000&maxReconnectAttempts=2");
like image 90
Andrew Avatar answered Sep 27 '22 17:09

Andrew