MQTT 5 Subscription Identifiers let a subscriber connect an incoming PUBLISH to the subscriptions that caused the delivery. They are especially useful in robot gateways that use overlapping wildcard filters, because a single telemetry message can legitimately match more than one subscription.

The important consequence is that Subscription Identifier is a repeatable property on a server-to-client PUBLISH. One delivered packet can contain several identifiers, and the order of those values has no defined meaning. Client code that reads only the first identifier can silently skip callbacks, accounting rules, or diagnostic paths associated with other matching subscriptions.

The identifier is attached by SUBSCRIBE

A client may include one Subscription Identifier property in a SUBSCRIBE packet. The valid range is 1 through 268,435,455; zero is a Protocol Error. The identifier is associated with every subscription created or modified by that SUBSCRIBE packet and is stored with those subscriptions by the server.

That means one SUBSCRIBE containing several Topic Filters assigns the same identifier to all of them. A client that needs a distinct identifier for each filter should send separate SUBSCRIBE packets or deliberately design a many-to-one mapping in its local dispatcher.

If a later SUBSCRIBE modifies an existing filter with a new identifier, the server stores the new association. Omitting the property stores the absence of an identifier for the affected subscription. The number is client-selected metadata, not a broker-generated globally unique subscription handle.

Overlapping filters create multiple matches

Imagine a robot publishes to factory/line4/robot12/temperature. The same client has subscription 41 for factory/+/+/temperature and subscription 77 for factory/line4/#. Both filters match the publication.

The MQTT 5 specification allows the server to deliver one PUBLISH that represents all matching subscriptions. If it does, that packet must carry every Subscription Identifier associated with the matching subscriptions. In this example, the PUBLISH contains identifiers 41 and 77. Their order is not significant.

A server may instead send additional copies, one for each matching subscription. In that mode, each PUBLISH carries the identifier for the subscription that caused that copy. Applications must therefore tolerate either one packet with several identifiers or multiple packets with their respective identifiers, while also considering the selected QoS behavior.

Several subscriptions can even use the same identifier. If all of them match and the server sends one combined PUBLISH, the packet can contain repeated identical Subscription Identifier properties. Treating the list as a set would lose evidence about the number of matching subscriptions, although many callback designs intentionally collapse identical values.

The value is routing evidence, not message identity

A Subscription Identifier says why the server delivered a message to this client. It does not identify the publication itself, establish end-to-end uniqueness, or prove that a physical event occurred once. Packet Identifier, QoS state, application event IDs, and robot command idempotency solve different problems.

The property also flows only from server to client in a PUBLISH caused by subscriptions. A client-to-server PUBLISH must not contain a Subscription Identifier. A server must not invent an identifier that was not received in the SUBSCRIBE packets responsible for the delivery.

For shared subscriptions, the returned identifiers come from the SUBSCRIBE packet of the client that actually receives the message. They should not be interpreted as a list of every group member that could have received it.

Build a multi-value dispatcher

Parse Subscription Identifier as an ordered packet field that can occur repeatedly, then expose it to application logic as a collection. Do not assign semantics to property order. Validate that every value is nonzero and within the Variable Byte Integer range.

Maintain a local map from identifier to one or more handlers or original Topic Filters. When a PUBLISH arrives, resolve all identifiers before dispatch. If two identifiers point to different processing paths, run both only when the application contract permits it. For robot control, avoid letting overlapping subscriptions trigger the same physical command twice; route commands through an application-level operation ID and idempotency check.

Handle a PUBLISH with no Subscription Identifier as a valid possibility. It may have matched a subscription created without one, or it may be an unsolicited message allowed by the deployment's broker features. Local policy can reject unexpected traffic, but absence alone is not proof of protocol corruption.

Session changes affect the client's map

The server stores Subscription Identifiers with subscriptions in server Session State. The specification notes that the client's local identifier-to-handler association is not itself MQTT Session State. Client software must persist or reconstruct its own map consistently.

When CONNACK reports Session Present 0, remove assumptions tied to the old subscriptions and subscribe again. When Session Present 1, the server may still hold the subscriptions, so the client needs compatible local callback state. If an application restarts without that state, it can receive identifiers it no longer understands even though the broker is acting correctly.

Retransmission adds another edge case. If a client remakes a subscription with a new identifier after a PUBLISH was first sent, a retransmitted packet may use the old or new identifiers under the specification's transition rules. The server cannot revert to an old identifier after it has sent a PUBLISH using the new one. Diagnostics should record packet DUP state and the full identifier list.

Test overlaps deliberately

Create two overlapping filters with identifiers 41 and 77, publish one matching robot telemetry message, and accept either one delivery containing both values or separate deliveries containing the relevant value. Verify that property order does not change behavior. Then assign the same identifier to both subscriptions and confirm the parser retains duplicate occurrences.

Resubscribe one filter without an identifier, reconnect with both Session Present outcomes, and exercise a QoS retransmission during an identifier change. Confirm that command handlers use an application operation key rather than assuming one Subscription Identifier means one physical action.

Subscription Identifiers make MQTT routing observable, but they describe subscription matches rather than unique messages. Preserve the complete multi-value list, keep local handler state aligned with Session recovery, and separate delivery routing from robot action deduplication.