Skip to content

feat(binding-mqtt-kafka): QoS 2 claim tickets for shared subscriptions - #3114

Merged
jfallows merged 29 commits into
developfrom
feature/mqtt-shared-subscriptions-6-qos2-claim-tickets
Nov 17, 2026
Merged

jfallows merged 29 commits into
developfrom
feature/mqtt-shared-subscriptions-6-qos2-claim-tickets

Conversation

@jfallows

@jfallows jfallows commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds QoS 2 delivery for shared subscriptions in binding-mqtt-kafka using durable claim tickets in the configured store, so a QoS 2 message completes PUBREL and PUBCOMP to the same client across reconnects, including through another node, and is never sent to another subscriber once it has been claimed (MQTT 5.0 4.8.2-4 and 4.8.2-5).

Part of #1801

Claim tickets

  • Before a PUBLISH is delivered, a claim ticket {packetId, state, topic, partition, offset, shareName, filter} is written to the store under <groupIdPrefix>:tickets:<clientId> (a versioned flyweight union, base64url encoded). Writes are coalesced. The record's frames are held until the write is durable, then the record is ACCEPTed and forwarded.
  • PUBREC (success) updates the ticket to PUBREL pending and triggers PUBREL. PUBCOMP, or a PUBREC at 0x80 or above, removes it. If the stream ends while a write is pending, the ticket is abandoned so a record released to another member cannot be redelivered to this client.
  • On reconnect with the subscription restored, PUBREL-pending tickets replay PUBREL, and PUBLISH-sent tickets re-fetch the record by its exact offset and redeliver it with the same packet id and DUP. A record that is gone, expired or at a different offset drops the ticket, and its packet id is reused. Stored tickets that cannot be read refuse the shared subscription.
  • Tickets are deleted at session termination: Clean Start, END with expiry 0, and the expiry signal.
  • Known limitation: tickets whose subscription is not restored at reconnect stay in the store until session termination and are not redelivered.

binding-mqtt

An encoded DUP flag on a redelivered PUBLISH, with spec and IT first.

Engine test store

The type: test store gains an assertions option of expected mutations (put, putIfAbsent, delete, getAndDelete) that ITs use to assert the order and content of the entries a binding writes, and it fails the test at detach when expected operations are missing. The config schema and adapter, spec scenarios and unit tests (TestStoreHandlerTest) are included. TestEntry is public because the public TestStoreHandler constructor takes it, and the ticket unit tests seed and read TestEntry values.

Stack

This is one layer of a stack of PRs for #1801. Each PR contains only the commits since the previous layer; this PR is based on the previous layer's branch.

# PR Layer Base
1 #3109 binding-kafka: share group stream develop
2 #3110 binding-mqtt: shared subscriptions, server and client #3109
3 #3111 binding-mqtt-kafka: shared subscriptions for QoS 0 and 1 #3110
4 #3112 binding-mqtt: SUBACK after application streams begin #3111
5 #3113 binding-mqtt: complete in-flight deliveries when unsubscribing #3112
6 #3114 (this PR) binding-mqtt-kafka: QoS 2 claim tickets (with engine test store assertions) #3113
7 #3115 binding-mqtt-kafka: epoch registry for the lifecycle of a shared subscription #3114
8 #3116 real-broker share stream fixes and mqtt.kafka.proxy example (top of the stack) #3115

Documentation: aklivity/aklivity-docs#181 (merge after the stack).

Test evidence

Run on this branch tip (checkstyle and license checks run in the validate phase of each build):

  • ./mvnw clean install -DskipTests -pl <modules> -am -Dmaven.build.cache.enabled=false: OK
  • ./mvnw clean verify -pl specs/engine.spec,config/engine.conf,runtime/engine,specs/binding-mqtt.spec,runtime/binding-mqtt,specs/binding-mqtt-kafka.spec,runtime/binding-mqtt-kafka -Dmaven.build.cache.enabled=false: OK (unit tests / ITs, 0 failures)
    • specs/engine.spec: 57 / 107
    • runtime/engine: 322 / 262
    • specs/binding-mqtt.spec: 100 / 606
    • specs/binding-mqtt-kafka.spec: 42 / 290
    • runtime/binding-mqtt: 63 / 485
    • runtime/binding-mqtt-kafka: 55 / 169

Notes for reviewers

  • The stack is linearized by rebase and force push, so expect SHA changes against any earlier view.
  • The original history had a develop merge between the ticket work and the next layer; the test store (TestEntry) change it required is folded into the commit that introduced the ticket unit tests, so every commit from there on compiles its tests. The tree of the stack tip is identical to the original branch tip apart from develop moving forward (CHANGELOG.md).
  • Known limitations and follow-ups are tracked in Support MQTT 5 Shared Subscriptions via Kafka share groups #1801.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2

