Avro schema doesn't honor backward compatibilty

前端 未结 3 1900
甜味超标
甜味超标 2021-01-17 18:53

I have this avro schema

{
 \"namespace\": \"xx.xxxx.xxxxx.xxxxx\",
 \"type\": \"record\",
 \"name\": \"MyPayLoad\",
 \"fields\": [
     {\"name\": \"filed1\"         


        
3条回答
  •  青春惊慌失措
    2021-01-17 19:21

    finally i got this working. I need to give both the schemas in the SpecificDatumReader So i modified the parsing like this where i passed both the old and new schema in the reader and it worked like a charm

    public static final MyPayLoad parseBinaryPayload(byte[] payload) {
            DatumReader payloadReader = new SpecificDatumReader<>(SCHEMA_V1, SCHEMA_V2);
            Decoder decoder = DecoderFactory.get().binaryDecoder(payload, null);
            MyPayLoad myPayLoad = null;
            try {
                myPayLoad = payloadReader.read(null, decoder);
            } catch (IOException e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
    
            return myPayLoad;
        }
    

提交回复
热议问题