Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Snippets/Bridge/Bridge_5/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ await Host.CreateDefaultBuilder()
#endregion
}

public void CriticalErrorAction()
{
var bridgeConfiguration = new BridgeConfiguration();

#region bridge-critical-error-action

bridgeConfiguration.DefineCriticalErrorAction(async (context, cancellationToken) =>
{
var fatalMessage =
$"The following critical error was encountered:{Environment.NewLine}" +
$"{context.Error}{Environment.NewLine}" +
"The bridge is shutting down.";

try
{
await context.Stop(cancellationToken);
}
finally
{
Environment.FailFast(fatalMessage, context.Exception);
}
});

#endregion
}

public async Task EndpointRegistration()
{
#region endpoint-registration
Expand Down
5 changes: 3 additions & 2 deletions nservicebus/bridge/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Bridge configuration options
summary: Configuration options for the messaging bridge.
component: Bridge
reviewed: 2026-05-13
reviewed: 2026-06-01
---

## Hosting
Expand All @@ -15,6 +15,8 @@ The overload that accepts a [`HostBuilderContext`](https://learn.microsoft.com/e

snippet: generic-host-builder-context

partial: critical-error-action

## Registering endpoints

If a logical endpoint communicates with other endpoints that use a different transport, it must be registered with the bridge. Endpoints are registered with the bridge on the transport they run on. The bridge then creates a proxy endpoint on each transport that needs to be bridged.
Expand Down Expand Up @@ -157,4 +159,3 @@ partial: monitoring




Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Critical error handling

A bridge can encounter a [critical error](/nservicebus/hosting/critical-errors.md) when a transport cannot recover from an infrastructure failure. Starting with version 5.1, `DefineCriticalErrorAction` can be used to stop the affected bridge endpoint and terminate the process:

snippet: bridge-critical-error-action

Configure the hosting environment to [restart the terminated process](/nservicebus/hosting/critical-errors.md#how-do-i-deal-with-persistent-critical-errors-terminate-and-restart-the-process). Calling `context.Stop` without terminating the process stops only the bridge endpoint that raised the critical error.
Loading