什么是 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
전문가
질문됨 5달 전44회 조회
1개 답변
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
전문가
답변함 5달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