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
TMessageThe 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
filterFunc<IInboundEnvelope<TMessage>, bool>The filter function. If it returns
truethe 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
filterFunc<TMessage, bool>The filter function, which receives
nullfor a tombstone. If it returnstruethe 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
envelopeIInboundEnvelopeThe envelope containing the deserialized message to be filtered.
cancellationTokenCancellationTokenA 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.