ch-robinson / dotnet-avro

An Avro implementation for .NET
https://engineering.chrobinson.com/dotnet-avro/
MIT License
135 stars 51 forks source link

Producer throws an exception - Confluent.SchemaRegistry.SchemaRegistryException: Incompatible artifact: <topic name>[AVRO]; error code: 409 #135

Closed mastery-sanket-nagare closed 3 years ago

mastery-sanket-nagare commented 3 years ago

We are supposed to add new fields in the existing schema for an existing topic, for which we added those field in the POCO classes and tried to generate a message. We received the exception Exception occured while preparing a kafka producer : Incompatible artifact: [AVRO]; error code: 409 Confluent.SchemaRegistry.SchemaRegistryException: Incompatible artifact: [AVRO]; error code: 409

We have set registerAutomatically setting to AutomaticRegistrationBehavior.Always. Here is the code snippet for the producer configuration

var typeResolver = new ReflectionResolver( resolveReferenceTypesAsNullable: true // this is the important line );

            var schemaRegistry = new CachedSchemaRegistryClient(schemaRegistryConfig);
            var schemaBuilder = new SchemaBuilder(typeResolver: typeResolver);
            var serializerBuilder = new SchemaRegistrySerializerBuilder(schemaRegistry, schemaBuilder: schemaBuilder);
            var producerBuilder = new ProducerBuilder<TKey, TValue>(producerConfig);
            producerBuilder = producerBuilder.SetAvroValueSerializer(serializerBuilder, this.Topic, registerAutomatically: AutomaticRegistrationBehavior.Always).GetAwaiter().GetResult();
            this.Getproducer = producerBuilder
                    .SetAvroKeySerializer(schemaRegistry, AutomaticRegistrationBehavior.Always)
                    .Build();`
mastery-sanket-nagare commented 3 years ago

@dstelljes Could you please help me with this?

dstelljes commented 3 years ago

Try adjusting the subject compatibility level. You can do that with an API request; currently it’s not possible to change the compatibility level using the Confluent.SchemaRegistry library.

To add fields, the compatibility level either needs to be FORWARD or NONE: https://docs.confluent.io/platform/current/schema-registry/avro.html#summary