Skip to content

feat(binding-mqtt-kafka): shared subscriptions for QoS 0 and 1 over Kafka share groups - #3111

Merged
jfallows merged 25 commits into
feature/mqtt-shared-subscriptions-2-mqtt-server-clientfrom
feature/mqtt-shared-subscriptions-3-mqtt-kafka-share
Nov 17, 2026
Merged

jfallows merged 25 commits into
feature/mqtt-shared-subscriptions-2-mqtt-server-clientfrom
feature/mqtt-shared-subscriptions-3-mqtt-kafka-share

Conversation

@jfallows

@jfallows jfallows commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Maps MQTT 5 shared subscriptions onto Kafka share groups in binding-mqtt-kafka for QoS 0 and 1. Before this PR a $share subscribe was rejected with 0x9E; with the capability enabled and a store configured it is granted and delivered through a SHARE stream, so each matching message reaches exactly one session in the shared subscription.

Part of #1801

Configuration and capability

  • zilla.binding.mqtt.kafka.shared.subscription.available (default true). The capability is advertised only when the property is enabled and the binding has options.store. Otherwise CONNACK advertises Shared Subscription Available = 0 and $share is rejected with 0x9E, as before.
  • The share route condition on mqtt-kafka routes, as a topic and share pairing. A shared subscription with no matching route is rejected. Schema and config adapter updated, including a store option.
  • A broker without share group support (share.version not enabled) fails the SUBSCRIBE with SUBACK 0x83 and the event BINDING_KAFKA_API_VERSION_REJECTED.

KafkaSharedProxy

  • Opens one SHARE stream per shared subscription and maps data and headers, including fragmented records carried via deferred. The share group id is derived from the group id prefix, the share name and the filter.
  • ACCEPTs QoS 0 and expired messages, maps PUBACK to ACCEPT and a PUBACK reason code of 0x80 or above to REJECT. UNSUBSCRIBE or disconnect ends the SHARE stream. Granted QoS of a shared subscription is capped per subscriber.

Per-client packet ids

