如何配置 mosquitto 代理以增加与 mqtt 客户端的断开连接时间?

How to configure mosquitto broker to increase the disconnection time to mqtt clients?

mqtt文档说明keepalive的最大值是18小时12分15秒

但是,如果 mosquitto 服务器在 60 秒加上 30 秒的容差(即最多 90 秒)之前没有收到消息,则会断开客户端连接。

也就是说,我不能配置超过90秒的keepalive。

你没有在broker上配置keep alive,它是在客户端配置的。

该值在从客户端到代理的连接数据包中传递 (http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Keep_Alive)

如何配置它取决于您使用的客户端库,但大多数库都将其作为配置选项。

例如对于 libmosquitto,您将以秒为单位的保持活动值传递给 mosquitto_connect 函数 (https://mosquitto.org/man/libmosquitto-3.html#idm46181896216640)

int mosquitto_connect(  mosq,    
    host,    
    port,    
    keepalive);      
struct mosquitto *mosq;
const char *host;
int port;

此外,您通常不必发布消息,如果在保持活动期间sent/received没有消息,客户端库应该发送 ping 数据包以保持连接活动。 内部保活;

是的,60 秒是客户端的默认保活时间。但是在mosquitto.conf中确实存在一个keepalive_interval,它是Mosquitto桥接模式,用于将多个mosquitto broker连接在一起。