Skip to content

[Java] Add the multiplexed stream JNI bridge - #1197

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

dimitrije-djordjevic-db wants to merge 1 commit into
effort/mux-streams-jni-shared-creationfrom
effort/mux-streams-jni-bridge

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 ← this PR
  3. [Java] Add multiplexed streams #1195
  4. [Java] Add multiplexed Avro streams #1198

What changes are proposed in this pull request?

Adds the JNI bridge for multiplexed streams (Beta). Nothing in this PR is reachable from the public builder yet; the next PR of this stack adds the public API.

  • multiplexed.rs: native methods to create a multiplexed stream with OAuth, a headers provider or federated auth, ingest single records and batches, wait for message IDs, flush, close and recover unacknowledged batches. A multiplexed ACK callback receives message IDs.
  • BaseZerobusMultiplexedStream holds the native handle behind a read/write lock. Several threads can use one stream, and close() waits for calls that are already inside native code.
  • ZerobusMultiplexedProtoStream is the first typed stream on top of the base class.
  • An empty batch also goes to the native stream. It sends nothing, but after a terminal failure it throws the same exception as a non-empty batch.
  • The native ABI version goes from 3 to 4 because of the new native methods, so a stale libzerobus_jni is rejected at load.
  • A call on a closed stream throws NonRetriableException, not the retryable ZerobusException.

Why: the bridge, the thread-safe base and its native tests are the core of the feature. Reviewing them before the public API keeps each PR small.

Part of #1115.

Note: the open Java PRs #1098 (ABI 3) and #1103 (ABI 4) also bump the native ABI version. Whichever merges second renumbers.

How is this tested?

  • New MultiplexedStreamNativeTest runs against the in-process mock server: create failures keep their retry class, protobuf records and message IDs cross the bridge in both directions, a server error reaches onError and keeps the record, a callback cannot block or stop delivery, threads share one stream, and close() waits for a call inside native code.
  • cargo test -p zerobus-jni: 16 passed; clippy and fmt clean.
  • mvn test: 188 run, 0 failed, 32 skipped (env-gated integration tests); Javadoc clean.

This pull request and its description were written by Isaac.

Bridge the Rust multiplexed stream (Beta) to Java: native methods to
create a multiplexed stream with OAuth, a headers provider or
federated auth, ingest single records and batches, wait for message
IDs, flush, close and recover unacknowledged batches, plus a
multiplexed ACK callback that receives message IDs.

BaseZerobusMultiplexedStream holds the native handle behind a
read-write lock, so several threads can use one stream while close()
waits for calls already inside native code. ZerobusMultiplexedProtoStream
is the first typed stream on top of it. Nothing is reachable from the
public builder yet; the next change adds the public API.

New native methods, so the native ABI version goes to 4 and a stale
libzerobus_jni is rejected at load.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
@dimitrije-djordjevic-db
dimitrije-djordjevic-db force-pushed the effort/mux-streams-jni-shared-creation branch from 71827e2 to eb3584d Compare November 27, 2026 12:59
@dimitrije-djordjevic-db
dimitrije-djordjevic-db force-pushed the effort/mux-streams-jni-bridge branch from 4f53a47 to dc669b6 Compare November 27, 2026 13:10
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