Packet ids are allocated per client in 1..65535 (wrap, never 0, skipping ids in flight) by a bounded allocator, replacing the factory-wide counter that overflowed uint16 (#3064).

Also in this layer

  • binding-kafka and binding-kafka.spec: a follow-up to the share stream from the first PR so that record headers are carried on the first frame of a fragmented share record (with its spec), and an integer header builder in the share data extension spec functions.

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 (this PR) 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 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/binding-mqtt.spec,runtime/binding-mqtt,specs/binding-mqtt-kafka.spec,runtime/binding-mqtt-kafka,config/binding-mqtt.conf,config/binding-mqtt-kafka.conf,specs/binding-kafka.spec,runtime/binding-kafka -Dmaven.build.cache.enabled=false: OK (unit tests / ITs, 0 failures)
    • specs/binding-kafka.spec: 256 / 591
    • specs/binding-mqtt.spec: 93 / 494
    • specs/binding-mqtt-kafka.spec: 32 / 262
    • runtime/binding-kafka: 257 / 496
    • runtime/binding-mqtt: 63 / 421
    • runtime/binding-mqtt-kafka: 29 / 151
    • config/binding-mqtt-kafka.conf: 21 unit tests

Notes for reviewers

  • The stack is linearized by rebase and force push, so expect SHA changes against any earlier view.
  • Commits keep the test-first order: the spec or test commit comes before the implementation commit.
  • The next two PRs harden the SUBACK and UNSUBSCRIBE behavior of binding-mqtt (SUBACK gated on application stream BEGIN, UNSUBSCRIBE draining), and later PRs add QoS 2 delivery with durable claim tickets and the subscription lifecycle. Known limitations are tracked in Support MQTT 5 Shared Subscriptions via Kafka share groups #1801.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2

Add an optional store reference to the binding options and an optional
share name or wildcard to subscribe route conditions.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Carry the store reference in the binding options and pair each subscribe
topic of a condition with an optional share name.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Match each condition topic together with its share name. An omitted share
places no constraint and a share condition never matches a subscription
that is not shared.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
The share data extension builder only wrote text header values, so a
script could not express headers that carry a binary integer.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Specify the session capability, granted QoS, and shared subscribe streams
against Kafka share streams, including acknowledgement, expiry, reset and
route share conditions.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…and cap their granted qos

Advertise the shared subscriptions capability only when the property is
enabled and the binding declares a store. A shared subscription is granted
at most QoS 1 in the session state returned to the mqtt binding.

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

Open one Kafka share stream per shared subscription with a group id derived
from the share name and the encoded topic filter. Map share records to
subscribe messages and map acknowledgements to ACCEPT or REJECT. Messages
that cannot be delivered are accepted when expired and rejected when
fragmented.

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

The share fan-out delivered a record's headers on the first data frame only
when the record was delivered whole, so a record delivered in fragments
carried them on the final frame alone. The staged record is complete before
delivery, so the first frame now always carries the record's headers beside
its key, mirroring the fetch cache path, which carries headers on both the
first and final frames. The final frame keeps carrying headers, as the fetch
path does, so a reader of either frame sees them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Replace the scenario that rejected a fragmented share record with scenarios
that deliver it. The first frame carries the record's key and headers, so a
fragmented QoS 1 message is acknowledged with PUBACK and accepted, a
fragmented QoS 0 message is accepted after its final frame, a fragmented
expired message is skipped and accepted, and a fragmented QoS 1 message
acknowledged with a failure reason code is rejected.

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

A share record delivered in fragments is no longer rejected. Its first frame
carries the key and headers, so the first MQTT frame is built from them,
including the remaining length as deferred, and the continuation and final
frames are forwarded as they arrive, as for a subscription that is not shared.
The delivery state of the record in progress is held as a decoder state:
deliver, or skip for an expired record whose frames are swallowed. A packet id
is allocated on the first frame for a message delivered at QoS 1 or above.
The record is accepted after its final frame when it is delivered at QoS 0 or
was skipped, and otherwise on the acknowledgement of its packet id.

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

The group id of a shared subscription ends with its epoch, which keeps the
value "0" until the epoch is taken from the subscription registry.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Replace the parallel topic and share lists of a mqtt-kafka condition with a
subscribe config that carries a topic and an optional share, as mqtt does,
and match each entry as a pair. The subscribe and publish shapes of a
condition in zilla.yaml are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Two clients subscribed to the same filter each receive their own first
qos 1 message with packet id 1 and acknowledge it independently.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Allocates ids in 1..65535, wraps without yielding 0, skips ids still in
flight and reports exhaustion instead of failing the worker.

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

Fails until packet ids are allocated per client: the second client
receives packet id 2 instead of 1.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Packet ids are allocated per client and start again at 1 once the client
has no open subscribe streams.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
A single worker-wide counter handed out ids above 65535, which fails the
flyweight builder and terminates the engine worker, and let unrelated
clients share one id space. Each client now owns a bounded id allocator
and its in-flight id to offset mapping, shared by all its subscribe
streams on the worker and released when the last of them closes. When
all 65535 ids of one client are in flight the stream is aborted rather
than failing the worker.

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

The mqtt-kafka condition builder pairs each subscribe topic with its share and lists publish topics separately, so the generated route calls subscribe() or publish(topic) instead of the removed topic() and kind().

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…tained describe and per-client offsets

Open the shared session scenarios with the retained topic describe, expect
the publish qos max configured by the test, position the second client of
the multiple client scenario at its own offset, and drop the shared
reject fragmented message scenario that the fragmented delivery replaced.

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-3-mqtt-kafka-share branch from d7ad9b9 to ac1a6a5 Compare November 17, 2026 05:45
@jfallows
jfallows merged commit 58083f7 into develop Nov 17, 2026
81 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