Table of Contents

Class KafkaProducerEndpointConfigurationBuilder<TMessage>

Namespace
Silverback.Messaging.Configuration.Kafka
Assembly
Silverback.Integration.Kafka.dll
public sealed class KafkaProducerEndpointConfigurationBuilder<TMessage> : ProducerEndpointConfigurationBuilder<TMessage, KafkaProducerEndpointConfiguration, KafkaProducerEndpoint, KafkaProducerEndpointConfigurationBuilder<TMessage>>, IMessageSerializationBuilder<TMessage, KafkaProducerEndpointConfigurationBuilder<TMessage>> where TMessage : class

Type Parameters

TMessage

The type of the messages being produced.

Inheritance
KafkaProducerEndpointConfigurationBuilder<TMessage>
Implements
Inherited Members

Constructors

KafkaProducerEndpointConfigurationBuilder(IServiceProvider, string?)

Initializes a new instance of the KafkaProducerEndpointConfigurationBuilder<TMessage> class.

public KafkaProducerEndpointConfigurationBuilder(IServiceProvider serviceProvider, string? friendlyName = null)

Parameters

serviceProvider IServiceProvider

The IServiceProvider.

friendlyName string

An optional friendly to be shown in the human-targeted output (e.g. logs, health checks result, etc.).

Properties

This

Gets this instance.

protected override KafkaProducerEndpointConfigurationBuilder<TMessage> This { get; }

Property Value

KafkaProducerEndpointConfigurationBuilder<TMessage>

Remarks

This is necessary to work around casting in the base classes.

Methods

CreateConfiguration()

Creates the TConfiguration instance.

protected override KafkaProducerEndpointConfiguration CreateConfiguration()

Returns

KafkaProducerEndpointConfiguration

The endpoint.

ProduceTo(TopicPartition)

Specifies the target topic and partition.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(TopicPartition topicPartition)

Parameters

topicPartition TopicPartition

The target topic and partition.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(Func<IOutboundEnvelope<TMessage>, TopicPartition>)

Specifies the function returning the target topic and partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(Func<IOutboundEnvelope<TMessage>, TopicPartition> topicPartitionFunction)

Parameters

topicPartitionFunction Func<IOutboundEnvelope<TMessage>, TopicPartition>

The function returning the target topic and partition index for the message being produced.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(Func<IOutboundEnvelope<TMessage>, string>, Func<IOutboundEnvelope<TMessage>, int>?)

Specifies the functions returning the target topic and partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(Func<IOutboundEnvelope<TMessage>, string> topicFunction, Func<IOutboundEnvelope<TMessage>, int>? partitionFunction = null)

Parameters

topicFunction Func<IOutboundEnvelope<TMessage>, string>

The function returning the target topic for the message being produced.

partitionFunction Func<IOutboundEnvelope<TMessage>, int>

The optional function returning the target partition index for the message being produced. If null the partition is automatically derived from the message key (use KafkaKeyMemberAttribute to specify a message key, otherwise a random one will be generated).

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(Func<TMessage?, TopicPartition>)

Specifies the function returning the target topic and partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(Func<TMessage?, TopicPartition> topicPartitionFunction)

Parameters

topicPartitionFunction Func<TMessage, TopicPartition>

The function returning the target topic and partition index for the message being produced.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(Func<TMessage?, string>, Func<TMessage?, int>?)

Specifies the functions returning the target topic and partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(Func<TMessage?, string> topicFunction, Func<TMessage?, int>? partitionFunction = null)

Parameters

topicFunction Func<TMessage, string>

The function returning the target topic for the message being produced.

partitionFunction Func<TMessage, int>

The optional function returning the target partition index for the message being produced. If null the partition is automatically derived from the message key (use KafkaKeyMemberAttribute to specify a message key, otherwise a random one will be generated).

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(string, Func<IOutboundEnvelope<TMessage>, int>)

Specifies the target topic and the function returning the target partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(string topic, Func<IOutboundEnvelope<TMessage>, int> partitionFunction)

Parameters

topic string

The target topic.

partitionFunction Func<IOutboundEnvelope<TMessage>, int>

The function returning the target partition index for the message being produced.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(string, Func<IOutboundEnvelope<TMessage>, string[]>, Func<IOutboundEnvelope<TMessage>, int>?)

Specifies the target topic format and an optional function returning the target partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(string topicFormatString, Func<IOutboundEnvelope<TMessage>, string[]> topicArgumentsFunction, Func<IOutboundEnvelope<TMessage>, int>? partitionFunction = null)

