1
votes

I'm currently working with Apache Camel and its MQTT component. I have a route consuming messages from the broker (Apache ActiveMQ artemis) and one other sending messages to it. The problem is that there are no exception thrown when the message broker is not available. Moreover all the messages that are not sent are kept in memory waiting for an eventual restart of the server, causing memory overflows. I don't know if this related to the MQTT protocol itself or to the configuration of the endpoint.

Here is my configuration :

    MQTTEndpoint mqttEndpoint = null;

    mqttEndpoint = (MQTTEndpoint) mqttComponent.createEndpoint(MQTT_BROKER);

    mqttEndpoint.getConfiguration().setHost(properties.getBrokerAddress());     
    mqttEndpoint.getConfiguration().setPublishTopicName(publishTopicName);
    //mqttEndpoint.getConfiguration().setSubscribeTopicNames(subscribreTopicNames);
    mqttEndpoint.getConfiguration().setUserName(properties.getBrokerUsername());
    mqttEndpoint.getConfiguration().setPassword(properties.getBrokerPassword());
    mqttEndpoint.getConfiguration().setSslContext(createSSLContext());
    mqttEndpoint.getConfiguration().setByDefaultRetain(false);
    mqttEndpoint.getConfiguration().setQualityOfService(QoS.AT_MOST_ONCE.toString());
    mqttEndpoint.getConfiguration().setConnectAttemptsMax(1);
    mqttEndpoint.getConfiguration().setConnectWaitInSeconds(5);
    mqttEndpoint.getConfiguration().setReconnectBackOffMultiplier(1);
    mqttEndpoint.getConfiguration().setDisconnectWaitInSeconds(3);      
    mqttEndpoint.setCamelContext(camelCtx);
1
What version of Camel and Artemis are you using?Claus Ibsen
I'm using Camel version 2.21.0Grégoire B
And Artemis 2.6.0Grégoire B

1 Answers

0
votes

So this is correct behaviour for the QOS level you have set. You are setting the QOS flag to QoS.AT_MOST_ONCE.toString(). This is known as QOS level 2.

A Small Summary Of QOS 2 – Only Once

This level guarantees that the message will be delivered only once. If there is networking issues and it cannot deliver it the message will stay in the client queue till delivery is possible. This is the slowest QOS level as it requires 4 messages.

  1. The sender sends a message and waits for an acknowledgement (PUBREC)

  2. The receiver sends a PUBREC message

  3. If the sender doesn’t receive an acknowledgement ( PUBREC) it will resend the message with the DUP flag set.

  4. When the sender receives an acknowledgement message PUBREC it then sends a message release message (PUBREL).
  5. If the sender doesn’t receive the PUBREL it will resend the PUBREC message
  6. When the receiver receives the PUBREL message it can now forward the message onto any subscribers.
  7. The receiver then send a publish complete (PUBCOMP) .
  8. If the sender doesn’t receive the PUBCOMP message it will resend the PUBREL message.
  9. When the sender receives the PUBCOMP the process is complete and it can delete the message from the outbound queue.

See this blog entry for more informaton.

Most important part is that in your case the receiver is not available thus the MQTT protocol for QOS 2 cannot complete.