How to get access to the confluent registry schema id used by kafka producer?

72 Views Asked by At

I have a kafka producer that uses confluent schema registry. I know that there is an algorithm based on which the KafkaAvroSerializer finds out the matching schemaId from the confluent schema registry (or gets it after registering the schema) so that it includes it as part of the wire format.

Is there a way that I can access the specific schema id that is added by the producer to the messages?

1

There are 1 best solutions below

0
OneCricketeer On

You can use CachedSchemaRegistryClient class to do HTTP lookups to get an ID.

Otherwise, you can use ByteBuffer

Serializer s = new KafkaAvroSerializer();
s.configure(...); // give properties like registry url 
byte[] value = s.serialize(record); // example

ByteBuffer bb = ByteBuffer.wrap(value);
bb.get(); // magic byte
int schemaId = bb.getInt();