Skip to content

[feat][client] Expose message schema version - #509

Open
dev-ankit wants to merge 1 commit into
apache:masterfrom
dev-ankit:feat/message-schema-version
Open

dev-ankit wants to merge 1 commit into
apache:masterfrom
dev-ankit:feat/message-schema-version

Conversation

@dev-ankit

@dev-ankit dev-ankit commented Oct 4, 2026 •

Copy link
Copy Markdown

Master Issue: #362

This is the first of two parts. A follow-up PR will expose Client.getSchemaInfo(topic, version) so a consumer can fetch the writer schema for a given version.

Motivation

A consumer of an Avro or JSON topic needs the writer schema version of each message to decode messages produced with an older, compatible schema. The Java client exposes this through Message.getSchemaVersion() and the Python client through Message.schema_version() / int_schema_version(). The bundled C++ client already provides Message::hasSchemaVersion() and Message::getLongSchemaVersion(), but the Node client does not expose them.

Modifications

  • src/Message.h, src/Message.cc: add Message.getSchemaVersion(). It returns the value of getLongSchemaVersion() as a number, or null when hasSchemaVersion() is false.
  • index.d.ts: declare getSchemaVersion(): number | null on Message.
  • tstest.ts: add a typing check for the new method.
  • tests/end_to_end.test.js: add the getSchemaVersion test.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added the end-to-end test getSchemaVersion. It:
    • subscribes and produces on a fresh topic with JSON schema V1, and asserts the received message reports version 0;
    • produces on the same topic with a compatible schema V2 (V1 plus a field with a default), and asserts the received message reports version 1;
    • produces and consumes on a fresh topic without a schema, and asserts the message reports null. With no schema, the broker registers no schema for the topic and the message metadata carries no schema version, so hasSchemaVersion() is false.

Locally, the test fails if getSchemaVersion() returns a constant.

Documentation

  • doc-required

  • doc-not-needed
    (New Message getter, documented in index.d.ts, which generates the API reference. The client feature matrix has no row for this.)

  • doc

  • doc-complete

🤖 Generated with Claude Code

Add Message.getSchemaVersion(), which returns the version of the schema
the producer used to serialize the message, or null when the message
carries no schema version. It wraps the C++ client's
hasSchemaVersion() and getLongSchemaVersion().

Consumers of Avro or JSON topics need the writer schema version to
decode messages produced with an older, compatible schema.

Master Issue: apache#362

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.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