Parameters

topicFormatString string

The topic format string that will be combined with the arguments returned by the topicArgumentsFunction using a Format(string, params object[]).

topicArgumentsFunction Func<IOutboundEnvelope<TMessage>, string[]>

The function returning the arguments to be used to format the string.

partitionFunction Func<IOutboundEnvelope<TMessage>, int>

The optional function returning the target partition index for the message being produced. If null the partition is automatically derived from the message key (use KafkaKeyMemberAttribute to specify a message key, otherwise a random one will be generated).

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(string, Func<TMessage?, int>)

Specifies the target topic and the function returning the target partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(string topic, Func<TMessage?, int> partitionFunction)

Parameters

topic string

The target topic.

partitionFunction Func<TMessage, int>

The function returning the target partition index for the message being produced.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(string, Func<TMessage?, string[]>, Func<TMessage?, int>?)

Specifies the target topic format and an optional function returning the target partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(string topicFormatString, Func<TMessage?, string[]> topicArgumentsFunction, Func<TMessage?, int>? partitionFunction = null)

Parameters

topicFormatString string

The topic format string that will be combined with the arguments returned by the topicArgumentsFunction using a Format(string, params object[]).

topicArgumentsFunction Func<TMessage, string[]>

The function returning the arguments to be used to format the string.

partitionFunction Func<TMessage, int>

The optional function returning the target partition index for the message being produced. If null the partition is automatically derived from the message key (use KafkaKeyMemberAttribute to specify a message key, otherwise a random one will be generated).

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceTo(string, int?)

Specifies the target topic and optionally the target partition.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceTo(string topic, int? partition = null)

Parameters

topic string

The target topic.

partition int?

The optional target partition index. If null the partition is automatically derived from the message key (use KafkaKeyMemberAttribute to specify a message key, otherwise a random one will be generated).

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

ProduceToDynamicTopic()

Specifies that the target topic and, optionally, the target partition will be specified per each message using the envelope's SetKafkaDestinationTopic(IOutboundEnvelope, string, int?) extension method.

public KafkaProducerEndpointConfigurationBuilder<TMessage> ProduceToDynamicTopic()

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

SetKafkaKey(Func<IOutboundEnvelope<TMessage>, object?>)

Uses the specified value provider function to set the kafka key for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> SetKafkaKey(Func<IOutboundEnvelope<TMessage>, object?> valueProvider)

Parameters

valueProvider Func<IOutboundEnvelope<TMessage>, object>

The value provider function.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

SetKafkaKey(Func<TMessage?, object?>)

Uses the specified value provider function to set the kafka key for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> SetKafkaKey(Func<TMessage?, object?> valueProvider)

Parameters

valueProvider Func<TMessage, object>

The value provider function.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

SetKafkaKey<TMessageChildType>(Func<IOutboundEnvelope<TMessageChildType>, object?>)

Uses the specified value provider function to set the kafka key for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> SetKafkaKey<TMessageChildType>(Func<IOutboundEnvelope<TMessageChildType>, object?> valueProvider) where TMessageChildType : TMessage

Parameters

valueProvider Func<IOutboundEnvelope<TMessageChildType>, object>

The value provider function.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

Type Parameters

TMessageChildType

The type of the messages to be enriched with this kafka key.

SetKafkaKey<TMessageChildType>(Func<TMessageChildType?, object?>)

Uses the specified value provider function to set the kafka key for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> SetKafkaKey<TMessageChildType>(Func<TMessageChildType?, object?> valueProvider) where TMessageChildType : TMessage

Parameters

valueProvider Func<TMessageChildType, object>

The value provider function.

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

Type Parameters

TMessageChildType

The type of the messages to be enriched with this kafka key.

UseEndpointResolver<TResolver>()

Specifies the type of the IKafkaProducerEndpointResolver<TMessage> to be used to resolve the target topic and partition for each message being produced.

public KafkaProducerEndpointConfigurationBuilder<TMessage> UseEndpointResolver<TResolver>() where TResolver : IKafkaProducerEndpointResolver<TMessage>

Returns

KafkaProducerEndpointConfigurationBuilder<TMessage>

The KafkaProducerEndpointConfigurationBuilder<TMessage> so that additional calls can be chained.

Type Parameters

TResolver

The type of the IKafkaProducerEndpointResolver<TMessage> to be used.