同一个ip下次重新连接时为何会有取消订阅的操作。是因为端口变更了么

持久会话,第一次连接只有
2023-09-15T15:41:50+08:00 [SUBSCRIBE] test-paho@10.10.7.36:50940 msg: subscribe, sub_id: test-paho, sub_opts: [nl: 0, qos: 2, rap: 0, rh: 0, sub_props: ], topic: test/1
关闭连接后,重新连接会话,并且不订阅会话。
2023-09-15T15:52:48+08:00 [MQTT] test-hive@10.10.7.36:51800 msg: mqtt_packet_received, packet: CONNECT(Q0, R0, D0, ClientId=test-hive, ProtoName=MQTT, ProtoVsn=5, CleanStart=false, KeepAlive=5, Username=undefined, Password=)
2023-09-15T15:52:48+08:00 [SUBSCRIBE] test-hive@10.10.7.36:51800 msg: subscribe, sub_id: test-hive, sub_opts: [nl: 0, qos: 1, rap: 0, rh: 0, sub_props: [Subscription-Identifier: 1], subid: 1], topic: msg
2023-09-15T15:52:48+08:00 [UNSUBSCRIBE] test-hive@10.10.7.36:51049 msg: unsubscribe, sub_opts: [nl: 0, qos: 1, rap: 0, rh: 0, sub_props: [Subscription-Identifier: 1], subid: test-hive], topic: msg

具体的EMQX版本是多少?

你日志里面第一次连接的clientid是test-paho
后面的又是test-hive,他们之间有什么联系么?

贴错了。贴的另外一个日志,但是是一样的,版本是5.0.21

并且我设置了一个连接的rule 和一个断连的rule ,我发现重新连接的时候会发送2个消息,一个是离线的一个是连接的。离线的是旧的端口,连接的是新的端口。5.0.26中也复现了上述问题。

听你的描述,有点神奇。 :innocent:
能分享一下针对clientid的 trace的完整日志么?

