What is an Mqtt 'session'?

0

In creating an Mqtt client connection using the class AwsIotMqttConnectionBuilder, I encounter a configuration setting called "withCleanSession(boolean)" that is described in the documentation this way:

/**
 * 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;
}

What is the meaning of "session" in this context? Is a session something that is local to one computer, or is it a state stored on the network somewhere? Is the client ID of the connection related to its state?

Frank
질문됨 2년 전529회 조회
1개 답변
0
수락된 답변

Please see here: 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.

And: 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.

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

Is the client ID of the connection related to its state?

Yes, the Client ID is used to identify which session to resume.

profile pictureAWS
전문가
Greg_B
답변함 2년 전
  • Thanks for the response. I think the source of my problem was that I had created multiple clients with the same Client ID and that was causing issues. Once I gave each client a unique ID things worked as expected.

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

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

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

관련 콘텐츠