Skip to content

Channel Events

Channel events provide visibility into RabbitMQ channel activity.

They are useful when diagnosing connection, publishing and consuming issues.


Enable Channel Events

Channel events must be enabled explicitly.

Example:

EnableChannelEvents = true;

Publisher Diagnostics

Publishers expose:

OnChannelEventFired

Example:

publisher.OnChannelEventFired.Add(
    async (sender, args) =>
    {
        Console.WriteLine(
            $"{DateTime.UtcNow:u} {args}");

        await Task.CompletedTask;
    });

Subscriber Diagnostics

Subscribers expose:

OnChannelEventFired

Example:

subscriber.OnChannelEventFired.Add(
    async (sender, args) =>
    {
        Console.WriteLine(
            $"{DateTime.UtcNow:u} {args}");

        await Task.CompletedTask;
    });

ChannelEventArgs

Handlers receive:

ChannelEventArgs

This object contains information about the RabbitMQ event that occurred.

One of the most useful properties is:

EventTag

which identifies the event category generated by the broker client.


Typical Diagnostic Scenarios

Channel events are useful for:

  • connection failures;
  • channel shutdowns;
  • publisher confirmations;
  • consumer lifecycle events;
  • topology creation failures;
  • unexpected broker behavior.

Event Handler Failures

Avoid throwing exceptions from event handlers.

Bad example:

publisher.OnChannelEventFired.Add(
    (sender, args) =>
    {
        throw new InvalidOperationException();
    });

Prefer logging and diagnostics.


Use channel events as a diagnostic and observability mechanism.

graph LR

    RabbitMQ

    Channel

    ChannelEventArgs

    Handler

    RabbitMQ --> Channel

    Channel --> ChannelEventArgs

    ChannelEventArgs --> Handler

Diagnostic Checklist

Verify:

  • channel events enabled;
  • handlers registered;
  • event handler exceptions;
  • channel lifecycle;
  • connection lifecycle.