什么是 Mqtt“会话(Session)”?

0

【以下的问题经过翻译处理】 在使用AwsIotMqttConnectionBuilder类创建Mqtt客户端连接时,我遇到了一个名为“withCleanSession(boolean)”的配置设置,该文档如下所述:

//**
 * Configures whether or not the service should try to resume prior
 * subscriptions, if it has any
 *
 * @param cleanSession true if the session should drop prior subscriptions when
 *                     a connection from this builder is established, false to resume the session
 * @return {@link AwsIotMqttConnectionBuilder}
 */
public AwsIotMqttConnectionBuilder withCleanSession(boolean cleanSession) {
    this.config.setCleanSession(cleanSession);
    return this;
}

这个上下文中“会话(Session)”的意义是什么?会话是局限于一个计算机上还是存储在网络的某个地方的状态?连接的客户端ID与其状态是否相关?

profile picture
EXPERTE
gefragt vor einem Jahr81 Aufrufe
1 Antwort
0

【以下的回答经过翻译处理】 请参见此处:https://docs.aws.amazon.com/iot/latest/developerguide/mqtt.html#mqtt-persistent-sessions

Persistent sessions store a client’s subscriptions and messages, with a quality of service (QoS) of 1, that have not been acknowledged by the client. When a disconnected device reconnects to a persistent session, the session resumes, its subscriptions are reinstated, and subscribed messages received prior to the reconnection and that have not been acknowledged by the client are sent to the client.

同时请参见:https://docs.aws.amazon.com/iot/latest/developerguide/sdk-tutorials.html

The message broker receives messages from devices and publishes messages to devices that have subscribed to them. With persistent sessions —sessions that remain active even when the initiating device is disconnected—devices can retrieve messages that were published while they were disconnected. On the device side, MQTT supports Quality of Service levels (QoS) that ensure the host receives messages sent by the device.

另请参见:https://aws.amazon.com/about-aws/whats-new/2019/01/aws-iot-core-now-enables-customers-to-store-messages-for-disconnected-devices/

客户端ID与其状态有关吗?

是的,客户端ID用于标识要恢复哪个会话。

profile picture
EXPERTE
beantwortet vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen