Table of Contents

Class EntityExtractor

Namespace
MASES.EntityFrameworkCore.KNet.Serialization
Assembly
MASES.EntityFrameworkCore.KNet.Serialization.dll

This is an helper class to extract data information from Kafka Records stored in topics

public class EntityExtractor
Inheritance
EntityExtractor
Inherited Members

Methods

FromRawValueData(Type, Type, Type, Type, string, byte[], byte[], Headers, bool, IComplexTypeConverterFactory?, IModel?)

Extract information for Entity from recordValue in input

public static object FromRawValueData(Type keyType, Type valueContainer, Type keySerializerSelectorType, Type valueSerializerSelectorType, string topic, byte[] recordKey, byte[] recordValue, Headers headers, bool throwUnmatch = false, IComplexTypeConverterFactory? converterFactory = null, IModel? model = null)

Parameters

keyType Type

Expected key Type

valueContainer Type

Expected ValueContainer Type

keySerializerSelectorType Type

Key serializer to be used

valueSerializerSelectorType Type

ValueContainer serializer to be used

topic string

The Apache Kafka topic the data is coming from

recordKey byte[]

The Apache Kafka record key containing the information

recordValue byte[]

The Apache Kafka record value containing the information

headers Headers

The Apache Kafka record Headers containing the meta information

throwUnmatch bool

Throws exceptions if there is unmatch in data retrieve

converterFactory IComplexTypeConverterFactory

Optional IComplexTypeConverterFactory for ComplexType deserialization. Obtain it from the KEFCore model builder outside of OnModelCreating(ModelBuilder).

model IModel

Optional IModel for accurate property mapping via IEntityType. When provided, the IEntityType is resolved from the CLR type embedded in the record value.

Returns

object

The extracted entity

FromRecord(ConsumerRecord<byte[], byte[]>, bool, IComplexTypeConverterFactory?, IModel?)

Extract information for Entity from record in input

public static object FromRecord(ConsumerRecord<byte[], byte[]> record, bool throwUnmatch = false, IComplexTypeConverterFactory? converterFactory = null, IModel? model = null)

Parameters

record ConsumerRecord<byte[], byte[]>

The Apache Kafka record containing the information

throwUnmatch bool

Throws exceptions if there is unmatch in data retrieve

converterFactory IComplexTypeConverterFactory

Optional IComplexTypeConverterFactory for ComplexType deserialization.

model IModel

Optional IModel for accurate property mapping via IEntityType.

Returns

object

The extracted entity

FromRecord<TEntity>(ConsumerRecord<byte[], byte[]>, bool, IComplexTypeConverterFactory?, IModel?)

Extract information for Entity from record in input

public static TEntity FromRecord<TEntity>(ConsumerRecord<byte[], byte[]> record, bool throwUnmatch = false, IComplexTypeConverterFactory? converterFactory = null, IModel? model = null) where TEntity : class

Parameters

record ConsumerRecord<byte[], byte[]>

The Apache Kafka record containing the information

throwUnmatch bool

Throws exceptions if there is unmatch in data retrieve

converterFactory IComplexTypeConverterFactory

Optional IComplexTypeConverterFactory for ComplexType deserialization.

model IModel

Optional IModel for accurate property mapping via IEntityType.

Returns

TEntity

The extracted entity

Type Parameters

TEntity

The Entity type if it is known

FromTopic(ConsumerConfigBuilder, string, Action<object?, Exception?>, CancellationToken, bool)

Extract information for Entity using consumerConfig configuration within a topicName and send them to cb

public static void FromTopic(ConsumerConfigBuilder consumerConfig, string topicName, Action<object?, Exception?> cb, CancellationToken token, bool onlyLatest = false)

Parameters

consumerConfig ConsumerConfigBuilder

The ConsumerConfigBuilder with configuration

topicName string

The topic containing the data

cb Action<object, Exception>

The Action<T1, T2> where data will be available

token CancellationToken

The CancellationToken to use to stop execution

onlyLatest bool

Start execution only for newest messages and does not execute for oldest, default is from beginning

FromTopic(string, string, Action<object?, Exception?>, CancellationToken, bool)

Extract information for Entity from bootstrapServer within a topicName and send them to cb

public static void FromTopic(string bootstrapServer, string topicName, Action<object?, Exception?> cb, CancellationToken token, bool onlyLatest = false)

Parameters

bootstrapServer string

The Apache Kafka bootstrap.servers

topicName string

The topic containing the data

cb Action<object, Exception>

The Action<T1, T2> where data will be available

token CancellationToken

The CancellationToken to use to stop execution

onlyLatest bool

Start execution only for newest messages and does not execute for oldest, default is from beginning

FromTopic<TEntity>(ConsumerConfigBuilder, string?, Action<TEntity?, Exception?>, CancellationToken, bool, IComplexTypeConverterFactory?, IModel?)

Extract information for Entity using consumerConfig configuration within a topic and send them to cb. When model is provided and topicName is null, the topic name is resolved from the model annotation set by the KEFCore topic naming convention.

public static void FromTopic<TEntity>(ConsumerConfigBuilder consumerConfig, string? topicName, Action<TEntity?, Exception?> cb, CancellationToken token, bool onlyLatest = false, IComplexTypeConverterFactory? converterFactory = null, IModel? model = null) where TEntity : class

Parameters

consumerConfig ConsumerConfigBuilder

The ConsumerConfigBuilder with configuration

topicName string

The topic containing the data. If null and model is provided, the topic name is resolved automatically from the model.

cb Action<TEntity, Exception>

The Action<T1, T2> where data will be available

token CancellationToken

The CancellationToken to use to stop execution

onlyLatest bool

Start execution only for newest messages and does not execute for oldest, default is from beginning

converterFactory IComplexTypeConverterFactory

Optional IComplexTypeConverterFactory for ComplexType deserialization. Obtain it from the KEFCore model builder outside of OnModelCreating(ModelBuilder).

model IModel

Optional IModel for accurate property mapping and automatic topic name resolution.

Type Parameters

TEntity

The Entity type if it is known

FromTopic<TEntity>(string, string, Action<TEntity?, Exception?>, CancellationToken, bool, IComplexTypeConverterFactory?, IModel?)

Extract information for Entity from bootstrapServer within a topicName and send them to cb

public static void FromTopic<TEntity>(string bootstrapServer, string topicName, Action<TEntity?, Exception?> cb, CancellationToken token, bool onlyLatest = false, IComplexTypeConverterFactory? converterFactory = null, IModel? model = null) where TEntity : class

Parameters

bootstrapServer string

The Apache Kafka bootstrap.servers

topicName string

The topic containing the data

cb Action<TEntity, Exception>

The Action<T1, T2> where data will be available

token CancellationToken

The CancellationToken to use to stop execution

onlyLatest bool

Start execution only for newest messages and does not execute for oldest, default is from beginning

converterFactory IComplexTypeConverterFactory

Optional IComplexTypeConverterFactory for ComplexType deserialization. Obtain it from the KEFCore model builder outside of OnModelCreating(ModelBuilder).

model IModel

Optional IModel for accurate property mapping and automatic topic name resolution. When provided and topicName is not given, the topic name is resolved from the model annotation set by the KEFCore topic naming convention.

Type Parameters

TEntity

The Entity type if it is known