Skip to content

[Java] Add multiplexed streams - #1195

Draft
dimitrije-djordjevic-db wants to merge 1 commit into
effort/mux-streams-jni-bridgefrom
effort/mux-streams-jni
Draft

dimitrije-djordjevic-db wants to merge 1 commit into
effort/mux-streams-jni-bridgefrom
effort/mux-streams-jni

Conversation

@dimitrije-djordjevic-db

@dimitrije-djordjevic-db dimitrije-djordjevic-db commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Stack

  1. [Java] Share stream creation in the JNI bridge #1196
  2. [Java] Add the multiplexed stream JNI bridge #1197
  3. [Java] Add multiplexed streams #1195 ← this PR
  4. [Java] Add multiplexed Avro streams #1198

What changes are proposed in this pull request?

Exposes multiplexed streams (Beta) for JSON and Protocol Buffers in the public Java API:

  • multiplexed(streamCount) on the json() and compiledProto(...) sub-builders returns a MultiplexedStreamBuilder. It takes a multiplexed ACK callback and builds a ZerobusMultiplexedJsonStream or ZerobusMultiplexedProtoStream.
  • A multiplexed stream spreads records round-robin across sub-streams. Ingest methods return opaque long message IDs, and unlike other Java streams, multiplexed streams are thread-safe.
  • Every auth mode of StreamBuilder works, federated auth included.
  • A call on a closed multiplexed stream throws NonRetriableException, so retry loops stop. The Javadoc and README say so.
  • Error handling: on a multiplexed stream, a retryable error can still be terminal when recovery is off or exhausted. The README tells users to check isClosed() after any exception: if it returns true, recover the unacknowledged records, close the stream and ingest them into a new one; if it returns false, only that call failed.
  • README, Javadoc, an example (ingest in a loop, then flush()) and NEXT_CHANGELOG.md describe message IDs, failures, resource management and thread safety.

Why: one stream can be the throughput bottleneck. The Rust core has had multiplexed streams since v2.10.0; this exposes them to Java.

Part of #1115.

Follow-up for ordinary streams: #1225

How is this tested?

  • StreamBuilderTest checks that multiplexed(n) rejects an out-of-range stream count and an ordinary ACK callback, and that the build reaches the multiplexed native create, federated auth included.
  • MultiplexedStreamNativeTest and FederatedTokenNativeTest add JSON and federated-auth cases against the in-process mock server.
  • A new env-gated case in IntegrationTest runs a multiplexed protobuf stream against a real Zerobus endpoint.
  • mvn test: 195 run, 0 failed, 33 skipped (env-gated integration tests). The env-gated multiplexed protobuf case passed against a real Zerobus endpoint.

This pull request and its description were written by Isaac.

Expose multiplexed streams (Beta) for JSON and Protocol Buffers:
multiplexed(streamCount) on the json() and compiledProto(...)
sub-builders returns a MultiplexedStreamBuilder, which takes a
multiplexed ACK callback and builds a ZerobusMultiplexedJsonStream or
ZerobusMultiplexedProtoStream. A multiplexed stream spreads records
round-robin across sub-streams to raise throughput when one stream is
the bottleneck. Ingest methods return message IDs, and unlike other
Java streams, multiplexed streams are thread-safe.

Every auth mode of StreamBuilder works, federated auth included. The
README, an example, the changelog and the Javadoc describe message
IDs, failures, resource management and thread safety.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
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.

1 participant