Publisher Channel Events¶
Publishers expose RabbitMQ channel-level events through the common IAsyncBrokerClient contract.
This is useful when you want to observe broker/channel behavior while the publisher is running.
Enable Channel Events¶
Channel events are enabled through the publisher descriptor.
var descriptor = new PublisherBoundDescriptor
{
EnableChannelEvents = true,
Exchanges =
{
new ExchangeBoundDescriptor
{
Name = "orders",
Type = ExchangeTypes.Direct,
Durable = true
}
}
};
Register Event Handlers¶
A publisher exposes:
IDelegateHandler<ChannelEventArgs> OnChannelEventFired { get; }
You can register one or more handlers.
publisher.OnChannelEventFired.Add(
async (sender, args) =>
{
var eventText = args.ToString();
Console.WriteLine(
$"channel event: {DateTime.UtcNow:u}, {eventText}");
await Task.CompletedTask;
});
EventTag¶
ChannelEventArgs.EventTag identifies the channel event raised by the RabbitMQ client.
Common event tags include:
| EventTag | Description |
|---|---|
FlowControl |
RabbitMQ changed the channel flow-control state. |
CallbackException |
RabbitMQ raised a callback exception on the channel. |
ModelShutdown |
The channel/model was shut down. |
Multiple Handlers¶
Multiple handlers can be registered.
publisher.OnChannelEventFired.Add(
async (sender, args) =>
{
Console.WriteLine(args.EventTag);
await Task.CompletedTask;
});
publisher.OnChannelEventFired.Add(
async (sender, args) =>
{
// Send the event to telemetry or monitoring.
await Task.CompletedTask;
});
Handler Errors¶
If a channel event handler throws an exception, the exception belongs to the handler logic.
Keep handlers lightweight and resilient.
publisher.OnChannelEventFired.Add(
async (sender, args) =>
{
try
{
Console.WriteLine(args.ToString());
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
await Task.CompletedTask;
});
When To Use¶
Publisher channel events are useful for:
- diagnostics;
- observability;
- broker troubleshooting;
- monitoring flow-control events;
- detecting channel shutdowns.
Difference From Delivery Confirmation¶
Channel events are not the same as publisher confirmations.
| Feature | Purpose |
|---|---|
| Delivery confirmation | Confirms whether RabbitMQ accepted a published message. |
| Channel events | Exposes channel-level events raised by RabbitMQ.Client. |
Use delivery confirmation for publish reliability.
Use channel events for observability and diagnostics.