Table of Contents

Class AvroSharpSerializer<T>

Namespace
AvroSharp.Confluent
Assembly
AvroSharp.Confluent.dll

Writes values in Confluent Schema Registry framing: a type generated by AvroSharp (from .avsc files or [AvroSerializable]), a primitive, or generic values (AvroSharpGeneric). It derives from Confluent's Confluent.SchemaRegistry.AsyncSerializer<T, TParsedSchema>, so subject name strategies, registration, use.latest.version, schema ID strategies, references and rules are Confluent's own code; only the Avro encoding is AvroSharp's. The bytes are those of Confluent's Avro serializer for the same schema and value.

public sealed class AvroSharpSerializer<T> : AsyncSerializer<T, AvroSchema>, IAsyncSerializer<T>, ISerializer<T>

Type Parameters

T

The type written.

Inheritance
AsyncSerde<AvroSchema>
AsyncSerializer<T, AvroSchema>
AvroSharpSerializer<T>
Implements
IAsyncSerializer<T>
ISerializer<T>
Inherited Members
AsyncSerializer<T, AvroSchema>.SerializeAsync(T, SerializationContext)

Remarks

It is both asynchronous and synchronous (Confluent.Kafka.ISerializer<T>), so producer.Produce works too. Confluent.Kafka's producer builder has a SetValueSerializer for each, so pass it as one of them, such as (ISerializer<T>)serializer, or use AvroSharpSerdeExtensions, which set the synchronous one. Once a topic's schema ID is known, the synchronous path writes without a task. It waits for the registry the first time, and on every message with use.latest.version, use.latest.with.metadata or use.schema.id, whose rules can run asynchronously.

Constructors

AvroSharpSerializer(ISchemaRegistryClient, AvroSharpSerializerConfig?, RuleRegistry?)

Creates a serializer of a generated type or a primitive, which AvroTypes knows. Generated types register themselves on .NET 5 and later; on .NET Standard, pass the type's AvroTypeInfo to the other constructor, or register it first.

AvroSharpSerializer(ISchemaRegistryClient, AvroTypeInfo<T>, AvroSharpSerializerConfig?, RuleRegistry?)

Creates a serializer of the type that type reads and writes.

AvroSharpSerializer(ISchemaRegistryClient, IEnumerable<Type>, AvroSharpSerializerConfig?, RuleRegistry?)

Creates a serializer of several record types, for a topic that carries them all: each value is written as its own type, with its own record's schema, registered under its own subject with the TopicRecord or Record subject name strategy. Confluent's serializer of ISpecificRecord writes the same.

Properties

CustomSubjectNameStrategy

Gets or sets how subjects are named, as a function (by default, the one of the configuration's subject.name.strategy), for names that Confluent.SchemaRegistry.SubjectNameStrategy can't express, such as a schema context (:.context:orders-value) or a team's prefix. It replaces the configuration's subject.name.strategy. It is asked when a topic's schema is first written, and on every message whose settings need the subject (use.latest.version and the others), so it should give the same subject for the same topic and component.

Methods

ParseSchema(Schema)
Serialize(T, SerializationContext)

Writes a value without a task once the topic's schema ID is known; until then, and with settings whose rules can run asynchronously, it waits for SerializeAsync(T, SerializationContext).

SerializeAsync(T, SerializationContext)

Writes a value: its schema ID (registered or looked up once per subject), then its Avro encoding.