diff --git a/Snippets/Bridge/Bridge_5/Configuration.cs b/Snippets/Bridge/Bridge_5/Configuration.cs index fe47e7d71d6..0c8b420f8c1 100644 --- a/Snippets/Bridge/Bridge_5/Configuration.cs +++ b/Snippets/Bridge/Bridge_5/Configuration.cs @@ -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 diff --git a/nservicebus/bridge/configuration.md b/nservicebus/bridge/configuration.md index 22b4683079d..f3f92093769 100644 --- a/nservicebus/bridge/configuration.md +++ b/nservicebus/bridge/configuration.md @@ -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 @@ -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. @@ -157,4 +159,3 @@ partial: monitoring - diff --git a/nservicebus/bridge/configuration_critical-error-action_bridge_[5,).partial.md b/nservicebus/bridge/configuration_critical-error-action_bridge_[5,).partial.md new file mode 100644 index 00000000000..173d8d61391 --- /dev/null +++ b/nservicebus/bridge/configuration_critical-error-action_bridge_[5,).partial.md @@ -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.