confluent-schema-registry
confluent-schema-registry copied to clipboard
How to get the schema subject from a message?
I have a service that publishes messages to a queue (not Kafka), and these messages are encoded using a schema from the Schema Registry.
On the consumer side, I want to validate that the message was encoded using a schema subject that the consumer knows and supports.
Extracting the schema ID is straightforward (bytes 1-4 of the message), but I couldn't find an API that allows retrieving the subject associated with a given schema ID.
Is there a recommended way to achieve this? Any ideas or best practices?
Thanks!
I have the same need.
In our case, we're processing events with multiple event types sent on a single kafka topic. In other words, we're receiving events on a given topic that were encoded with varying schemas.
When processing these events, we'd like to determine the schema subject of the schema used to encode the received event so we can handle it appropriately.
As @Matan-Yadaev-Forter indicated, it's possible to get the id of the schema used to decode the incoming event message.
It'd be nice if the library exposed a convenience method for retrieving the schema subject:
const schemaSubject = getSchemaSubjectFromMessage(buffer);
Looking at the decode method, looks like it'd be possible to fetch a message's schema by using the wireDecoder (to get the registryId) and the existing getSchema method:
@joyrexus You can get the schema this way, but I didn't find how I can extract the subject out of it.
@Matan-Yadaev-Forter You should be able to use the registry API directly to get the schema subject for each version: GET /schemas/ids/{int: id}/versions