Table of Contents

Class ConsumerEndpointConfigurationBuilder<TMessage, TConfiguration, TBuilder>

Namespace
Silverback.Messaging.Configuration
Assembly
Silverback.Integration.dll
public abstract class ConsumerEndpointConfigurationBuilder<TMessage, TConfiguration, TBuilder> : EndpointConfigurationBuilder<TMessage, TConfiguration, TBuilder> where TConfiguration : ConsumerEndpointConfiguration where TBuilder : ConsumerEndpointConfigurationBuilder<TMessage, TConfiguration, TBuilder>

Type Parameters

TMessage

The type of the messages being consumed.

TConfiguration

The type of the configuration being built.

TBuilder

The actual builder type.

Inheritance
EndpointConfigurationBuilder<TMessage, TConfiguration, TBuilder>
ConsumerEndpointConfigurationBuilder<TMessage, TConfiguration, TBuilder>
Derived
Inherited Members

Constructors

ConsumerEndpointConfigurationBuilder(IServiceProvider, string?)

protected ConsumerEndpointConfigurationBuilder(IServiceProvider serviceProvider, string? friendlyName)

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.).

Methods

AllowStreaming()

Specifies that the subscribers can subscribe a stream (IAsyncEnumerable<T>, IEnumerable<T>, etc.) pushed with all messages consumed from that endpoint (or partition). This setup can be used for basic stream processing, but it's more fragile and should be used with care. Some features, like error policies, won't work as expected. This is disabled by default.

public TBuilder AllowStreaming()

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Build()

Builds the endpoint configuration instance.

public override sealed TConfiguration Build()

Returns

TConfiguration

The endpoint configuration.

ConsumeBinaryMessages(Action<BinaryMessageDeserializerBuilder>?)

Sets the deserializer to an instance of BinaryMessageDeserializer<TModel> to wrap the consumed binary messages into a BinaryMessage.

public TBuilder ConsumeBinaryMessages(Action<BinaryMessageDeserializerBuilder>? deserializerBuilderAction = null)

Parameters

deserializerBuilderAction Action<BinaryMessageDeserializerBuilder>

An optional Action<T> that takes the BinaryMessageDeserializerBuilder and configures it.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

ConsumeRaw(Action<RawMessageDeserializerBuilder>?)

Sets the deserializer to an instance of RawMessageDeserializer<T> to return the consumed messages as raws.

public TBuilder ConsumeRaw(Action<RawMessageDeserializerBuilder>? deserializerBuilderAction = null)

Parameters

deserializerBuilderAction Action<RawMessageDeserializerBuilder>

An optional Action<T> that takes the RawMessageDeserializerBuilder and configures it.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

ConsumeStrings(Action<StringMessageDeserializerBuilder>?)

Sets the deserializer to an instance of StringMessageDeserializer<T> to return the consumed messages as strings.

public TBuilder ConsumeStrings(Action<StringMessageDeserializerBuilder>? deserializerBuilderAction = null)

Parameters

deserializerBuilderAction Action<StringMessageDeserializerBuilder>

An optional Action<T> that takes the StringMessageDeserializerBuilder and configures it.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Decrypt(IDecryptionSettings)

Specifies the settings to be used to decrypt the messages.

public TBuilder Decrypt(IDecryptionSettings encryptionSettings)

Parameters

encryptionSettings IDecryptionSettings

The IDecryptionSettings.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

DecryptUsingAes(byte[], byte[]?)

Specifies that the AES algorithm has to be used to decrypt the messages.

public TBuilder DecryptUsingAes(byte[] key, byte[]? initializationVector = null)

Parameters

key byte[]

The secret key for the symmetric algorithm.

initializationVector byte[]

The optional initialization vector (IV) for the symmetric algorithm. If null it is expected that the IV is prepended to the actual encrypted message.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

DecryptUsingAes(Func<string?, byte[]>, byte[]?)

Specifies that the AES algorithm has to be used to decrypt the messages.

public TBuilder DecryptUsingAes(Func<string?, byte[]> decryptionKeyProvider, byte[]? initializationVector = null)

Parameters

decryptionKeyProvider Func<string, byte[]>

The function to be used to retrieve the encryption key according to the identifier passed in the header (see EncryptionKeyId).

initializationVector byte[]

The optional initialization vector (IV) for the symmetric algorithm. If null it is expected that the IV is prepended to the actual encrypted message.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

DeserializeJson(Action<JsonMessageDeserializerBuilder>?)

Sets the deserializer to an instance of JsonMessageDeserializer<TMessage> to deserialize the consumed JSON.

public TBuilder DeserializeJson(Action<JsonMessageDeserializerBuilder>? deserializerBuilderAction = null)

Parameters

