Skip to content

Publisher Contracts

Publisher contracts define how applications send messages.

The framework currently exposes two primary publishing abstractions:

  • IAsyncPublisher
  • IAsyncRestPublisher

IAsyncPublisher

IAsyncPublisher is the standard asynchronous publishing abstraction.

graph LR

    Application --> IAsyncPublisher

    IAsyncPublisher --> MessageBroker

Typical usage:

public sealed class OrderService(
    IAsyncPublisher publisher)
{
    public async Task PublishAsync(
        OrderCreated message,
        CancellationToken cancellationToken)
    {
        await publisher.PublishAsync(
            message,
            cancellationToken);
    }
}

Responsibilities

  • publish messages;
  • serialize payloads;
  • deliver messages to the configured transport.

Typical Scenarios

  • event publishing;
  • integration events;
  • asynchronous workflows.

IAsyncRestPublisher

IAsyncRestPublisher extends the publisher model for RPC scenarios.

graph LR

    Client --> IAsyncRestPublisher

    IAsyncRestPublisher --> RabbitMQ

    RabbitMQ --> ASPNET["ASP.NET Core"]

The contract is primarily used with:

  • ServiceBus.AspNetCore.Rabbit;
  • RestHostSubscriberBound;
  • request/response workflows.