我已经建立了一个用于MQTT通信的Mosquitto代理,但我甚至无法让它开箱即用。连接并等待一点后,服务器重置客户端连接并显示'Socket error on client .. , disconnecting.'
我几乎排除了客户端的错误,因为使用两个不同的(MQTT.fx和mqtt-spy)客户端软件时错误仍然存在。
Connection-timeout: 30
Keep-alive interval: 30
Mosquitto运行在最新版本(mosquitto版本1.4.2)和库存配置。
我执行以下操作:
编辑:
贯穿代码
static void loop_handle_reads_writes(struct mosquitto_db *db, struct pollfd *pollfds)
{
[...]
if(pollfds[context->pollfd_index].revents & POLLIN){
if(_mosquitto_packet_read(db, context)){
do_disconnect(db, context); <-- Line that causes disconnection
continue;
}
}
}
[...]
void do_disconnect(struct mosquitto_db *db, struct mosquitto *context)
{
char *id;
if(context->state == mosq_cs_disconnected){
return;
}
[...]
{
if(db->config->connection_messages == true){
if(context->id){
id = context->id;
}else{
id = "<unknown>";
}
if(context->state != mosq_cs_disconnecting){
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Socket error on client %s, disconnecting.", id);
}else{
_mosquitto_log_printf(NULL, MOSQ_LOG_NOTICE, "Client %s disconnected.", id);
}
}
mqtt3_context_disconnect(db, context);
[...]
if(context->clean_session){
mosquitto__add_context_to_disused(db, context);
if(context->id){
HASH_DELETE(hh_id, db->contexts_by_id, context);
_mosquitto_free(context->id);
context->id = NULL;
}
}
context->state = mosq_cs_disconnected;
}
}
控制台日志:
1433171947: New connection from 192.168.2.5 on port 1883.
1433171947: New client connected from 192.168.2.5 as testuser (c1, k30, u'testuser').
1433171947: Sending CONNACK to testuser (0, 0)
1433171954: Received PUBLISH from testuser (d0, q1, r1, m1, 'test', ... (4 bytes))
1433171954: Sending PUBACK to testuser (Mid: 1)
1433171984: Received PINGREQ from testuser
1433171984: Sending PINGRESP to testuser
1433172003: Socket error on client testuser, disconnecting.
以下是交换的13帧的一些数据包捕获以及导致套接字错误的连接重置。
服务器(192.168.2.15)捕获脚本:
No. Time Source Destination Protocol Length Info
129 14.587072000 192.168.2.5 192.168.2.15 TCP 62 55176 > ibm-mqisdp [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1
Frame 129: 62 bytes on wire (496 bits), 62 bytes captured (496 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 0, Len: 0
No. Time Source Destination Protocol Length Info
131 14.587250000 192.168.2.5 192.168.2.15 TCP 60 55176 > ibm-mqisdp [ACK] Seq=1 Ack=1 Win=17424 Len=0
Frame 131: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 1, Ack: 1, Len: 0
No. Time Source Destination Protocol Length Info
132 14.589586000 192.168.2.5 192.168.2.15 TCP 92 55176 > ibm-mqisdp [PSH, ACK] Seq=1 Ack=1 Win=17424 Len=38
Frame 132: 92 bytes on wire (736 bits), 92 bytes captured (736 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 1, Ack: 1, Len: 38
Data (38 bytes)
0000 10 24 00 04 4d 51 54 54 04 c2 00 1e 00 08 74 65 .$..MQTT......te
0010 73 74 75 73 65 72 00 08 74 65 73 74 75 73 65 72 stuser..testuser
0020 00 04 6d 61 72 79 ..mary
No. Time Source Destination Protocol Length Info
135 14.590183000 192.168.2.5 192.168.2.15 TCP 60 55176 > ibm-mqisdp [ACK] Seq=39 Ack=5 Win=17420 Len=0
Frame 135: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 39, Ack: 5, Len: 0
No. Time Source Destination Protocol Length Info
144 21.534467000 192.168.2.5 192.168.2.15 TCP 68 55176 > ibm-mqisdp [PSH, ACK] Seq=39 Ack=5 Win=17420 Len=14
Frame 144: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 39, Ack: 5, Len: 14
Data (14 bytes)
0000 33 0c 00 04 74 65 73 74 00 01 74 65 73 74 3...test..test
No. Time Source Destination Protocol Length Info
146 21.534941000 192.168.2.5 192.168.2.15 TCP 60 55176 > ibm-mqisdp [ACK] Seq=53 Ack=9 Win=17416 Len=0
Frame 146: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 53, Ack: 9, Len: 0
No. Time Source Destination Protocol Length Info
184 51.556401000 192.168.2.5 192.168.2.15 TCP 60 55176 > ibm-mqisdp [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 184: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
187 51.850874000 192.168.2.5 192.168.2.15 TCP 60 [TCP Retransmission] 55176 > ibm-mqisdp [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 187: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
190 52.452535000 192.168.2.5 192.168.2.15 TCP 60 [TCP Retransmission] 55176 > ibm-mqisdp [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 190: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
197 53.655674000 192.168.2.5 192.168.2.15 TCP 60 [TCP Retransmission] 55176 > ibm-mqisdp [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 197: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
201 56.056945000 192.168.2.5 192.168.2.15 TCP 60 [TCP Retransmission] 55176 > ibm-mqisdp [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 201: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
213 60.854141000 192.168.2.5 192.168.2.15 TCP 60 [TCP Retransmission] 55176 > ibm-mqisdp [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 213: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
233 70.449632000 192.168.2.5 192.168.2.15 TCP 60 55176 > ibm-mqisdp [RST, ACK] Seq=55 Ack=9 Win=0 Len=0
Frame 233: 60 bytes on wire (480 bits), 60 bytes captured (480 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: ibm-mqisdp (1883), Seq: 55, Ack: 9, Len: 0
客户端(192.168.2.5)捕获脚本:
No. Time Source Destination Protocol Length Info
174 5.754193000 192.168.2.5 192.168.2.15 TCP 62 55176→1883 [SYN] Seq=0 Win=8192 Len=0 MSS=1460 SACK_PERM=1
Frame 174: 62 bytes on wire (496 bits), 62 bytes captured (496 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 0, Len: 0
No. Time Source Destination Protocol Length Info
176 5.754376000 192.168.2.5 192.168.2.15 TCP 54 55176→1883 [ACK] Seq=1 Ack=1 Win=17424 Len=0
Frame 176: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 1, Ack: 1, Len: 0
No. Time Source Destination Protocol Length Info
177 5.756658000 192.168.2.5 192.168.2.15 TCP 92 55176→1883 [PSH, ACK] Seq=1 Ack=1 Win=17424 Len=38
Frame 177: 92 bytes on wire (736 bits), 92 bytes captured (736 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 1, Ack: 1, Len: 38
Data (38 bytes)
0000 10 24 00 04 4d 51 54 54 04 c2 00 1e 00 08 74 65 .$..MQTT......te
0010 73 74 75 73 65 72 00 08 74 65 73 74 75 73 65 72 stuser..testuser
0020 00 04 6d 61 72 79 ..mary
No. Time Source Destination Protocol Length Info
180 5.757101000 192.168.2.5 192.168.2.15 TCP 54 55176→1883 [ACK] Seq=39 Ack=5 Win=17420 Len=0
Frame 180: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 39, Ack: 5, Len: 0
No. Time Source Destination Protocol Length Info
393 12.701517000 192.168.2.5 192.168.2.15 TCP 68 55176→1883 [PSH, ACK] Seq=39 Ack=5 Win=17420 Len=14
Frame 393: 68 bytes on wire (544 bits), 68 bytes captured (544 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 39, Ack: 5, Len: 14
Data (14 bytes)
0000 33 0c 00 04 74 65 73 74 00 01 74 65 73 74 3...test..test
No. Time Source Destination Protocol Length Info
395 12.701938000 192.168.2.5 192.168.2.15 TCP 54 55176→1883 [ACK] Seq=53 Ack=9 Win=17416 Len=0
Frame 395: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 53, Ack: 9, Len: 0
No. Time Source Destination Protocol Length Info
1192 42.723471000 192.168.2.5 192.168.2.15 TCP 56 55176→1883 [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 1192: 56 bytes on wire (448 bits), 56 bytes captured (448 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
1205 43.017917000 192.168.2.5 192.168.2.15 TCP 56 [TCP Retransmission] 55176→1883 [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 1205: 56 bytes on wire (448 bits), 56 bytes captured (448 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
1213 43.619506000 192.168.2.5 192.168.2.15 TCP 56 [TCP Retransmission] 55176→1883 [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 1213: 56 bytes on wire (448 bits), 56 bytes captured (448 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
1236 44.822621000 192.168.2.5 192.168.2.15 TCP 56 [TCP Retransmission] 55176→1883 [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 1236: 56 bytes on wire (448 bits), 56 bytes captured (448 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
1273 47.224018000 192.168.2.5 192.168.2.15 TCP 56 [TCP Retransmission] 55176→1883 [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 1273: 56 bytes on wire (448 bits), 56 bytes captured (448 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
1462 52.021241000 192.168.2.5 192.168.2.15 TCP 56 [TCP Retransmission] 55176→1883 [PSH, ACK] Seq=53 Ack=9 Win=17416 Len=2
Frame 1462: 56 bytes on wire (448 bits), 56 bytes captured (448 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 53, Ack: 9, Len: 2
Data (2 bytes)
0000 c0 00 ..
No. Time Source Destination Protocol Length Info
1713 61.616726000 192.168.2.5 192.168.2.15 TCP 54 55176→1883 [RST, ACK] Seq=55 Ack=9 Win=0 Len=0
Frame 1713: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
Ethernet II, Src: Cisco-Li_21:62:a7 (00:1e:e5:21:62:a7), Dst: NX_6a:d6:31 (00:0c:29:6a:d6:31)
Internet Protocol Version 4, Src: 192.168.2.5 (192.168.2.5), Dst: 192.168.2.15 (192.168.2.15)
Transmission Control Protocol, Src Port: 55176 (55176), Dst Port: 1883 (1883), Seq: 55, Ack: 9, Len: 0
_mosquitto_packet_read()
失败的最可能原因是远程端关闭了连接,因此无法读取。如果do_disconnect()
到达你提到的那个点,那么从代理的角度来看,套接字基本上是开放的。
我刚刚尝试使用下面的客户端代码重现此问题(您将需要安装Paho Python,pip install paho-mqtt
)。
import paho.mqtt.client as paho
mqtt = paho.Client(client_id="testuser", clean_session=True)
mqtt.username_pw_set("testuser", "password")
mqtt.connect("localhost", 1883, 30)
mqtt.publish("test", "test", qos=1, retain=True)
mqtt.loop_forever()
我从经纪人那里得到的日志是:
1433245884: New connection from ::1 on port 1883.
1433245884: New client connected from ::1 as testuser (c1, k30, u'testuser').
1433245884: Sending CONNACK to testuser (0, 0)
1433245884: Received PUBLISH from testuser (d0, q1, r1, m1, 'test', ... (4 bytes))
1433245884: Sending PUBACK to testuser (Mid: 1)
1433245915: Received PINGREQ from testuser
1433245915: Sending PINGRESP to testuser
1433245945: Received PINGREQ from testuser
1433245945: Sending PINGRESP to testuser
1433245975: Received PINGREQ from testuser
1433245975: Sending PINGRESP to testuser
...
你可以在你的系统上试试这个吗?
当从mosquitto到EMQ代理进行桥接配置时,我们遇到了这个错误。我们有两座桥梁,其中一座位于QoS 0
并且曾经运作良好。 QoS 2
上有一个问题。以下是可以帮助您的观察和步骤:
这是通过在mosquitto配置中设置log_type all
属性。根据您的Linux发行版查找/var/log/mosquitto/mosquitto.log
或'/ var / log / messages`上的错误。
Mosquitto排队的消息需要发布到EMQ,而EMQ也有消息要发布到mosquitto。一旦建立了连接,经纪人就忙着发送数据包,蚊子常常错过PINGREQ
在配置的时间发送的keepalive_interval
。
在使用命令sudo emqttd_ctl listeners
检查客户端终止的EMQ原因时,可能会发现超时是问题所在。因此,我们用mqtt.client.idle_timeout
增加了EMQ的超时。
该问题已于当天重新确定,并在第二天重新发布。在检查EMQ上的日志时,超时是终止的原因,并且在指定时间内没有从mosquitto发送PINGREQ
s。我们怀疑带宽并在一段时间内推送了许多大小合适的消息,这被视为终止的原因。我们决定将mosquitto和EMQ设置为通过将机上消息计数设置为1
一次发送一条消息。这使连接稳定并传递了消息。
建议在EMQ上增加mosquitto和retry_interval
上的mqtt.session.retry_interval
,以防你在QoS 1或2上发送大量的消息。此外,在这种情况下,EMQ上的mqtt.session.await_rel_timeout
是一个重要的配置。 mqtt.client.max_publish_rate
是另一个值得关注的人。