Skip to content

[Java] Add multiplexed Avro streams - #1198

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

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

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

What changes are proposed in this pull request?

Adds multiplexed Avro streams (Beta):

  • multiplexed(streamCount) on the avro(...) sub-builder builds a ZerobusMultiplexedAvroStream. It ingests GenericRecords or pre-encoded Avro datums across sub-streams.
  • Multiplexed streams are thread-safe, so the Avro encoder must be too. AvroEncoder.threadSafe() encodes each call into its own buffer, and its schema-match cache is a concurrent map. Ordinary Avro streams keep the single-threaded encoder that reuses one buffer.
  • README and NEXT_CHANGELOG.md now list Avro next to JSON and Protocol Buffers. The README adds that an Avro record that cannot be encoded fails only its own call with NonRetriableException and sends nothing; the stream stays usable.

Why: with this PR, Java multiplexed streams support JSON, Protocol Buffers and Avro. Arrow multiplexed streams are not part of this stack.

Closes #1115.

How is this tested?

  • MultiplexedStreamNativeTest adds Avro cases against the in-process mock server, including several threads that ingest Avro records into one stream; the test checks that every record arrives intact.
  • New AvroEncoderTest cases check that the thread-safe encoder writes the same bytes as the ordinary one, and that it accepts records from many equal schema instances.
  • StreamBuilderTest adds Avro cases: multiplexed(n) rejects an out-of-range stream count, and the Avro build reaches the multiplexed native create.
  • A new env-gated case in IntegrationTest runs a multiplexed Avro stream against a real Zerobus endpoint.
  • mvn test: 200 run, 0 failed, 34 skipped (env-gated integration tests). The env-gated multiplexed protobuf and Avro cases passed 2/2 against a real Zerobus endpoint.

This pull request and its description were written by Isaac.

Add multiplexed(streamCount) to the avro(...) sub-builder, building a
ZerobusMultiplexedAvroStream (Beta) that ingests GenericRecords or
pre-encoded Avro datums across sub-streams.

Multiplexed streams are thread-safe, so the Avro encoder must be too.
AvroEncoder.threadSafe() encodes each call into its own buffer, and
its schema-match cache is a concurrent map; ordinary Avro streams
keep the single-threaded encoder that reuses one buffer.

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