Search code examples
apache-camelmqttpahospring-camel

Apache Camel PAHO MQTT component does not receive messages after disconnecting


I saw this same issue here, but don't understand how to fix this issue based on the response.

Camel PAHO routes not receiving offline messages while connecting back

Is receiving offline messages possible at the paho endpoint and if so how? Would this require modifying the source code?

I verified I receive offline messages using mosquitto_sub from the command line.

Here's my endpoint configuration:

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

Some more details. It appears that when disconnecting the camel client, the client is unsubscribing first which is preventing the client from receiving the offline messages when it reconnects.

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.

The mosquitto_sub command line client is not unsubscribing on disconnects and is therefore able to receive the offline messages on reconnect.

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)


Solution

  • Issue was incorrect syntax in the endpoint configuration so cleanSession was never getting set via the paramter and defaulting to true.

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

    should be

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