RabbitMQ 服务器中的连接在 600 秒后自动丢失 [英] Connection in RabbitMQ server auto lost after 600s

查看:34
本文介绍了RabbitMQ 服务器中的连接在 600 秒后自动丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 amq 的 rabbitMQ 服务器.

I'm using rabbitMQ server with amq.

我遇到了一个难题.离开服务器约10分钟后,连接丢失.

I am having a difficult problem. After leaving the server alone for about 10 min, the connection is lost.

这可能是什么原因造成的?

What could be causing this?

推荐答案

RabbitMQ 连接工厂的默认连接超时为 600 秒(至少在 Java 客户端 API 中),因此您的 10 分钟.您可以通过向连接工厂指定您选择的超时来更改此设置.

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

确保您的连接在特定时间后被释放和重新创建是一种很好的做法,以防止最终泄漏和过多的资源.您的代码应确保它寻找一个有效的连接,该连接不会超时,并在超时的连接上重新建立新连接.总的来说,采用连接池方法.

It is good practice to ensure your connection is release and recreated after a specific amount of time, to prevent eventual leaks and excessive resournces. Your code should ensure that it seeks a valid connection that is not close to be timed-out, and re-establish a new connection on the ones that did time-out. Overall, adopt a connection-pooling approach.

- Java 示例:

    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();

这篇关于RabbitMQ 服务器中的连接在 600 秒后自动丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