private Confluent.SchemaRegistry.Serdes.AvroSerializerConfig GetSerializerConfig(ISchemaRegistryConfig config) { Confluent.SchemaRegistry.Serdes.AvroSerializerConfig c = new Confluent.SchemaRegistry.Serdes.AvroSerializerConfig(); if (config.AutoRegisterSchemas.HasValue) { c.AutoRegisterSchemas = config.AutoRegisterSchemas; } return(c); }
/// <summary> /// Initialize a new instance of the AvroSerializer class. /// When passed as a parameter to the Confluent.Kafka.Producer constructor, /// the following configuration properties will be extracted from the producer's /// configuration property collection: /// /// avro.serializer.buffer.bytes (default: 128) - Initial size (in bytes) of the buffer /// used for message serialization. Use a value high enough to avoid resizing /// the buffer, but small enough to avoid excessive memory use. Inspect the size of /// the byte array returned by the Serialize method to estimate an appropriate value. /// Note: each call to serialize creates a new buffer. /// /// avro.serializer.auto.register.schemas (default: true) - true if the serializer should /// attempt to auto-register unrecognized schemas with Confluent Schema Registry, /// false if not. /// </summary> /// <param name="schemaRegistryClient"> /// An implementation of ISchemaRegistryClient used for /// communication with Confluent Schema Registry. /// </param> /// <param name="config"> /// Serializer configuration properties (refer to /// <see cref="AvroSerializerConfig" />) /// </param> public AvroSerializer(ISchemaRegistryClient schemaRegistryClient, AvroSerializerConfig config = null) { this.schemaRegistryClient = schemaRegistryClient; if (config == null) { return; } var nonAvroConfig = config.Where(item => !item.Key.StartsWith("avro.")); if (nonAvroConfig.Count() > 0) { throw new ArgumentException($"AvroSerializer: unknown configuration parameter {nonAvroConfig.First().Key}"); } var avroConfig = config.Where(item => item.Key.StartsWith("avro.")); foreach (var property in avroConfig) { if (property.Key != AvroSerializerConfig.PropertyNames.AutoRegisterSchemas && property.Key != AvroSerializerConfig.PropertyNames.UseLatestVersion && property.Key != AvroSerializerConfig.PropertyNames.BufferBytes && property.Key != AvroSerializerConfig.PropertyNames.SubjectNameStrategy) { throw new ArgumentException($"AvroSerializer: unknown configuration property {property.Key}"); } } if (config.BufferBytes != null) { this.initialBufferSize = config.BufferBytes.Value; } if (config.AutoRegisterSchemas != null) { this.autoRegisterSchema = config.AutoRegisterSchemas.Value; } if (config.NormalizeSchemas != null) { this.normalizeSchemas = config.NormalizeSchemas.Value; } if (config.UseLatestVersion != null) { this.useLatestVersion = config.UseLatestVersion.Value; } if (config.SubjectNameStrategy != null) { this.subjectNameStrategy = config.SubjectNameStrategy.Value.ToDelegate(); } if (this.useLatestVersion && this.autoRegisterSchema) { throw new ArgumentException($"AvroSerializer: cannot enable both use.latest.version and auto.register.schemas"); } }
private Confluent.SchemaRegistry.Serdes.AvroSerializerConfig GetSerializerConfig(ISchemaRegistryConfig config) { Confluent.SchemaRegistry.Serdes.AvroSerializerConfig c = new Confluent.SchemaRegistry.Serdes.AvroSerializerConfig(); if (config.AutoRegisterSchemas.HasValue) { c.AutoRegisterSchemas = config.AutoRegisterSchemas; } if (config.SubjectNameStrategy.HasValue) { c.SubjectNameStrategy = (Confluent.SchemaRegistry.SubjectNameStrategy)config.SubjectNameStrategy.Value; } return(c); }