Я использую реестр схемы Kafka для создания / использования сообщений Kafka, например, у меня есть два поля, оба они строкового типа, псевдосхема, как показано ниже :
{"name": "test1", "type": "string"}
{"name": "test2", "type": "string"}
но после отправки и потребления мне нужно изменить схему, чтобы изменить второе поле на длинный тип, после чего возникло следующее исключение:
Schema being registered is incompatible with an earlier schema; error code: 409
Я запутался, если реестр схемы не может развить обновление / изменение схемы, тогда почему я должен использовать реестр схемы или сказать, почему я использую Avro?

Поля не могут быть переименованы в режиме совместимости с BACKWARD. В качестве обходного пути можно изменить правила совместимости для реестра схем.
Согласно документы:
The schema registry server can enforce certain compatibility rules when new schemas are registered in a subject. Currently, we support the following compatibility rules.
Backward compatibility (default): A new schema is backward compatible if it can be used to read the data written in all previous schemas. Backward compatibility is useful for loading data into systems like Hadoop since one can always query data of all versions using the latest schema.
Forward compatibility: A new schema is forward compatible if all previous schemas can read data written in this schema. Forward compatibility is useful for consumer applications that can only deal with data in a particular version that may not always be the latest version.
Full compatibility: A new schema is fully compatible if it’s both backward and forward compatible.
No compatibility: A new schema can be any schema as long as it’s a valid Avro.
Настройка compatibility на NONE должна помочь.
# Update compatibility requirements globally
$ curl -X PUT -H "Content-Type: application/vnd.schemaregistry.v1+json" \
--data '{"compatibility": "NONE"}' \
http://localhost:8081/config
И ответ должен быть
{"compatibility":"NONE"}
Я обычно не рекомендую устанавливать совместимость с NONE на предмете, за исключением случаев крайней необходимости.
https://docs.confluent.io/current/avro.html Возможно, вам потребуется добавить «по умолчанию»: null.
Вы также можете удалить существующий и зарегистрировать обновленный.
Вы можете просто добавить такое значение по умолчанию.
{"name": "test3", "type": "string","default": null}
Да, это не строковое значение по умолчанию для строки: null
милая и простая вещь для обратной совместимости, спасибо. работает !
Если вам нужна только новая схема, и вам не нужны предыдущие схемы из реестра схем, вы можете удалить старые схемы, как указано ниже. :
Я тестировал это с помощью confluent-kafka, и у меня это сработало.
curl -X DELETE http://localhost:8081/subjects/Kafka-value
curl -X DELETE http://localhost:8081/subjects/Kafka-value/versions/1
curl -X DELETE http://localhost:8081/subjects/Kafka-value/versions/latest
Ссылка: https://docs.confluent.io/platform/current/schema-registry/schema-deletion-guidelines.html
Разве это не даст вам
org.apache.avro.AvroTypeException: Invalid default for field test3: null not a "string"?