Skip to content

How to count messages consumption for retained messages in persistent sessions during subsequent client reconnections to persistent sessions.

0

Scenario: A client has a persistent session to IoT core MQTT Broker with subscriptions to a retained topic and the retained topic has a valid retained message.

Question:

  • From AWS documentation it is clear that each delivery of retained message to persistent session is counted as one message and delivery of the retained message from persistent session to client gets counted as another message, in total 2 messages.
  • Is it the case only when persistent session is created or each time client reconnects to persistent session? e.g. When the persistent session is created sending retained message results in 2 messages consumption, and client got disconnected & reconnected before persistent session expires, in this case does total message consumption becomes 1 message or 2 messages?

/Srinivas

asked a year ago139 views

1 Answer
0

Let me clarify how message counting works with retained messages in AWS IoT Core when using persistent sessions:

  1. Initial Persistent Session Creation:
  • When a persistent session is first created: 2 messages are counted
    • 1 message for delivering retained message to persistent session
    • 1 message for delivering from persistent session to client
  1. Client Reconnection Scenario:
  • When client reconnects to an existing persistent session: 1 message is counted
    • Only the delivery from persistent session to client is counted
    • No new delivery to persistent session is needed since it already has the retained message

The key points are:

  • The double counting (2 messages) only happens during initial persistent session creation
  • Subsequent reconnections within the persistent session validity period only count as 1 message
  • This is because the persistent session maintains the retained message state between reconnections

So in your example:

  1. First connection: 2 messages counted
  2. Disconnect and reconnect: 1 additional message counted Total: 3 messages

This behavior helps optimize message counts while still maintaining the reliability guarantees of persistent sessions.

AWS

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.