Code Monkey home page Code Monkey logo

Comments (6)

zmstone avatar zmstone commented on July 24, 2024 1

所以在飞窗里的消息还会重发吗

当前版本 EMQX,飞行窗口中的消息会重发,但是只有在客户端在线的情况下。
飞行窗口中重发消息的行为是违反协议的,在 5.8 中会修复:#13080

from emqx.

zmstone avatar zmstone commented on July 24, 2024

你好。
如果从 EMQX 的控制台上看到消息已经发送到飞行窗口了。那么应该需要调查客户端为什么没有收到消息或者更大的可能是已经收到了但是没有处理。

如果客户端连上了还没订阅就收到消息,那么可能是 clean-start=false。
这种情况客户端是不需要重新订阅的,因为订阅都存在会话状态中了。

from emqx.

LvChenhui avatar LvChenhui commented on July 24, 2024

你好。 如果从 EMQX 的控制台上看到消息已经发送到飞行窗口了。那么应该需要调查客户端为什么没有收到消息或者更大的可能是已经收到了但是没有处理。

如果客户端连上了还没订阅就收到消息,那么可能是 clean-start=false。 这种情况客户端是不需要重新订阅的,因为订阅都存在会话状态中了。

感谢您的恢复。
是的,我们设置的clean-start=false,会保持会话。所以会造成"客户端连上了还没订阅就收到消息",但是此时我们的listener还没有注册上来。
代码逻辑如下,client在连接的时候,延迟注册listener

public static void main(String[] args) throws Exception {
    MqttSubscribe subscribe = new MqttSubscribe();
    subscribe.connect("emqx_test_subscribe_10");

    new Thread(() -> {
        try {
           //延迟 20s
            Thread.sleep(10 * 1000);
            // 订阅
            MqttSubscription mqttSubscription = new MqttSubscription("testtopic10/10/#", 1);
            System.out.println(simpleDateFormat.format(System.currentTimeMillis()) + "subscribe");
            subscribe.client.subscribe(new MqttSubscription[]{mqttSubscription}, new IMqttMessageListener[]{new DefaultIMqttMessageListener()});
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }).start();
}

void connect(String clientId) throws Exception {
    MemoryPersistence persistence = new MemoryPersistence();

    String broker = "xxxxx";
    client = new MqttClient(broker, clientId, persistence);
    // MQTT 连接选项
    MqttConnectionOptions connOpts = new MqttConnectionOptions();
    connOpts.setUserName("test");
    connOpts.setPassword("test".getBytes());
    // 保留会话
    connOpts.setCleanStart(false);
    connOpts.setSessionExpiryInterval(7200L);
    //自动重连
    connOpts.setAutomaticReconnect(true);

    // 建立连接
    System.out.println("Connecting to broker: " + broker);
    client.connect(connOpts);
}

from emqx.

LvChenhui avatar LvChenhui commented on July 24, 2024

所以在飞窗里的消息还会重发吗

from emqx.

zmstone avatar zmstone commented on July 24, 2024

但是此时我们的listener还没有注册上来

我不太理解什么是你们 listener。

  • 如果客户端首次连接然后订阅, 那么这是一个 “新建一个订阅” 的请求
  • 如果客户端重练,老的session还在EMQX里,那么连上之后就会立刻收到离线期间累积的消息。然后 20s 之后发送的那个订阅请求相当于是“修改原来的订阅的意思“。

from emqx.

github-actions avatar github-actions commented on July 24, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from emqx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.