Automatically switch to RabbitMQ server after 600 seconds

I am using rabbitMQ server with amq.

I have a difficult problem. After exiting the server for about 10 minutes, the connection will be lost.

What could be the reason for this?

+5
timeout rabbitmq
source share
2 answers

The default connection timeout for a RabbitMQ factory connection is 600 seconds (at least in the Java API), so your 10 minutes. You can change this by pointing to the factory connection your choice timeout.

It is good practice to ensure that your connection is released and recreated after a certain amount of time to prevent possible leaks and excessive resources. Your code must ensure that it searches for the correct connection that is not close to the timeout, and re-establish a new connection with those that timed out. In general, take the channel aggregation approach.

- Java example:

ConnectionFactory factory = new ConnectionFactory(); factory.setHost(this.serverName); factory.setPort(this.serverPort); factory.setUsername(this.userName); factory.setPassword(this.userPassword); factory.setConnectionTimeout( YOUR-TIMEOUT-IN-SECONDS ); Connection = factory.newConnection(); 
+3
source share

If you look at the Erlang client documentation http://www.rabbitmq.com/erlang-client-user-guide.html , you will see the section "Connecting to a broker"

This gives you several different parameters that you can specify when setting up the connection to the RabbitMQ server, one of the parameters is heartbeat , since you see that the default value is 0 , so not a single beat is indicated.

I don't know the exact Erlang entry, but you will need to do something like:

 {ok, Connection} = amqp_connection:start(#amqp_params_network{heartbeat = 5}) 

The heartbeat timeout is indicated in seconds. Thus, this will cause your consumer to return to the server every 5 seconds.

Also take a look at this discussion: https://groups.google.com/forum/?fromgroups=#!topic/rabbitmq-discuss/u227xzvqOr8

+2
source share

All Articles