【问题标题】:Apache Camel MQTT - No exception thrown when the message broker is downApache Camel MQTT - 消息代理关闭时不会引发异常
【发布时间】:2019-02-10 06:43:46
【问题描述】:

我目前正在使用 Apache Camel 及其 MQTT 组件。我有一条使用来自代理(Apache ActiveMQ artemis)的消息的路由和另一个向它发送消息的路由。问题是当消息代理不可用时没有抛出异常。此外,所有未发送的消息都保存在内存中,等待服务器最终重新启动,从而导致内存溢出。不知道是不是和MQTT协议本身有关,还是跟端点的配置有关。

这是我的配置:

    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);

【问题讨论】:

  • 你用的是什么版本的 Camel 和 Artemis?
  • 我使用的是 Camel 版本 2.21.0
  • 还有阿耳忒弥斯 2.6.0

标签: exception-handling apache-camel out-of-memory mqtt except


【解决方案1】:

所以这是您设置的 QOS 级别的正确行为。您将 QOS 标志设置为 QoS.AT_MOST_ONCE.toString()。这称为 QOS 级别 2。

QOS 2 的小总结 - 只有一次

这个级别保证消息只会被传递一次。如果存在网络问题并且无法传递,则消息将保留在客户端队列中,直到可以传递为止。这是最慢的 QOS 级别,因为它需要 4 条消息。

  1. 发件人发送消息并等待确认 (PUBREC)

  2. 接收方发送一条 PUBREC 消息

  3. 如果发件人没有收到确认 (PUBREC),它将重新发送消息 设置了 DUP 标志。

  4. 当发送方收到确认消息 PUBREC 时,它会发送消息释放消息 (PUBREL)。
  5. 如果发件人没有收到 PUBREL,它将重新发送 PUBREC 消息
  6. 当接收者收到 PUBREL 消息时,它现在可以将消息转发给任何订阅者。
  7. 然后接收方发送一个发布完成 (PUBCOMP)。
  8. 如果发件人没有收到 PUBCOMP 消息,它将重新发送 PUBREL 消息。
  9. 当发送者收到 PUBCOMP 时,该过程完成,它可以从出站队列中删除消息。

看到这个blog entry for more informaton

最重要的部分是,在您的情况下,接收器不可用,因此 QOS 2 的 MQTT 协议无法完成。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 2018-07-30
    • 2013-08-18
    • 2019-06-25
    • 1970-01-01
    • 2022-01-17
    相关资源
    最近更新 更多