@jfallows
jfallows force-pushed the feature/mqtt-shared-subscriptions-6-qos2-claim-tickets branch from deada99 to 150db14 Compare November 12, 2026 21:28
@jfallows
jfallows force-pushed the feature/mqtt-shared-subscriptions-6-qos2-claim-tickets branch from 150db14 to 20f262a Compare November 12, 2026 21:45
@jfallows
jfallows added this pull request to stack #3298 November 17, 2026 01:44
@jfallows
jfallows force-pushed the feature/mqtt-shared-subscriptions-6-qos2-claim-tickets branch from 20f262a to cd451c2 Compare November 17, 2026 07:54
Base automatically changed from feature/mqtt-shared-subscriptions-5-mqtt-unsubscribe-drain to develop November 17, 2026 18:36
Let the test store declare an ordered list of expected entry mutations
(put, putIfAbsent, delete, getAndDelete with key, value and ttl). When the
list is configured, each mutation must match the next expectation or the
operation fails with an assertion error, so integration tests can prove what
was written and in which order. Omitting the list keeps every operation
unchecked and an empty list expects no mutation at all.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add a versioned union holding a client's tickets, each with its packet id,
state, topic, partition and offset.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Encode a client's ticket list with the versioned flyweight as unpadded
base64url so it fits a string-valued store, and decode it back, reporting an
unrecognised version so it is never rewritten.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add scripts for shared qos 2 messages whose claim ticket is written before
the message is accepted and delivered: the full PUBREC, PUBREL and PUBCOMP
exchange, a rejecting PUBREC, a fragmented message, two messages in quick
succession, an expired message and pre-existing tickets. Grant shared
subscriptions up to qos 2 and drop the scenario that rejected qos 2
acknowledgements. Declare the expected store writes in test configurations.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…ickets

Run the shared qos 2 scenarios against the proxy with a test store that
asserts each ticket write, and expect no store writes when a qos 2 message
is delivered at qos 1.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
When the test store declares expected entry mutations, fail the store
detach if any expectation was never consumed, so a mutation that should have
happened and did not is reported instead of passing silently.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Keep the stored qos of the shared reconnect scenario as requested now that
shared subscriptions are granted qos 2, and refuse a shared subscription
whose stored ticket list cannot be read rather than overwrite it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…claim tickets

Attach the binding store, load the client's ticket list when its first
shared subscribe stream begins, and write a ticket before a qos 2 message is
accepted and delivered. Hold the frames of the message in a buffer slot,
without crediting Kafka for them, until the coalesced write that contains the
ticket completes, then accept the record and forward the frames in order.
PUBREC moves the ticket to PUBREL pending and sends the release, while PUBCOMP
or a PUBREC with a reason code of 0x80 or above removes it. Grant shared
subscriptions up to qos 2.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add a dup flag to the subscribe data extension flags and specify the
network publish of a redelivered message at qos 1 and qos 2 with the
dup bit set.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Set the dup bit of a publish packet for a qos 1 or qos 2 message when the
subscribe data extension carries the dup flag, so a resent message is
identifiable to the receiver.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add the share name and the filter of the owning shared subscription to the
ticket, and update the stored ticket values of the test configurations. The
ticket of an unrelated subscription is seeded for the existing tickets
scenario.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…t tests

Move the stored ticket list of a client, with its load, coalesced write and
completion handling, out of the subscribe factory so its behavior is covered
without a stream, and add the lookup of tickets by owning subscription and
the clearing of the list.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…hen a shared stream ends

When a shared stream ended while the write of a ticket was pending, the message
was never accepted and was released to another member, yet the ticket still
reached the store, so a later reconnect would resend a message the client
never received. Remove those tickets once the in-flight write completes and
release their packet ids.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Specify resending the release of a ticket awaiting release, and refetching the
message of a ticket awaiting acknowledgment by its exact topic, partition and
offset to redeliver it with the same packet id and the dup flag, then removing
the ticket on completion. A refetched message at a different offset, an expired
message and a missing message drop the ticket without delivery, a recovered
message is delivered before a new one, and a fragmented message is recovered.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…sage

A dropped ticket is removed from the store before the next message is
delivered, so its packet id is free again and the next message reuses it.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…ption is restored

Once the tickets of a client are loaded and the shared stream begins, resend
the release for each ticket of the subscription awaiting release, and refetch
the message of each ticket awaiting acknowledgment by its exact topic,
partition and offset to redeliver it with the same packet id and the dup flag.
A refetched message at a different offset, an expired message or a missing
message drops the ticket once its removal is durable. New messages wait for
the recovery to finish so recovered packet ids are not reused.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…nation

Specify that a session starting clean, a session closing without an expiry
and an expiring session discard the stored tickets of the client, while a
session closing with an expiry keeps them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…mination

Delete the stored tickets of a client when its session starts clean, when a
session without an expiry closes and when the expiry of a session elapses, and
release the packet ids of the discarded tickets held for the client. The
discard goes through the per-client ticket list of the subscribe factory, which
orders it with any write in flight and drops the list once idle.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…ession behavior

Merge the claim ticket state into the per client high water marks, convert
the redeliver scenarios to the version-aware session state builder with an
MQTT 3.1.1 variant of the qos 2 application script, and open the session
close scenario with the retained topic describe.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoWETrA5Cn7uqKAtsMH
@jfallows
jfallows force-pushed the feature/mqtt-shared-subscriptions-6-qos2-claim-tickets branch from cd451c2 to 0e70d12 Compare November 17, 2026 18:36
@jfallows
jfallows merged commit f25ccd0 into develop Nov 17, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants