Skip to content

fix(binding-kafka): share stream fixes found against a real broker and mqtt.kafka.proxy example - #3116

Closed
jfallows wants to merge 162 commits into
feature/mqtt-shared-subscriptions-7-share-lifecyclefrom
claude/laughing-cray-e6yaqr
Closed

jfallows wants to merge 162 commits into
feature/mqtt-shared-subscriptions-7-share-lifecyclefrom
claude/laughing-cray-e6yaqr

Conversation

@jfallows

@jfallows jfallows commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes found while running the stack against a real Kafka 4.1.1 broker, and the mqtt.kafka.proxy example extended with shared subscriptions. This is the top of the stack, and the designated branch for the whole change.

Part of #1801

Fixes

  • binding-kafka: a share stream begins once its first ShareFetch is accepted. The broker fixes the share partition start offset at the first fetch it handles, so the reply BEGIN waits for that fetch and a message published right after SUBACK is not lost.
  • binding-kafka: the share staging directory name is bounded, so long group ids and topics stay within file name limits.
  • binding-mqtt-kafka: the share group id is derived without colons, since the share coordinator keys its state as groupId:topicId:partition and a real broker rejects a group id containing :. The id is dot separated.
  • binding-asyncapi: injects mqtt-kafka routes with both subscribe and publish conditions.

Example

examples/mqtt.kafka.proxy gains the share-group settings, a memory store, and two shared subscribers in test.sh.

Verified against Kafka 4.1.1 (manual, not part of CI)

Load split across shared subscribers, group id accepted by the broker, QoS 2 recovery after reconnect, epoch bump after the last member leaves, and a broker without share groups.

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 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 (this PR) 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-kafka.spec,runtime/binding-kafka,specs/binding-mqtt-kafka.spec,runtime/binding-mqtt-kafka,runtime/binding-asyncapi -Dmaven.build.cache.enabled=false: OK (unit tests / ITs, 0 failures)
    • specs/binding-kafka.spec: 256 / 591
    • runtime/binding-kafka: 264 / 496
    • specs/binding-mqtt-kafka.spec: 52 / 298
    • runtime/binding-mqtt-kafka: 105 / 177
    • runtime/binding-asyncapi: 27 / 20
  • binding-mqtt and engine are unchanged since the layers below and were verified there.

Notes for reviewers

  • Interleaved fixes found in the real-broker run live in this layer. Known limitations are in the Support MQTT 5 Shared Subscriptions via Kafka share groups #1801 description.
  • The stack is linearized by rebase and force push, so expect SHA changes against any earlier view. The tree of this tip equals the pre-linearization tip except for develop moving forward (CHANGELOG.md).
  • The example's test.sh needs Docker and Kafka 4.1.1 with share.version=1; it was not run as part of the module builds above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2

Describe a Kafka share group client stream (KIP-932): begin carries the
group id, member id, topic, filters and the maximum number of records
in flight; data carries the acquired record with its partition offset
and delivery count; flush carries a per-record acknowledgement of
ACCEPT, RELEASE or REJECT with an optional correlation.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add paired client and server k3po scripts for the share stream at the
application level and at the wire level (FindCoordinator v6, Metadata
v13, ShareGroupHeartbeat v1, ShareFetch v1, ShareAcknowledge v1), with
spec-level ITs for both protocol sides and a client IT that drives the
scripts against the engine.

Scenarios cover receiving records, fragmented delivery, acknowledging
with ACCEPT, RELEASE and REJECT piggybacked on the next fetch or sent
as an explicit acknowledge, filtering of non-matching records,
multiple partitions, assignment changes, flow control bounded by the
stream window and the records in flight, leaving the group, and error
handling for coordinator, member, topic and authorization failures.

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

Every share group connection begins with an ApiVersions v0 exchange, ahead of
any SASL handshake and request, and the chosen version of each API used on the
connection (Metadata 13, FindCoordinator 6 on the bootstrap connection,
ShareGroupHeartbeat 1 on the coordinator, ShareFetch 1 and ShareAcknowledge 1 on
the partition leader) must fall within the advertised range. An absent API or an
excluded range rejects the stream with UNSUPPORTED_VERSION.

Adds scenarios for an absent share API, version range mismatch on the bootstrap,
coordinator and leader connections, application ABORT and RESET mid-stream, and
network abort of the coordinator and leader connections mid-session.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Adds flexible-version codec scopes for Metadata v13, FindCoordinator v6,
ShareGroupHeartbeat v1, ShareFetch v1 and ShareAcknowledge v1.

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

KafkaRecordFilter evaluates ORed filters of ANDed key, header, headers and not
conditions over a decoded record, with the same semantics as the cache filter
conditions. KafkaShareRanges tracks disjoint ordered offset ranges.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Handles the SHARE stream kind with one share group member per stream:
per-connection ApiVersions negotiation, Metadata and FindCoordinator on a
bootstrap connection, ShareGroupHeartbeat on the coordinator connection, and
ShareFetch and ShareAcknowledge on each partition leader connection, with
acknowledgements piggybacked on fetch and a graceful leave on stream close.

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

A broker without the share feature enabled still advertises the share APIs but
answers ShareGroupHeartbeat with UNSUPPORTED_VERSION, which resets the stream.

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

The share stream delivers every record of a fetch response as it streams and
reports the acquired offset ranges with their delivery counts in a reply flush
once a partition's records are complete, so the per-record data extension no
longer carries a delivery count.

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

Share record data frames now precede the acquired ranges flush of their
partition; add scenarios for a record larger than the decode slot, a batch of
records, records outside the acquired ranges, acquired offset gaps and
compressed batches. Remove the client-level key filter scenarios, assert the
api version rejected event in the unsupported version scenarios.

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

Report the whole batch of a flow controlled response in one acquired ranges
flush and match the api version rejected event messages formatted by the
binding.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
The event formatter resolved no title for the share group heartbeat, share
fetch and share acknowledge api keys and failed on events raised for them.

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

Decode the share fetch response progressively so a record or batch larger than
the decode slot streams to the application in fragments. Records are delivered
as they are decoded and the acquired offset ranges with their delivery counts
are reported in a reply flush once the acquired records of a partition are
decoded. Offsets acquired but not delivered are accepted or rejected, and the
client no longer evaluates record filters.

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

Share fetch requests carry the same static limits on every request, taken
from configuration like the regular fetch: the maximum bytes of a response
and the maximum records (also the batch size) of a response. The share begin
extension no longer carries a records limit, and the application window only
paces delivery of already requested records.

Add the client.share.fetch.max.bytes and client.share.fetch.max.records
properties. Scenarios that relied on a records limit to hold back the next
fetch until an acknowledgement was written now withhold the end of the
response until the acknowledgement is written, so the acknowledgement
piggybacks on the next fetch. Replace the window scenario with a response
larger than the application window delivered across window replenishments,
add leaving while a fetch is outstanding, and remove the scenarios that
exercised a records limit or a standalone acknowledge while the stream
could not fetch.

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

Send the configured maximum bytes, maximum records and batch size on every
share fetch, as the regular fetch does, instead of deriving them from the
application window and the unacknowledged record count. The next request is
sent once the previous response has been completely consumed; the application
window only paces delivery of requested records and network backpressure
holds the rest. Acquired but unacknowledged offsets are still tracked for
acknowledgement piggybacking and release on leave, but no longer gate fetches.

Acknowledgements always piggyback on the next share fetch, so the standalone
acknowledge request is now only sent when leaving, and the unused records
count helper is removed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…unt and optional member id

The share acquired flush reports the acquisition lock timeout of the fetch
response so a consumer of the stream knows how long the acquired records stay
locked. The share data extension reports the delivery count of a record, 0
meaning not reported, and the share begin extension makes the member id
optional for streams that do not own a share group member.

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

The kafka cache server holds one share group member per share group and
fans out the acquired records to the share streams attached to the group,
distributing each record to exactly one stream, returning the records of a
stream that ends to the other streams and releasing the records when the last
stream ends. Records are held until their acquired range is known, filtered on
the complete record, dropped when their acquisition lock expires and withheld
from delivery when too little lock time remains.

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

Wait for the share stream to receive the record before the member stream
aborts, wait for the first acknowledgement before the second record is
distributed, and observe the reset of the initial direction before the abort
of the reply direction, as the cache group scenarios do.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
The kafka cache server holds one share group member per binding and share
group id and fans the acquired records out to the share streams attached to
the group. Records are staged in an ephemeral cache partition as they are
streamed, held until the acquired flush names their offset, evaluated against
the group filters on the complete record, and delivered to exactly one attached
stream with window, in rotation. Acknowledgements are forwarded to the member
stream and confirmations are routed back to the originating stream by
correlation. The records of a stream that ends are redelivered to the other
streams, and the records are released when the last stream ends.

Records are dropped when their acquisition lock expires and are released
instead of delivered when too little lock time remains. The member stream is
granted window only while the acquired records held stay under a bound. The
cache client keeps a share stream per attached stream as a pass-through.

Add the cache.server.share.staging.max.bytes, cache.server.share.staging.segment.bytes
and cache.server.share.lock.margin.percent properties. The record filter
evaluates the headers of a cache entry.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…timeout and uncorrelated rejected acknowledgement

The acquired flush reports the broker lock timeout minus the time elapsed
since the share fetch that produced the response was sent, floored at zero,
so a response held back in the network buffer does not overstate the
remaining lock. An engine clock that advances by a fixed step makes the
delayed response deterministic.

When the lock of a record held by the cache lapses before it is acknowledged,
the fan-out releases the record to the member stream instead of dropping it.
The expiry is driven by the signaler, held records are not delivered because
the attached stream has no window, and the release is awaited as an ordinary
frame. A lock that has already lapsed on arrival is released the same way.

A release the broker rejects as an invalid record state does not fail the
share stream and the offset no longer counts as in flight when leaving.

The staging bound scenario streams records larger than the member stream
credit, so the window withheld at the bound is exhausted and the stream only
completes when the bound resumes the window.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…an assignment change revokes the partition

An acknowledgement the application has requested a confirmation for and that
is still to be sent cannot reach the broker once the partition is revoked
from the member, so the confirmation reports an invalid record state instead
of success.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…ords and confirm revoked acknowledgements

The client factory reports the lock timeout of an acquired flush as the
broker lock timeout minus the time elapsed since the share fetch that
produced the response was sent, floored at zero, so a response held back in
the network buffer does not overstate the lock that remains.

The cache fan-out releases a record to the member stream when its lock
expires, whether or not it was delivered, instead of dropping it. The broker
rejects a release for a lapsed or reacquired record as an invalid record
state without affecting the member, and the client factory has already
cleared the offset from its in-flight set when the acknowledgement was
accepted, so the rejection of an uncorrelated acknowledgement is ignored.

A confirmation requested for an acknowledgement that is still to be sent when
an assignment change revokes the partition now reports an invalid record
state, as the acknowledgement can no longer reach the broker, instead of
reporting success when the next fetch completes.

The staging bound documentation states that the bound gates acknowledgement
and can be exceeded by one response, so it needs no relation to the share
fetch size.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add an optional shareName to MqttTopicFilter, bump MqttSessionState to
version 2, and keep the version 1 layout readable through
MqttTopicFilterV1 and MqttSessionStateV1. MqttFunctions gain sharedFilter
and sharedSubscription builders, a shared filter begin matcher and a
version 1 session state builder.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add an optional share condition to when[].subscribe[] in the schema, the
condition config, builder and adapter. The value is a share name or a
wildcard.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Add paired network and application scripts, spec ITs and runtime ITs for
shared subscriptions: stream per shared subscription, share name and
filter identity, shared with non-shared filters, QoS change on
re-subscribe, unsubscribe, malformed and no-local rejection, share route
condition, delivery at the lower of message and granted QoS, restore on
reconnect from version 2 and version 1 session state, and MQTT 3.1.1
filters declined in the SUBACK. Correct the topic filter length in the
unsupported shared subscription script.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Recognize a shared subscription by its $share/ prefix and validate the
share name and topic filter. A shared subscription is identified by its
share name and topic filter, opens one application subscribe stream at the
granted QoS, ignores retain handling and rejects no local. Re-subscribing
updates the granted QoS with a filter flush, and unsubscribing ends the
stream. Messages are delivered at the lower of the message QoS and the
granted QoS. Match the share condition when routing a subscription.

Persist the share name in version 2 of the session state and keep reading
version 1. Decline a shared subscription from an MQTT 3.1.1 client with a
SUBACK failure code and remove the unused shared subscription property.

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
…est store

The type: test store asserts the order and content of the entry
mutations it receives through options.assertions, but the atomic
increment, conditional replace and multi-key delete operations had no
way to be expected.

Extend the assertion shape: increment takes key, delta, optional ttl and
an optional resulting value; replace takes key, expected, value and
optional ttl; delete takes key or keys. Reads, locks and watches remain
unasserted. The schema requires the fields each operation needs.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
…ion by its live members

Join the registry of a shared subscription before the share stream begins so the
group id carries the epoch of the current life of the subscription, and leave it
when the session state no longer holds the subscription or when the session of
the client is discarded.

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
…pted

The broker fixes the start offset of a share partition at the first ShareFetch it handles, so a record produced after the stream began but before that fetch was never delivered. Send the first fetch as soon as a partition is assigned and begin the reply once that fetch is accepted, so a consumer that observes the begin has an initialized share partition. A rejection before then resets the stream without a begin.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
The staging directory was named after the group id and topic, so a long group id exceeded the file name limit and terminated the engine worker. Derive the name from a SHA-256 digest of the group id and topic.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
A share group id containing a colon is accepted by the group coordinator but rejected by the share coordinator, which splits its state key on colons, so no partition was ever assigned. Separate the prefix, share name, encoded filter and epoch with dots, replace the colons of the configured prefix with dots and escape the colons and percent signs of the share name. The subscription registry key is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVCzGPCAFKe3smSge2
Enable Kafka share groups with the share.version feature and a single replica share coordinator state topic, configure the memory store on the mqtt-kafka binding, start zilla after the kafka-init service completes, and assert in the example test that two shared subscribers receive each message exactly once. Document shared subscriptions in the README.

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

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3154. The stack was rebased onto the current develop, and the stack branches were renamed to feature/mqtt-shared-subscriptions-* because the build workflow only runs for pull requests whose base is develop, support/** or feature/**. The replacement has the same title and description, with the stack table updated. Head: feature/mqtt-shared-subscriptions-8-real-broker, base: feature/mqtt-shared-subscriptions-7-share-lifecycle.


Generated by Claude Code

@jfallows jfallows closed this Nov 12, 2026
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