Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Subscription identifier #801

Closed
4 tasks done
andsel opened this issue Dec 24, 2023 · 0 comments
Closed
4 tasks done

Implement Subscription identifier #801

andsel opened this issue Dec 24, 2023 · 0 comments
Assignees
Labels

Comments

@andsel
Copy link
Collaborator

andsel commented Dec 24, 2023

General description

A client (subscriber) can tag his subscription topics so that when it receives a PUBLISH he can know which subscriptions were matched by the triggering publish.

MQTT 5 specification (relevant to server implementation)

Publish properties 3.3.2.3.8

  • The Subscription Identifier can have the value of 1 to 268,435,455.
  • ⚠️ It is a Protocol Error if the Subscription Identifier has a value of 0.
  • Multiple Subscription Identifiers will be included if the publication is the result of a match to more than one subscription, in this case their order is not significant.

Publish action 3.3.4

  • The PUBLISH packet includes the Subscription Identifier carried in the SUBSCRIBE packet, if there was one.
  • 📓 If the Client specified a Subscription Identifier for any of the overlapping subscriptions the Server MUST send those Subscription Identifiers in the message which is published as the result of the subscriptions [MQTT-3.3.4-3].
  • 📓 If the Server sends a single copy of the message it MUST include in the PUBLISH packet the Subscription Identifiers for all matching subscriptions which have a Subscription Identifiers, their order is not significant [MQTT-3.3.4-4].
  • 📓 If the Server sends multiple PUBLISH packets it MUST send, in each of them, the Subscription Identifier of the matching subscription if it has a Subscription Identifier [MQTT-3.3.4-5].
  • It is possible that the Client made several subscriptions which match a publication and that it used the same identifier for more than one of them. In this case the PUBLISH packet will carry multiple identical Subscription Identifiers.
  • ✋ If the subscription was shared, then only the Subscription Identifiers that were present in the SUBSCRIBE packet from the Client which is receiving the message are returned in the PUBLISH packet.

Subscribe properties 3.8.2.1.2

  • The Subscription Identifier can have the value of 1 to 268,435,455.
  • ⚠️ It is a Protocol Error if the Subscription Identifier has a value of 0.
  • ⚠️ It is a Protocol Error to include the Subscription Identifier more than once.
  • The Subscription Identifier is associated with any subscription created or modified as the result of this SUBSCRIBE packet.
  • If there is a Subscription Identifier, it is stored with the subscription. If this property is not specified, then the absence of a Subscription Identifier is stored with the subscription.

Subscribe action 3.8.4

  • The Subscription Identifiers are part of the Session State in the Server and are returned to the Client receiving a matching PUBLISH packet. They are removed from the Server’s Session State when the Server receives an UNSUBSCRIBE packet, when the Server receives a SUBSCRIBE packet from the Client for the same Topic Filter but with a different Subscription Identifier or with no Subscription Identifier, or when the Server sends Session Present 0 in a CONNACK packet.
  • The Server need not use the same set of Subscription Identifiers in the retransmitted PUBLISH packet. The Client can remake a Subscription by sending a SUBSCRIBE packet containing a Topic Filter that is identical to the Topic Filter of an existing Subscription in the current Session. If the Client remade a subscription after the initial transmission of a PUBLISH packet and used a different Subscription Identifier, then the Server is allowed to use the identifiers from the first transmission in any retransmission. Alternatively, the Server is allowed to use the new identifiers during a retransmission. The Server is not allowed to revert to the old identifier after it has sent a PUBLISH packet containing the new one.

Task list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant