Interface IProtoMessageConsumer
One test's view of a broker, created by CreateConsumerAsync(CancellationToken) during setup and disposed with the test's teardown. A consumer belongs to exactly one test: it must never be shared, and its disposal removes whatever the adapter declared for the test (queues, in RabbitMQ's case). Each test gets its own tap on an exchange destination, so parallel tests cannot steal each other's messages there. A queue destination is shared: tests awaiting the same queue compete for it.
public interface IProtoMessageConsumer : IAsyncDisposable
- Inherited Members
- Extension Methods
Methods
AwaitAsync(string, Func<ProtoMessage, bool>, TimeSpan, CancellationToken)
Waits for the first message on destination matching predicate
within timeout. Only messages that reach this consumer count, so another test's
traffic on a shared broker can never satisfy the await. Awaits on one consumer are serialized in
call order, and a delivery that matches no active predicate is not consumed: it stays available to
a later await on the same consumer, so concurrent awaits neither lose nor steal each other's
messages and every matched message is consumed exactly once.
ValueTask<ProtoMessage> AwaitAsync(string destination, Func<ProtoMessage, bool> predicate, TimeSpan timeout, CancellationToken cancellationToken = default)
Parameters
destinationstringpredicateFunc<ProtoMessage, bool>timeoutTimeSpancancellationTokenCancellationToken
Returns
AwaitAsync(string, string?, Func<ProtoMessage, bool>, TimeSpan, CancellationToken)
Waits like AwaitAsync(string, Func<ProtoMessage, bool>, TimeSpan, CancellationToken)
but matches only a delivery the transport carried under routingKey; null
matches any routing key and behaves exactly like the plain overload. The default implementation
filters the predicate by RoutingKey, which a consumer over a broker
that keeps history gets for free; a tap adapter overrides it to bind the routing key on its tap as
well, so a direct exchange delivers the key this await matches.
ValueTask<ProtoMessage> AwaitAsync(string destination, string? routingKey, Func<ProtoMessage, bool> predicate, TimeSpan timeout, CancellationToken cancellationToken = default)
Parameters
destinationstringroutingKeystringpredicateFunc<ProtoMessage, bool>timeoutTimeSpancancellationTokenCancellationToken
Returns
PrepareAsync(IReadOnlyCollection<string>, CancellationToken)
Prepares the destinations this test intends to await before the system under test publishes, so a message published after this call is not missed. Adapters that keep history may treat it as a no-op. Prepares may run concurrently: a prepare for several destinations may prepare them at the same time, and separate prepares may overlap, so every destination must own the resources it declares (the RabbitMQ adapter gives each tap its own channel). Every requested destination is attempted even when one of them fails; a failed destination is reported to the caller and does not stop the others from being prepared.
ValueTask PrepareAsync(IReadOnlyCollection<string> destinations, CancellationToken cancellationToken = default)
Parameters
destinationsIReadOnlyCollection<string>cancellationTokenCancellationToken