Class GenericOutboundMessageFilter<TMessage>
- Namespace
- Silverback.Messaging.Producing.Filter
- Assembly
- Silverback.Integration.dll
Can be used to filter the messages to be produced based on the message content.
public class GenericOutboundMessageFilter<TMessage> : IOutboundMessageFilter
Type Parameters
TMessageThe type of the messages to be filtered.
- Inheritance
-
GenericOutboundMessageFilter<TMessage>
- Implements
- Inherited Members
Constructors
GenericOutboundMessageFilter(Func<IOutboundEnvelope<TMessage>, bool>)
Initializes a new instance of the GenericOutboundMessageFilter<TMessage> class.
public GenericOutboundMessageFilter(Func<IOutboundEnvelope<TMessage>, bool> filter)
Parameters
filterFunc<IOutboundEnvelope<TMessage>, bool>The filter function. If it returns
truethe message will be produced, otherwise it will be skipped.
GenericOutboundMessageFilter(Func<TMessage?, bool>)
Initializes a new instance of the GenericOutboundMessageFilter<TMessage> class.
public GenericOutboundMessageFilter(Func<TMessage?, bool> filter)
Parameters
filterFunc<TMessage, bool>The filter function. If it returns
truethe message will be produced, otherwise it will be skipped.
Methods
ShouldProduceAsync(IOutboundEnvelope, CancellationToken)
Returns a value indicating whether the specified message should be produced.
public ValueTask<bool> ShouldProduceAsync(IOutboundEnvelope envelope, CancellationToken cancellationToken)
Parameters
envelopeIOutboundEnvelopeThe envelope containing the 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 produced.
Remarks
The filter might also be invoked while the caller synchronously waits for the message to be produced, for example when using
the synchronous IProducer or IPublisher methods or when publishing a batch. Use
ConfigureAwait(false) when awaiting and keep the asynchronous work short, to avoid deadlocks and blocked threads.