Apache Camel PAHO MQTT 组件在断开连接后不接收消息

Apache Camel PAHO MQTT component does not receive messages after disconnecting

我在这里看到了同样的问题,但不明白如何根据回复解决这个问题。

是否可以在 paho 端点接收离线消息?如果可以,如何接收?这需要修改源代码吗?

我已验证我使用 mosquitto_sub 从命令行接收离线消息。

这是我的端点配置:

<from uri="paho:JUNK?brokerUrl=tcp://localhost:1883?cleanSession=false&amp;qos=2&amp;clientId=camel_test" />

更多细节。看来camel客户端断开连接时,客户端先取消订阅,这样客户端在重新连接时就无法接收到离线消息了。

Sep 21 06:33:40 me mosquitto.mosquitto[1290]: 1600684420: camel_test JUNK
Sep 21 06:33:40 me mosquitto.mosquitto[1290]: 1600684420: Sending UNSUBACK to camel_test
Sep 21 06:33:40 me mosquitto.mosquitto[1290]: 1600684420: Received DISCONNECT from camel_test
Sep 21 06:33:40 me mosquitto.mosquitto[1290]: 1600684420: Client camel_test disconnected.

mosquitto_sub 命令行客户端不会在断开连接时取消订阅,因此能够在重新连接时接收离线消息。

Sep 21 06:33:21 me mosquitto.mosquitto[1290]: 1600684400: Client ns_consumer disconnected.
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: New client connected from ::1 as ns_consumer (p2, c0, k60).
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Sending CONNACK to ns_consumer (1, 0)
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Sending PUBLISH to ns_consumer (d0, q2, r0, m26, 'JUNK', ... (189 bytes))
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Received SUBSCRIBE from ns_consumer
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: ns_consumer 2 JUNK
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Sending SUBACK to ns_consumer
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Sending PUBLISH to ns_consumer (d0, q2, r1, m27, 'JUNK', ... (189 bytes))
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Received PUBREC from ns_consumer (Mid: 26)
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Sending PUBREL to ns_consumer (m26)
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Received PUBREC from ns_consumer (Mid: 27)
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Sending PUBREL to ns_consumer (m27)
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Received PUBCOMP from ns_consumer (Mid: 26, RC:0)
Sep 21 06:42:23 me mosquitto.mosquitto[1290]: 1600684943: Received PUBCOMP from ns_consumer (Mid: 27, RC:0)

问题是端点配置中的语法不正确,因此 cleanSession 从未通过参数设置并默认为 true。

<from uri="paho:JUNK?brokerUrl=tcp://localhost:1883?cleanSession=false&amp;qos=2&amp;clientId=camel_test" />

应该是

<from uri="paho:JUNK?brokerUrl=tcp://localhost:1883&amp;cleanSession=false&amp;qos=2&amp;clientId=camel_test" />