Skip to content

Publishers

Publishers are responsible for delivering messages to RabbitMQ.

The ServiceBus.Core RabbitMQ provider encapsulates publishing responsibilities behind a consistent abstraction that remains independent from application business logic.


Overview

A publisher receives:

  • a message;
  • a formatter;
  • descriptor configuration;
  • RabbitMQ channel infrastructure.

It is responsible for:

  • serializing the message;
  • selecting the target exchange;
  • applying routing information;
  • delivering the payload.
graph LR

    Message --> Publisher

    Formatter --> Publisher

    Descriptor --> Publisher

    Publisher --> RabbitMQ

Architecture

The publisher implementation is driven by descriptors.

graph TD

    PublisherBoundDescriptor

    IDataFormatter

    Publisher

    RabbitMQ

    PublisherBoundDescriptor --> Publisher

    IDataFormatter --> Publisher

    Publisher --> RabbitMQ

The publisher itself contains minimal business configuration.

Most runtime behavior is controlled through descriptors.


Publisher Responsibilities

The publisher is responsible for:

  • payload serialization;
  • exchange selection;
  • routing key application;
  • delivery confirmation integration;
  • message publication.

The publisher is not responsible for:

  • queue creation;
  • topology design;
  • retry policy design.

Those concerns belong to descriptor configuration.


Low-Level Construction

The following diagram illustrates the dependencies required to construct a publisher.

RabbitMQ.Client v6

graph LR

    IModel --> Publisher

    IDataFormatter --> Publisher

    PublisherBoundDescriptor --> Publisher

Primary channel abstraction:

IModel

RabbitMQ.Client v7

graph LR

    IChannel --> Publisher

    IDataFormatter --> Publisher

    PublisherBoundDescriptor --> Publisher

Primary channel abstraction:

IChannel

Publish Flow

The runtime publishing workflow is conceptually simple.

sequenceDiagram

    participant App

    participant Publisher

    participant Formatter

    participant RabbitMQ

    App->>Publisher: PublishAsync()

    Publisher->>Formatter: Serialize()

    Formatter-->>Publisher: Payload

    Publisher->>RabbitMQ: BasicPublish()

    RabbitMQ-->>Publisher: Ack (optional)

Descriptor Integration

The publisher heavily relies on descriptor metadata.

Typical configuration includes:

  • exchange name;
  • exchange type;
  • routing keys;
  • retry configuration;
  • delivery confirmation settings.

This descriptor-driven model allows infrastructure changes without modifying application code.


Delivery Confirmation

Publishers may optionally use RabbitMQ publisher confirmations.

sequenceDiagram

    participant Publisher

    participant RabbitMQ

    Publisher->>RabbitMQ: Publish

    RabbitMQ-->>Publisher: Ack

This mechanism improves delivery guarantees and provides visibility into publication failures.


Lifecycle

The typical publisher lifecycle is:

graph LR

    Created

    Configured

    Ready

    Publishing

    Disposed

    Created --> Configured

    Configured --> Ready

    Ready --> Publishing

    Publishing --> Disposed

Error Handling

Publishers may encounter failures caused by:

  • connection interruptions;
  • unavailable exchanges;
  • network failures;
  • serialization failures.

Error recovery strategies are generally configured through descriptors and RabbitMQ infrastructure rather than application code.


v6 vs v7

Capability RabbitMQ.Client v6 RabbitMQ.Client v7
Channel Type IModel IChannel
Publisher API Supported Supported
Descriptor Model Same Same
Formatter Model Same Same

The ServiceBus.Core abstraction minimizes the differences between both implementations.