2023-09-15T16:48:03.877644+08:00 [SOCKET] test-paho@210.210.0.5:58065 msg: emqx_connection_terminated, reason: {shutdown,kicked}
2023-09-15T16:48:03.878056+08:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 666, peername: 210.210.0.5:58065, clientid: test-paho, reason: {shutdown,kicked}
2023-09-15T16:48:12.978143+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_received, packet: CONNECT(Q0, R0, D0, ClientId=test-paho, ProtoName=MQTT, ProtoVsn=5, CleanStart=false, KeepAlive=20, Username=undefined, Password=)
2023-09-15T16:48:12.978682+08:00 [RULE] test-paho@210.210.0.5:58699 msg: republish_message, flags: [retain: false], pub_props: [User-Property: ], topic: onoffline, payload: {clientId: “test-paho”, val: 1}
2023-09-15T16:48:12.978926+08:00 [PUBLISH] test-paho@210.210.0.5:58699 msg: publish_to, topic: onoffline, payload: {clientId: “test-paho”, val: 1}
2023-09-15T16:48:12.979164+08:00 [debug] msg: insert_channel_info, mfa: emqx_cm:insert_channel_info/3, line: 166, peername: 210.210.0.5:58699, clientid: test-paho
2023-09-15T16:48:12.979339+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_sent, packet: CONNACK(Q0, R0, D0, AckFlags=0, ReasonCode=0)
2023-09-15T16:48:13.027918+08:00 [debug] msg: raw_bin_received, mfa: emqx_connection:when_bytes_in/3, line: 771, peername: 210.210.0.5:58699, clientid: test-paho, bin: 820C0001000006746573742F3102, size: 14, type: hex
2023-09-15T16:48:13.028290+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_received, packet: SUBSCRIBE(Q1, R0, D0, PacketId=1 TopicFilters=[test/1(#{nl => 0,qos => 2,rap => 0,rh => 0})])
2023-09-15T16:48:13.028569+08:00 [info] msg: authorization_permission_allowed, mfa: emqx_authz:log_allowed/1, line: 380, peername: 210.210.0.5:58699, clientid: test-paho, topic: test/1, ipaddr: {210,210,0,5}, source: file, username: undefined
2023-09-15T16:48:13.028961+08:00 [SUBSCRIBE] test-paho@210.210.0.5:58699 msg: subscribe, sub_id: test-paho, sub_opts: [nl: 0, qos: 2, rap: 0, rh: 0, sub_props: ], topic: test/1
2023-09-15T16:48:13.029259+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_sent, packet: SUBACK(Q0, R0, D0, PacketId=1, ReasonCodes=[2])
2023-09-15T16:48:13.029520+08:00 [debug] msg: insert_channel_info, mfa: emqx_cm:insert_channel_info/3, line: 166, peername: 210.210.0.5:58699, clientid: test-paho
2023-09-15T16:48:33.029548+08:00 [debug] msg: raw_bin_received, mfa: emqx_connection:when_bytes_in/3, line: 771, peername: 210.210.0.5:58699, clientid: test-paho, bin: C000, size: 2, type: hex
2023-09-15T16:48:33.029941+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_received, packet: PINGREQ(Q0, R0, D0)
2023-09-15T16:48:33.030120+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_sent, packet: PINGRESP(Q0, R0, D0)
2023-09-15T16:48:53.018679+08:00 [debug] msg: raw_bin_received, mfa: emqx_connection:when_bytes_in/3, line: 771, peername: 210.210.0.5:58699, clientid: test-paho, bin: C000, size: 2, type: hex
2023-09-15T16:48:53.019036+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_received, packet: PINGREQ(Q0, R0, D0)
2023-09-15T16:48:53.019195+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_sent, packet: PINGRESP(Q0, R0, D0)
2023-09-15T16:49:13.028827+08:00 [debug] msg: raw_bin_received, mfa: emqx_connection:when_bytes_in/3, line: 771, peername: 210.210.0.5:58699, clientid: test-paho, bin: C000, size: 2, type: hex
2023-09-15T16:49:13.029215+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_received, packet: PINGREQ(Q0, R0, D0)
2023-09-15T16:49:13.029377+08:00 [MQTT] test-paho@210.210.0.5:58699 msg: mqtt_packet_sent, packet: PINGRESP(Q0, R0, D0)
2023-09-15T16:49:16.838327+08:00 [RULE] test-paho@210.210.0.5:58699 msg: republish_message, flags: [retain: false], pub_props: [User-Property: ], topic: onoffline, payload: {clientId: “test-paho”, val: 0}
2023-09-15T16:49:16.838653+08:00 [PUBLISH] test-paho@210.210.0.5:58699 msg: publish_to, topic: onoffline, payload: {clientId: “test-paho”, val: 0}
------上面是第一次连接并且停止连接----------
2023-09-15T16:51:28.645606+08:00 [MQTT] test-paho@210.210.0.5:59171 msg: mqtt_packet_received, packet: CONNECT(Q0, R0, D0, ClientId=test-paho, ProtoName=MQTT, ProtoVsn=5, CleanStart=false, KeepAlive=20, Username=undefined, Password=)
2023-09-15T16:51:28.646030+08:00 [SUBSCRIBE] test-paho@210.210.0.5:59171 msg: subscribe, sub_id: test-paho, sub_opts: [nl: 0, qos: 2, rap: 0, rh: 0, sub_props: ], topic: test/1
2023-09-15T16:51:28.646344+08:00 [UNSUBSCRIBE] test-paho@210.210.0.5:58699 msg: unsubscribe, sub_opts: [nl: 0, qos: 2, rap: 0, rh: 0, sub_props: , subid: test-paho], topic: test/1
2023-09-15T16:51:28.646575+08:00 [debug] msg: emqx_channel_takeover_end, mfa: emqx_channel:handle_call/2, line: 1204, peername: 210.210.0.5:58699, clientid: test-paho
2023-09-15T16:51:28.646880+08:00 [RULE] test-paho@210.210.0.5:58699 msg: republish_message, flags: [retain: false], pub_props: [User-Property: ], topic: onoffline, payload: {clientId: “test-paho”, val: 0}
2023-09-15T16:51:28.647091+08:00 [PUBLISH] test-paho@210.210.0.5:58699 msg: publish_to, topic: onoffline, payload: {clientId: “test-paho”, val: 0}
2023-09-15T16:51:28.647302+08:00 [SOCKET] test-paho@210.210.0.5:58699 msg: emqx_connection_terminated, reason: {shutdown,takenover}
2023-09-15T16:51:28.647634+08:00 [RULE] test-paho@210.210.0.5:59171 msg: republish_message, flags: [retain: false], pub_props: [User-Property: ], topic: onoffline, payload: {clientId: “test-paho”, val: 1}
2023-09-15T16:51:28.647837+08:00 [PUBLISH] test-paho@210.210.0.5:59171 msg: publish_to, topic: onoffline, payload: {clientId: “test-paho”, val: 1}
2023-09-15T16:51:28.647762+08:00 [info] msg: terminate, mfa: emqx_connection:terminate/2, line: 666, peername: 210.210.0.5:58699, clientid: test-paho, reason: {shutdown,takenover}
2023-09-15T16:51:28.648093+08:00 [debug] msg: insert_channel_info, mfa: emqx_cm:insert_channel_info/3, line: 166, peername: 210.210.0.5:59171, clientid: test-paho
2023-09-15T16:51:28.648276+08:00 [MQTT] test-paho@210.210.0.5:59171 msg: mqtt_packet_sent, packet: CONNACK(Q0, R0, D0, AckFlags=1, ReasonCode=0)

看到完整的日志,这行为应该是对的,
发生了takenover,新的mqtt连接接管以前的旧的mqtt连接后,旧连接会把状态传给新的,同时把自己订阅的topic都退订(此unsubscribe不影响新连接上的主题),然后自己再退出。

好的,多谢,像这种重连的情况会不会影响订阅消息的送达。