Table of Contents

Class GenericInboundMessageFilter<TMessage>

Namespace
Silverback.Messaging.Consuming.Filter
Assembly
Silverback.Integration.dll

Can be used to filter the consumed messages based on the message content.

public class GenericInboundMessageFilter<TMessage> : IInboundMessageFilter

Type Parameters

TMessage

The type of the messages to be filtered.

Inheritance
GenericInboundMessageFilter<TMessage>
Implements
Inherited Members

Remarks

The filter applies only to the messages of type TMessage: the messages of the other types are always processed.

Constructors

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

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

public GenericInboundMessageFilter(Func<IInboundEnvelope<TMessage>, bool> filter)

Parameters

filter Func<IInboundEnvelope<TMessage>, bool>

The filter function. If it returns true the message will be processed, otherwise it will be skipped.

GenericInboundMessageFilter(Func<TMessage?, bool>)

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

public GenericInboundMessageFilter(Func<TMessage?, bool> filter)

Parameters

filter Func<TMessage, bool>

The filter function, which receives null for a tombstone. If it returns true the message will be processed, otherwise it will be skipped.

Methods

ShouldProcessAsync(IInboundEnvelope, CancellationToken)

Returns a value indicating whether the specified consumed message should be processed.

public ValueTask<bool> ShouldProcessAsync(IInboundEnvelope envelope, CancellationToken cancellationToken)

Parameters

envelope IInboundEnvelope

The envelope containing the deserialized message to be filtered.

cancellationToken CancellationToken

A CancellationToken used to cancel the operation.

Returns

ValueTask<bool>

A ValueTask<TResult> representing the asynchronous operation. The task result contains a value indicating whether the message should be processed.

Remarks

The messages that should not be processed are skipped: they aren't delivered to any subscriber and are committed (or acknowledged) like the messages that no subscriber handles. An exception thrown by the filter is handled by the error policy of the endpoint, like any other processing error.