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
keyTypeTypeExpected key Type
valueContainerTypeExpected ValueContainer Type
keySerializerSelectorTypeTypeKey serializer to be used
valueSerializerSelectorTypeTypeValueContainer serializer to be used
topicstringThe Apache Kafka topic the data is coming from
recordKeybyte[]The Apache Kafka record key containing the information
recordValuebyte[]The Apache Kafka record value containing the information
headersHeadersThe Apache Kafka record Headers containing the meta information
throwUnmatchboolThrows exceptions if there is unmatch in data retrieve
converterFactoryIComplexTypeConverterFactoryOptional IComplexTypeConverterFactory for ComplexType deserialization. Obtain it from the KEFCore model builder outside of OnModelCreating(ModelBuilder).
modelIModelOptional 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
recordConsumerRecord<byte[], byte[]>The Apache Kafka record containing the information
throwUnmatchboolThrows exceptions if there is unmatch in data retrieve
converterFactoryIComplexTypeConverterFactoryOptional IComplexTypeConverterFactory for ComplexType deserialization.
modelIModelOptional 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
recordConsumerRecord<byte[], byte[]>The Apache Kafka record containing the information
throwUnmatchboolThrows exceptions if there is unmatch in data retrieve
converterFactoryIComplexTypeConverterFactoryOptional IComplexTypeConverterFactory for ComplexType deserialization.
modelIModelOptional IModel for accurate property mapping via IEntityType.
Returns
- TEntity
The extracted entity
Type Parameters
TEntityThe 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
consumerConfigConsumerConfigBuilderThe ConsumerConfigBuilder with configuration
topicNamestringThe topic containing the data
cbAction<object, Exception>The Action<T1, T2> where data will be available
tokenCancellationTokenThe CancellationToken to use to stop execution
onlyLatestboolStart 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
bootstrapServerstringThe Apache Kafka bootstrap.servers
topicNamestringThe topic containing the data
cbAction<object, Exception>The Action<T1, T2> where data will be available
tokenCancellationTokenThe CancellationToken to use to stop execution
onlyLatestboolStart 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
consumerConfigConsumerConfigBuilderThe ConsumerConfigBuilder with configuration
topicNamestringThe topic containing the data. If null and
modelis provided, the topic name is resolved automatically from the model.cbAction<TEntity, Exception>The Action<T1, T2> where data will be available
tokenCancellationTokenThe CancellationToken to use to stop execution
onlyLatestboolStart execution only for newest messages and does not execute for oldest, default is from beginning
converterFactoryIComplexTypeConverterFactoryOptional IComplexTypeConverterFactory for ComplexType deserialization. Obtain it from the KEFCore model builder outside of OnModelCreating(ModelBuilder).
modelIModelOptional IModel for accurate property mapping and automatic topic name resolution.
Type Parameters
TEntityThe 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
bootstrapServerstringThe Apache Kafka bootstrap.servers
topicNamestringThe topic containing the data
cbAction<TEntity, Exception>The Action<T1, T2> where data will be available
tokenCancellationTokenThe CancellationToken to use to stop execution
onlyLatestboolStart execution only for newest messages and does not execute for oldest, default is from beginning
converterFactoryIComplexTypeConverterFactoryOptional IComplexTypeConverterFactory for ComplexType deserialization. Obtain it from the KEFCore model builder outside of OnModelCreating(ModelBuilder).
modelIModelOptional IModel for accurate property mapping and automatic topic name resolution. When provided and
topicNameis not given, the topic name is resolved from the model annotation set by the KEFCore topic naming convention.
Type Parameters
TEntityThe Entity type if it is known