Is it possible to set the ActiveMQ transport parameters such as maxReconnectAttempts using a java API at the runtime?
In my case I'm creating the ActiveMQ connection factory initially by providing a basic failover url failover:
ActiveMQSslConnectionFactory connectionFactory = new ActiveMQSslConnectionFactory("(ssl://192.168.1.112:61617,ssl://192.168.1.112:61619)?randomize=false")
However later I would require to set transport parameter to this connection factory such as maxReconnectAttempts. Is it possible?
certainly, simply like this:
All failover Transport Options can be set in the url
http://activemq.apache.org/failover-transport-reference.html
If you want to change the url later, you can call
connectionFactory.setBrokerURL("newURL"), after that all new connections created will be configured with the new parameters of the url.if you want to change that after the creation of the ConnectionFactory, keep in mind that a new instance of FailoverTransport is created for each new Connection based on the url parameters and each Connection holds an instance of his FailoverTransport, so to change his state you can access it like this :
or more readable :
to understand why all these casts, you can take a look at source code of this method :
here https://github.com/apache/activemq/blob/master/activemq-client/src/main/java/org/apache/activemq/transport/failover/FailoverTransportFactory.java