deserializerBuilderAction Action<JsonMessageDeserializerBuilder>

An optional Action<T> that takes the JsonMessageDeserializerBuilder and configures it.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

DeserializeUsing(IMessageDeserializer)

Specifies the IMessageDeserializer to be used to deserialize the messages.

public TBuilder DeserializeUsing(IMessageDeserializer deserializer)

Parameters

deserializer IMessageDeserializer

The IMessageDeserializer.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

EnableBatchProcessing(int, TimeSpan?)

Enables batch processing.

public TBuilder EnableBatchProcessing(int batchSize, TimeSpan? maxWaitTime = null)

Parameters

batchSize int

The number of messages to be processed in batch.

maxWaitTime TimeSpan?

The maximum amount of time to wait for the batch to be filled, measured from its first message. After this time the batch will be completed even if the specified batchSize is not reached.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Filter(IInboundMessageFilter)

Sets the filter used to filter out the consumed messages that should not be processed, replacing any previously configured filter. The filtered messages aren't delivered to any subscriber and are committed (or acknowledged) like the messages that no subscriber handles.

public TBuilder Filter(IInboundMessageFilter filter)

Parameters

filter IInboundMessageFilter

The IInboundMessageFilter to be used.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Filter(Func<IInboundEnvelope<TMessage>, bool>)

Sets the filter used to filter out the consumed messages that should not be processed, replacing any previously configured filter. The filtered messages aren't delivered to any subscriber and are committed (or acknowledged) like the messages that no subscriber handles. The messages of other types than TMessage are always processed.

public TBuilder Filter(Func<IInboundEnvelope<TMessage>, bool> filter)

Parameters

filter Func<IInboundEnvelope<TMessage>, bool>

The predicate that returns true for the envelopes to be processed.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Filter(Func<TMessage?, bool>)

Sets the filter used to filter out the consumed messages that should not be processed, replacing any previously configured filter. The filtered messages aren't delivered to any subscriber and are committed (or acknowledged) like the messages that no subscriber handles. The messages of other types than TMessage are always processed.

public TBuilder Filter(Func<TMessage?, bool> filter)

Parameters

filter Func<TMessage, bool>

The predicate that returns true for the messages to be processed. It receives null for a tombstone.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Filter<TFilter>()

Sets a filter of the specified type, used to filter out the consumed messages that should not be processed, replacing any previously configured filter. The filtered messages aren't delivered to any subscriber and are committed (or acknowledged) like the messages that no subscriber handles. The filter is resolved via dependency injection for each message, from the service scope of the message, therefore the type must be registered in the service collection.

public TBuilder Filter<TFilter>() where TFilter : IInboundMessageFilter

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Type Parameters

TFilter

The type of the IInboundMessageFilter to be used.

IgnoreUnhandledMessages()

Specifies that the message has to be silently ignored if no subscriber is handling it.

public TBuilder IgnoreUnhandledMessages()

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Remarks

An ignored message isn't added to the sequence it belongs to and doesn't count toward its length. A custom ISequenceReader whose sequences are completed by their last message, or by a total length equal to the fixed number of messages they are made of, doesn't complete a sequence whose last message (or any message, with a total length) is ignored, which is eventually aborted as incomplete. The built-in batches, chunked messages and streams aren't affected.

OnError(IErrorPolicy)

Specifies the error policy to be applied when an exception occurs during the processing of the consumed messages.

public TBuilder OnError(IErrorPolicy errorPolicy)

Parameters

errorPolicy IErrorPolicy

The IErrorPolicy.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

OnError(Action<IErrorPolicyBuilder>)

Specifies the error policy to be applied when an exception occurs during the processing of the consumed messages.

public TBuilder OnError(Action<IErrorPolicyBuilder> errorPolicyBuilderAction)

Parameters

errorPolicyBuilderAction Action<IErrorPolicyBuilder>

An Action<T> that takes the Silverback.Messaging.Configuration.ErrorPolicyBuilder and configures it.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

ThrowIfUnhandled()

Specifies that an exception must be thrown if no subscriber is handling the received message. This option is enabled by default. Use the IgnoreUnhandledMessages() method to disable it.

public TBuilder ThrowIfUnhandled()

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

WithSequenceTimeout(TimeSpan)

Sets the timeout after which an incomplete sequence that isn't pushed with new messages will be aborted and discarded. The default is a conservative 30 minutes.

public TBuilder WithSequenceTimeout(TimeSpan timeout)

Parameters

timeout TimeSpan

The timeout.

Returns

TBuilder

The endpoint builder so that additional calls can be chained.

Remarks

This setting is ignored for batches (BatchSequence), use the maxWaitTime parameter of the EnableBatchProcessing(int, TimeSpan?) method instead.