Exemple #1
0
        private static async Task <IProducer <OrderKey, OrderEventRecord> > CreateProducer(
            ISchemaRegistryClient registryClient,
            AutomaticRegistrationBehavior automaticRegistrationBehavior)
        {
            var schemaBuilder = new SchemaBuilder(
                SchemaBuilder.CreateDefaultCaseBuilders()
                .Prepend(builder => new OrderEventUnionSchemaBuilderCase(builder)));

            using var serializerBuilder = new SchemaRegistrySerializerBuilder(
                      registryClient,
                      schemaBuilder,
                      serializerBuilder: new BinarySerializerBuilder(
                          BinarySerializerBuilder.CreateDefaultCaseBuilders()
                          .Prepend(builder => new OrderEventUnionSerializerBuilderCase(builder))));

            var producerBuilder = new ProducerBuilder <OrderKey, OrderEventRecord>(
                new ProducerConfig
            {
                BootstrapServers = BootstrapServers,
            });

            await producerBuilder.SetAvroKeySerializer(
                registryClient,
                SubjectNameStrategy.Topic.ConstructKeySubjectName(Topic),
                automaticRegistrationBehavior);

            await producerBuilder.SetAvroValueSerializer(
                serializerBuilder,
                SubjectNameStrategy.Topic.ConstructKeySubjectName(Topic),
                automaticRegistrationBehavior);

            return(producerBuilder.Build());
        }
 /// <summary>
 /// Set the message key serializer.
 /// </summary>
 /// <param name="producerBuilder">
 /// The <see cref="ProducerBuilder{TKey, TValue}" /> instance to be configured.
 /// </param>
 /// <param name="registryClient">
 /// A client to use to resolve the schema. (The client will not be disposed.)
 /// </param>
 /// <param name="id">
 /// The ID of the schema that should be used to serialize keys.
 /// </param>
 public static async Task <ProducerBuilder <TKey, TValue> > SetAvroKeySerializer <TKey, TValue>(
     this ProducerBuilder <TKey, TValue> producerBuilder,
     ISchemaRegistryClient registryClient,
     int id
     )
 {
     using (var serializerBuilder = new SchemaRegistrySerializerBuilder(registryClient))
     {
         return(await producerBuilder.SetAvroKeySerializer(serializerBuilder, id));
     }
 }
 /// <summary>
 /// Set the message key serializer.
 /// </summary>
 /// <param name="producerBuilder">
 /// The <see cref="ProducerBuilder{TKey, TValue}" /> instance to be configured.
 /// </param>
 /// <param name="registryConfiguration">
 /// Schema Registry configuration. Using the <see cref="SchemaRegistryConfig" /> class is
 /// highly recommended.
 /// </param>
 /// <param name="id">
 /// The ID of the schema that should be used to serialize keys.
 /// </param>
 public static async Task <ProducerBuilder <TKey, TValue> > SetAvroKeySerializer <TKey, TValue>(
     this ProducerBuilder <TKey, TValue> producerBuilder,
     IEnumerable <KeyValuePair <string, string> > registryConfiguration,
     int id
     )
 {
     using (var serializerBuilder = new SchemaRegistrySerializerBuilder(registryConfiguration))
     {
         return(await producerBuilder.SetAvroKeySerializer(serializerBuilder, id));
     }
 }
 /// <summary>
 /// Set the message key serializer.
 /// </summary>
 /// <param name="producerBuilder">
 /// The <see cref="ProducerBuilder{TKey, TValue}" /> instance to be configured.
 /// </param>
 /// <param name="registryConfiguration">
 /// Schema Registry configuration. Using the <see cref="SchemaRegistryConfig" /> class is
 /// highly recommended.
 /// </param>
 /// <param name="subject">
 /// The subject of the schema that should be used to serialize keys. The latest version of
 /// the subject will be resolved.
 /// </param>
 /// <param name="registerAutomatically">
 /// Whether to automatically register a schema that matches <typeparamref name="TKey" />
 /// if one does not already exist.
 /// </param>
 public static async Task <ProducerBuilder <TKey, TValue> > SetAvroKeySerializer <TKey, TValue>(
     this ProducerBuilder <TKey, TValue> producerBuilder,
     IEnumerable <KeyValuePair <string, string> > registryConfiguration,
     string subject,
     bool registerAutomatically = false
     )
 {
     using (var serializerBuilder = new SchemaRegistrySerializerBuilder(registryConfiguration))
     {
         return(await producerBuilder.SetAvroKeySerializer(serializerBuilder, subject, registerAutomatically));
     }
 }
 /// <summary>
 /// Set the message key serializer.
 /// </summary>
 /// <param name="producerBuilder">
 /// The <see cref="ProducerBuilder{TKey, TValue}" /> instance to be configured.
 /// </param>
 /// <param name="registryClient">
 /// A client to use to resolve the schema. (The client will not be disposed.)
 /// </param>
 /// <param name="subject">
 /// The subject of the schema that should be used to serialize keys. The latest version of
 /// the subject will be resolved.
 /// </param>
 /// <param name="registerAutomatically">
 /// Whether to automatically register a schema that matches <typeparamref name="TKey" />
 /// if one does not already exist.
 /// </param>
 public static async Task <ProducerBuilder <TKey, TValue> > SetAvroKeySerializer <TKey, TValue>(
     this ProducerBuilder <TKey, TValue> producerBuilder,
     ISchemaRegistryClient registryClient,
     string subject,
     bool registerAutomatically = false
     )
 {
     using (var serializerBuilder = new SchemaRegistrySerializerBuilder(registryClient))
     {
         return(await producerBuilder.SetAvroKeySerializer(serializerBuilder, subject, registerAutomatically));
     }
 }