增加春兔的心跳值 [英] Increase heartbeat value in spring rabbit

查看:45
本文介绍了增加春兔的心跳值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设置面临一些问题我正在尝试增加心跳间隔以测试可能的修复方法.我正在使用

I'm facing some problems with my setup and I'm trying to increase the heartbeat interval in order to test a possible fix. I'm using

Spring boot 1.3.2.RELEASE
Spring rabbit 1.5.3.RELEASE

实例化连接工厂的代码如下

And the code instantiating the connection factory is the below

RabbitConnectionFactoryBean connectionFactoryBean = new RabbitConnectionFactoryBean();
connectionFactoryBean.setUseSSL(useSsl);
connectionFactoryBean.setHost(rabbitHostname);
connectionFactoryBean.setVirtualHost(rabbitVhost);
connectionFactoryBean.setUsername(rabbitUsername);
connectionFactoryBean.setPassword(rabbitPassword);
connectionFactoryBean.setConnectionTimeout(900000);
connectionFactoryBean.setRequestedHeartbeat(900);
connectionFactoryBean.afterPropertiesSet();

CachingConnectionFactory cf = new CachingConnectionFactory(connectionFactoryBean.getObject());
cf.setChannelCacheSize(40);
return cf;

问题是心跳间隔没有改变.我在 AMQConnection 中快速查看显示以下

The problem is that the heartbeat interval is not changing. I quick look in AMQConnection reveals the below

int heartbeat = negotiatedMaxValue(this.requestedHeartbeat,
                                   connTune.getHeartbeat());


private static int negotiatedMaxValue(int clientValue, int serverValue) {
        return (clientValue == 0 || serverValue == 0) ?
            Math.max(clientValue, serverValue) :
            Math.min(clientValue, serverValue);
}

来自服务器的值是 60.方法 negotiatedMaxValue 将不尊重客户端的首选项(不能禁用或增加心跳).我错过了什么吗?

The value coming from the server is 60. The method negotiatedMaxValue will not respect the client's preferences (cannot disable heartbeat nor increase it). Am I missing something?

推荐答案

你说得对.AMQConnection 将根据该方法确定心跳值,然后使用 TuneOk 方法将该值发送到服务器 (https://www.rabbitmq.com/amqp-0-9-1-reference.html#connection.tune-ok).您可以看到它从您看到调用方法的位置向下几行发送了协商的MaxValue()的结果:

You are correct. The AMQConnection will determine the heartbeat value based on that method and then sends that value with the TuneOk method to the server (https://www.rabbitmq.com/amqp-0-9-1-reference.html#connection.tune-ok). You can see it sends the result of the negotiatedMaxValue() a few lines down from where you see the call to the method:

_channel0.transmit(new AMQP.Connection.TuneOk.Builder()
    .channelMax(channelMax)
    .frameMax(frameMax)
    .heartbeat(heartbeat)
    .build());

似乎基于代码的逻辑,您只能减少心跳,但最大心跳将是服务器发送的任何内容,并且不能增加更多.RabbitMQ 文档对能够增加服务器最初发送的心跳的细节有些含糊,但确实说它可以被覆盖:https://www.rabbitmq.com/heartbeats.html

It seems based on the logic of the code that you can only reduce the heartbeat but the maximum heartbeat will be whatever the server sends and can't be increased more than that. RabbitMQ documentation is a little vague on the specifics of being able to increase the heartbeat that the server initially sends but does say it can be overwritten: https://www.rabbitmq.com/heartbeats.html

我检查了最新版本的 spring rabbit 并且它仍然具有相同的配置,因此看起来不会很快发生变化.

I checked in the latest version of spring rabbit and it still has the same configuration so doesn't look like it is changing anytime soon.

检查 RabbitMQ GitHub 没有显示任何关于将心跳值设置为大于服务器发送值的现有问题.也许在那里提交一个问题,看看开发人员怎么说?https://github.com/rabbitmq/rabbitmq-java-client/issues?utf8=%E2%9C%93&q=heartbeat

Checking the RabbitMQ GitHub doesn't show any existing issues around setting the heartbeat value greater than the server's sent value. Maybe submit an issue there and see what the developers say? https://github.com/rabbitmq/rabbitmq-java-client/issues?utf8=%E2%9C%93&q=heartbeat

这篇关于增加春兔的心跳值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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