Interface IProtoMessageBroker

Namespace
ProtoTest.Messaging
Assembly
ProtoTest.Messaging.dll

The broker capability's adapter contract. The capability owns the broker resource and the trace-facing API; an adapter owns the client technology (RabbitMQ today, others later). One broker is shared by the whole run and may publish concurrently, while every test gets its own IProtoMessageConsumer.

public interface IProtoMessageBroker
Extension Methods

Properties

Name

The adapter name recorded on the capability and the broker entity.

string Name { get; }

Property Value

string

Methods

CreateConsumerAsync(CancellationToken)

Creates a consumer for one test. The caller owns it for that test and disposes it with the test's teardown, so an adapter can declare per-test taps and remove them at the test boundary: parallel tests on the same destination stay isolated instead of stealing each other's messages.

ValueTask<IProtoMessageConsumer> CreateConsumerAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<IProtoMessageConsumer>

DeclareAsync(IReadOnlyCollection<string>, CancellationToken)

Declares each destination on the broker, so publishing to it and awaiting it both work even when nothing else declares it - a suite that owns the broker and publishes its own events. Called during test setup before any tap is prepared. Declaration is idempotent: a destination that already exists, declared earlier in the run or by the application with the same shape, is left as it is, and a repeated declaration is a no-op. An adapter whose broker has no topology implements this as a no-op, because every destination already exists there; the default implementation refuses instead of pretending, so an adapter that cannot create the destination fails the declaration loudly rather than letting the test publish into nothing.

ValueTask DeclareAsync(IReadOnlyCollection<string> destinations, CancellationToken cancellationToken = default)

Parameters

destinations IReadOnlyCollection<string>
cancellationToken CancellationToken

Returns

ValueTask

Exceptions

NotSupportedException

The adapter does not declare destinations.

PublishAsync(ProtoMessage, CancellationToken)

Publishes one message to a destination.

ValueTask PublishAsync(ProtoMessage message, CancellationToken cancellationToken = default)

Parameters

message ProtoMessage
cancellationToken CancellationToken

Returns

ValueTask