confluent-kafka-dotnet
Show / Hide Table of Contents

Class SyncOverAsyncDeserializer<T>

An adapter that allows an async deserializer to be used where a sync deserializer is required. In using this adapter, there are two potential issues you should be aware of:

  1. If you are working in a single threaded SynchronizationContext (for example, a WindowsForms application), you must ensure that all methods awaited by your deserializer (at all levels) are configured to NOT continue on the captured context, otherwise your application will deadlock. You do this by calling .ConfigureAwait(false) on every method awaited in your deserializer implementation. If your deserializer makes use of a library that does not do this, you can get around this by calling await Task.Run(() => ...) to force the library method to execute in a SynchronizationContext that is not single threaded. Note: all Confluent async deserializers comply with the above.

  2. In any application, there is potential for a deadlock due to thread pool exhaustion. This can happen because in order for an async method to complete, a thread pool thread is typically required. However, if all available thread pool threads are in use waiting for the async methods to complete, there will be no threads available to complete the tasks (deadlock). Due to (a) the large default number of thread pool threads in the modern runtime and (b) the infrequent need for a typical async deserializer to wait on an async result (i.e. most deserializers will only infrequently need to execute asynchronously), this scenario should not commonly occur in practice.

Inheritance
object
SyncOverAsyncDeserializer<T>
Implements
IDeserializer<T>
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Confluent.Kafka.SyncOverAsync
Assembly: Confluent.Kafka.dll
Syntax
public class SyncOverAsyncDeserializer<T> : IDeserializer<T>
Type Parameters
Name Description
T

Constructors

SyncOverAsyncDeserializer(IAsyncDeserializer<T>)

Initializes a new SyncOverAsyncDeserializer.

Declaration
public SyncOverAsyncDeserializer(IAsyncDeserializer<T> asyncDeserializer)
Parameters
Type Name Description
IAsyncDeserializer<T> asyncDeserializer

Methods

Deserialize(ReadOnlySpan<byte>, bool, SerializationContext)

Deserialize a message key or value.

Declaration
public T Deserialize(ReadOnlySpan<byte> data, bool isNull, SerializationContext context)
Parameters
Type Name Description
ReadOnlySpan<byte> data

The data to deserialize.

bool isNull

Whether or not the value is null.

SerializationContext context

Context relevant to the deserialize operation.

Returns
Type Description
T

The deserialized value.

Implements

IDeserializer<T>
In this article