-
This is the field we defined in our .avsc After using producer with the Chr.Avro.Confluent auto registry turn on, we saw the registered schema looks like this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Your .avsc file won't have any effect in that situation, since the schema that Chr.Avro.Confluent registers is generated by reflecting your .NET types. If you want to use the contents of the .avsc file instead of a generated schema, don't use auto registration; instead, read the file and use the Schema Registry client to register it. Alternatively, if you want Chr.Avro to use .NET's nullable semantics (i.e., any reference types can have a null value) when generating schemas, you can provide a custom schema builder: using Chr.Avro.Abstract;
using Chr.Avro.Confluent;
using Chr.Avro.Resolution;
using Confluent.Kafka;
using Confluent.SchemaRegistry;
var registry = new CachedSchemaRegistryClient(new SchemaRegistryConfig { ... });
var typeResolver = new ReflectionResolver(
resolveReferenceTypesAsNullable: true // this is the important line
);
var schemaBuilder = new SchemaBuilder(typeResolver: typeResolver);
var serializerBuilder = new SchemaRegistrySerializerBuilder(registry, schemaBuilder: schemaBuilder)
var producerBuilder = new ProducerBuilder<Ignore, SomeValue>();
await builder.SetAvroValueSerializer(serializerBuilder, "test-subject", registerAutomatically: AutomaticRegistrationBehavior.Always); |
Beta Was this translation helpful? Give feedback.
Your .avsc file won't have any effect in that situation, since the schema that Chr.Avro.Confluent registers is generated by reflecting your .NET types. If you want to use the contents of the .avsc file instead of a generated schema, don't use auto registration; instead, read the file and use the Schema Registry client to register it.
Alternatively, if you want Chr.Avro to use .NET's nullable semantics (i.e., any reference types can have a null value) when generating schemas, you can provide a custom schema builder: