From ea01635bbdc39bf3678f9ce3ad2a71ec3bf50e86 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Thu, 7 Mar 2024 15:46:23 +0100 Subject: [PATCH 1/7] Add redirects --- nservicebus/recoverability/custom-recoverability-policy.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nservicebus/recoverability/custom-recoverability-policy.md b/nservicebus/recoverability/custom-recoverability-policy.md index 95e65e84852..3b373305b8e 100644 --- a/nservicebus/recoverability/custom-recoverability-policy.md +++ b/nservicebus/recoverability/custom-recoverability-policy.md @@ -8,6 +8,9 @@ related: - samples/faulttolerance - samples/custom-recoverability - samples/recoverabilitypolicytesting +redirects: + - samples/message-error-handling + - nservicebus/pipeline/customizing-error-handling --- From 1f8a15ab115f7f59e91850350feeda7b5ea84c16 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Thu, 7 Mar 2024 15:47:33 +0100 Subject: [PATCH 2/7] Remove the message error handling sample In favor of a redirect to custom recoverability policies --- .../CustomErrorHandling.csproj | 10 --- .../CustomErrorHandlingBehavior.cs | 40 ------------ .../CustomErrorHandling/MyCustomException.cs | 25 -------- .../Core_7/CustomErrorHandling/MyMessage.cs | 9 --- .../CustomErrorHandling/MyMessageHandler.cs | 17 ------ .../Core_7/CustomErrorHandling/Program.cs | 60 ------------------ .../Core_7/ErrorHandling.sln | 25 -------- .../PlatformLauncher/PlatformLauncher.csproj | 10 --- .../Core_7/PlatformLauncher/Program.cs | 15 ----- .../CustomErrorHandling.csproj | 10 --- .../CustomErrorHandlingBehavior.cs | 40 ------------ .../CustomErrorHandling/MyCustomException.cs | 25 -------- .../Core_8/CustomErrorHandling/MyMessage.cs | 9 --- .../CustomErrorHandling/MyMessageHandler.cs | 17 ------ .../Core_8/CustomErrorHandling/Program.cs | 61 ------------------- .../Core_8/ErrorHandling.sln | 25 -------- .../PlatformLauncher/PlatformLauncher.csproj | 10 --- .../Core_8/PlatformLauncher/Program.cs | 15 ----- .../CustomErrorHandling.csproj | 10 --- .../CustomErrorHandlingBehavior.cs | 40 ------------ .../CustomErrorHandling/MyCustomException.cs | 19 ------ .../Core_9/CustomErrorHandling/MyMessage.cs | 9 --- .../CustomErrorHandling/MyMessageHandler.cs | 17 ------ .../Core_9/CustomErrorHandling/Program.cs | 61 ------------------- .../Core_9/ErrorHandling.sln | 25 -------- .../PlatformLauncher/PlatformLauncher.csproj | 10 --- .../Core_9/PlatformLauncher/Program.cs | 13 ---- .../Core_9/prerelease.txt | 0 samples/message-error-handling/sample.md | 23 ------- 29 files changed, 650 deletions(-) delete mode 100644 samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandling.csproj delete mode 100644 samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandlingBehavior.cs delete mode 100644 samples/message-error-handling/Core_7/CustomErrorHandling/MyCustomException.cs delete mode 100644 samples/message-error-handling/Core_7/CustomErrorHandling/MyMessage.cs delete mode 100644 samples/message-error-handling/Core_7/CustomErrorHandling/MyMessageHandler.cs delete mode 100644 samples/message-error-handling/Core_7/CustomErrorHandling/Program.cs delete mode 100644 samples/message-error-handling/Core_7/ErrorHandling.sln delete mode 100644 samples/message-error-handling/Core_7/PlatformLauncher/PlatformLauncher.csproj delete mode 100644 samples/message-error-handling/Core_7/PlatformLauncher/Program.cs delete mode 100644 samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandling.csproj delete mode 100644 samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandlingBehavior.cs delete mode 100644 samples/message-error-handling/Core_8/CustomErrorHandling/MyCustomException.cs delete mode 100644 samples/message-error-handling/Core_8/CustomErrorHandling/MyMessage.cs delete mode 100644 samples/message-error-handling/Core_8/CustomErrorHandling/MyMessageHandler.cs delete mode 100644 samples/message-error-handling/Core_8/CustomErrorHandling/Program.cs delete mode 100644 samples/message-error-handling/Core_8/ErrorHandling.sln delete mode 100644 samples/message-error-handling/Core_8/PlatformLauncher/PlatformLauncher.csproj delete mode 100644 samples/message-error-handling/Core_8/PlatformLauncher/Program.cs delete mode 100644 samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandling.csproj delete mode 100644 samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandlingBehavior.cs delete mode 100644 samples/message-error-handling/Core_9/CustomErrorHandling/MyCustomException.cs delete mode 100644 samples/message-error-handling/Core_9/CustomErrorHandling/MyMessage.cs delete mode 100644 samples/message-error-handling/Core_9/CustomErrorHandling/MyMessageHandler.cs delete mode 100644 samples/message-error-handling/Core_9/CustomErrorHandling/Program.cs delete mode 100644 samples/message-error-handling/Core_9/ErrorHandling.sln delete mode 100644 samples/message-error-handling/Core_9/PlatformLauncher/PlatformLauncher.csproj delete mode 100644 samples/message-error-handling/Core_9/PlatformLauncher/Program.cs delete mode 100644 samples/message-error-handling/Core_9/prerelease.txt delete mode 100644 samples/message-error-handling/sample.md diff --git a/samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandling.csproj b/samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandling.csproj deleted file mode 100644 index feb63a2a205..00000000000 --- a/samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandling.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - net7.0;net6.0;net48 - Exe - 10.0 - - - - - \ No newline at end of file diff --git a/samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandlingBehavior.cs b/samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandlingBehavior.cs deleted file mode 100644 index b3c4881dfc8..00000000000 --- a/samples/message-error-handling/Core_7/CustomErrorHandling/CustomErrorHandlingBehavior.cs +++ /dev/null @@ -1,40 +0,0 @@ - -using System; -using System.Threading.Tasks; -using NServiceBus; -using NServiceBus.Logging; -using NServiceBus.Pipeline; - -public class CustomErrorHandlingBehavior : - Behavior -{ - static ILog Log = LogManager.GetLogger(typeof(CustomErrorHandlingBehavior)); - - #region MoveToErrorQueue - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - try - { - await next() - .ConfigureAwait(false); - } - catch (MyCustomException) - { - // Ignore the exception, avoid doing this in a production code base - Log.WarnFormat("MyCustomException was thrown. Ignoring the error for message Id {0}.", context.Message.MessageId); - } - catch (MessageDeserializationException deserializationException) - { - // Custom processing that needs to occur when a serialization failure occurs. - Log.Error("Message deserialization failed", deserializationException); - throw; - } - catch (Exception ex) - { - //Throwing will eventually send the message to the error queue - Log.Error("Message failed.", ex); - throw; - } - } - #endregion -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_7/CustomErrorHandling/MyCustomException.cs b/samples/message-error-handling/Core_7/CustomErrorHandling/MyCustomException.cs deleted file mode 100644 index f6748965e10..00000000000 --- a/samples/message-error-handling/Core_7/CustomErrorHandling/MyCustomException.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Runtime.Serialization; - -public class MyCustomException : - Exception -{ - public MyCustomException() - { - } - - public MyCustomException(string message) : - base(message) - { - } - - public MyCustomException(string message, Exception innerException) : - base(message, innerException) - { - } - - protected MyCustomException(SerializationInfo info, StreamingContext context) : - base(info, context) - { - } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_7/CustomErrorHandling/MyMessage.cs b/samples/message-error-handling/Core_7/CustomErrorHandling/MyMessage.cs deleted file mode 100644 index 71cadabf5fc..00000000000 --- a/samples/message-error-handling/Core_7/CustomErrorHandling/MyMessage.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; -using NServiceBus; - -public class MyMessage : - ICommand -{ - public Guid Id { get; set; } - public bool ThrowCustomException { get; set; } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_7/CustomErrorHandling/MyMessageHandler.cs b/samples/message-error-handling/Core_7/CustomErrorHandling/MyMessageHandler.cs deleted file mode 100644 index 80edba81461..00000000000 --- a/samples/message-error-handling/Core_7/CustomErrorHandling/MyMessageHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Threading.Tasks; -using NServiceBus; - -public class MyMessageHandler : - IHandleMessages -{ - public Task Handle(MyMessage message, IMessageHandlerContext context) - { - if (message.ThrowCustomException) - { - throw new MyCustomException(); - } - - throw new Exception("An exception occurred in the handler."); - } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_7/CustomErrorHandling/Program.cs b/samples/message-error-handling/Core_7/CustomErrorHandling/Program.cs deleted file mode 100644 index 6de1c80061e..00000000000 --- a/samples/message-error-handling/Core_7/CustomErrorHandling/Program.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Threading.Tasks; -using NServiceBus; -using NServiceBus.Logging; - -static class Program -{ - static async Task Main() - { - Console.Title = "Samples.CustomErrorHandling"; - LogManager.Use() - .Level(LogLevel.Warn); - - var endpointConfiguration = new EndpointConfiguration("Samples.CustomErrorHandling"); - endpointConfiguration.UsePersistence(); - endpointConfiguration.UseTransport(); - - var recoverability = endpointConfiguration.Recoverability(); - recoverability.Delayed( - customizations: delayedRetriesSettings => - { - delayedRetriesSettings.NumberOfRetries(0); - }); - - #region Registering-Behavior - - var pipeline = endpointConfiguration.Pipeline; - pipeline.Register( - behavior: new CustomErrorHandlingBehavior(), - description: "Manages thrown exceptions instead of delayed retries."); - - #endregion - - var endpointInstance = await Endpoint.Start(endpointConfiguration) - .ConfigureAwait(false); - Console.WriteLine("Press enter to send a message that will throw an exception or \r\n" + - "Press [E] key to send a message failing with the custom exception."); - Console.WriteLine("Press [ESC] key to exit"); - - while (true) - { - var input = Console.ReadKey(); - - var myMessage = new MyMessage - { - Id = Guid.NewGuid(), - ThrowCustomException = input.Key == ConsoleKey.E - }; - - if (input.Key == ConsoleKey.Escape) - { - break; - } - await endpointInstance.SendLocal(myMessage) - .ConfigureAwait(false); - } - await endpointInstance.Stop() - .ConfigureAwait(false); - } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_7/ErrorHandling.sln b/samples/message-error-handling/Core_7/ErrorHandling.sln deleted file mode 100644 index 766c1baab9c..00000000000 --- a/samples/message-error-handling/Core_7/ErrorHandling.sln +++ /dev/null @@ -1,25 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29728.190 -MinimumVisualStudioVersion = 15.0.26730.12 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomErrorHandling", "CustomErrorHandling\CustomErrorHandling.csproj", "{43CB6673-3AF0-4D97-AD9F-EB1B9403C768}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlatformLauncher", "PlatformLauncher\PlatformLauncher.csproj", "{4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {43CB6673-3AF0-4D97-AD9F-EB1B9403C768}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {43CB6673-3AF0-4D97-AD9F-EB1B9403C768}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}.Debug|Any CPU.Build.0 = Debug|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {68AC7E9D-56CF-4811-A21A-42E36D31419B} - EndGlobalSection -EndGlobal diff --git a/samples/message-error-handling/Core_7/PlatformLauncher/PlatformLauncher.csproj b/samples/message-error-handling/Core_7/PlatformLauncher/PlatformLauncher.csproj deleted file mode 100644 index 6602d2323fc..00000000000 --- a/samples/message-error-handling/Core_7/PlatformLauncher/PlatformLauncher.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - net7.0;net6.0;net48 - Exe - 10.0 - - - - - \ No newline at end of file diff --git a/samples/message-error-handling/Core_7/PlatformLauncher/Program.cs b/samples/message-error-handling/Core_7/PlatformLauncher/Program.cs deleted file mode 100644 index 3e5fb492b52..00000000000 --- a/samples/message-error-handling/Core_7/PlatformLauncher/Program.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace PlatformLauncher -{ - using System; - using System.Threading.Tasks; - - class Program - { - static async Task Main(string[] args) - { - Console.Title = "PlatformLauncher"; - await Particular.PlatformLauncher.Launch() - .ConfigureAwait(false); - } - } -} diff --git a/samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandling.csproj b/samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandling.csproj deleted file mode 100644 index 1784328f7b6..00000000000 --- a/samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandling.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - net7.0;net6.0;net48 - Exe - 10.0 - - - - - \ No newline at end of file diff --git a/samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandlingBehavior.cs b/samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandlingBehavior.cs deleted file mode 100644 index b3c4881dfc8..00000000000 --- a/samples/message-error-handling/Core_8/CustomErrorHandling/CustomErrorHandlingBehavior.cs +++ /dev/null @@ -1,40 +0,0 @@ - -using System; -using System.Threading.Tasks; -using NServiceBus; -using NServiceBus.Logging; -using NServiceBus.Pipeline; - -public class CustomErrorHandlingBehavior : - Behavior -{ - static ILog Log = LogManager.GetLogger(typeof(CustomErrorHandlingBehavior)); - - #region MoveToErrorQueue - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - try - { - await next() - .ConfigureAwait(false); - } - catch (MyCustomException) - { - // Ignore the exception, avoid doing this in a production code base - Log.WarnFormat("MyCustomException was thrown. Ignoring the error for message Id {0}.", context.Message.MessageId); - } - catch (MessageDeserializationException deserializationException) - { - // Custom processing that needs to occur when a serialization failure occurs. - Log.Error("Message deserialization failed", deserializationException); - throw; - } - catch (Exception ex) - { - //Throwing will eventually send the message to the error queue - Log.Error("Message failed.", ex); - throw; - } - } - #endregion -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_8/CustomErrorHandling/MyCustomException.cs b/samples/message-error-handling/Core_8/CustomErrorHandling/MyCustomException.cs deleted file mode 100644 index f6748965e10..00000000000 --- a/samples/message-error-handling/Core_8/CustomErrorHandling/MyCustomException.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Runtime.Serialization; - -public class MyCustomException : - Exception -{ - public MyCustomException() - { - } - - public MyCustomException(string message) : - base(message) - { - } - - public MyCustomException(string message, Exception innerException) : - base(message, innerException) - { - } - - protected MyCustomException(SerializationInfo info, StreamingContext context) : - base(info, context) - { - } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_8/CustomErrorHandling/MyMessage.cs b/samples/message-error-handling/Core_8/CustomErrorHandling/MyMessage.cs deleted file mode 100644 index 71cadabf5fc..00000000000 --- a/samples/message-error-handling/Core_8/CustomErrorHandling/MyMessage.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; -using NServiceBus; - -public class MyMessage : - ICommand -{ - public Guid Id { get; set; } - public bool ThrowCustomException { get; set; } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_8/CustomErrorHandling/MyMessageHandler.cs b/samples/message-error-handling/Core_8/CustomErrorHandling/MyMessageHandler.cs deleted file mode 100644 index 80edba81461..00000000000 --- a/samples/message-error-handling/Core_8/CustomErrorHandling/MyMessageHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Threading.Tasks; -using NServiceBus; - -public class MyMessageHandler : - IHandleMessages -{ - public Task Handle(MyMessage message, IMessageHandlerContext context) - { - if (message.ThrowCustomException) - { - throw new MyCustomException(); - } - - throw new Exception("An exception occurred in the handler."); - } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_8/CustomErrorHandling/Program.cs b/samples/message-error-handling/Core_8/CustomErrorHandling/Program.cs deleted file mode 100644 index a5df6dece9d..00000000000 --- a/samples/message-error-handling/Core_8/CustomErrorHandling/Program.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Threading.Tasks; -using NServiceBus; -using NServiceBus.Logging; - -static class Program -{ - static async Task Main() - { - Console.Title = "Samples.CustomErrorHandling"; - LogManager.Use() - .Level(LogLevel.Warn); - - var endpointConfiguration = new EndpointConfiguration("Samples.CustomErrorHandling"); - endpointConfiguration.UsePersistence(); - endpointConfiguration.UseSerialization(); - endpointConfiguration.UseTransport(new LearningTransport()); - - var recoverability = endpointConfiguration.Recoverability(); - recoverability.Delayed( - customizations: delayedRetriesSettings => - { - delayedRetriesSettings.NumberOfRetries(0); - }); - - #region Registering-Behavior - - var pipeline = endpointConfiguration.Pipeline; - pipeline.Register( - behavior: new CustomErrorHandlingBehavior(), - description: "Manages thrown exceptions instead of delayed retries."); - - #endregion - - var endpointInstance = await Endpoint.Start(endpointConfiguration) - .ConfigureAwait(false); - Console.WriteLine("Press enter to send a message that will throw an exception or \r\n" + - "Press [E] key to send a message failing with the custom exception."); - Console.WriteLine("Press [ESC] key to exit"); - - while (true) - { - var input = Console.ReadKey(); - - var myMessage = new MyMessage - { - Id = Guid.NewGuid(), - ThrowCustomException = input.Key == ConsoleKey.E - }; - - if (input.Key == ConsoleKey.Escape) - { - break; - } - await endpointInstance.SendLocal(myMessage) - .ConfigureAwait(false); - } - await endpointInstance.Stop() - .ConfigureAwait(false); - } -} diff --git a/samples/message-error-handling/Core_8/ErrorHandling.sln b/samples/message-error-handling/Core_8/ErrorHandling.sln deleted file mode 100644 index 766c1baab9c..00000000000 --- a/samples/message-error-handling/Core_8/ErrorHandling.sln +++ /dev/null @@ -1,25 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29728.190 -MinimumVisualStudioVersion = 15.0.26730.12 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomErrorHandling", "CustomErrorHandling\CustomErrorHandling.csproj", "{43CB6673-3AF0-4D97-AD9F-EB1B9403C768}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlatformLauncher", "PlatformLauncher\PlatformLauncher.csproj", "{4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {43CB6673-3AF0-4D97-AD9F-EB1B9403C768}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {43CB6673-3AF0-4D97-AD9F-EB1B9403C768}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}.Debug|Any CPU.Build.0 = Debug|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {68AC7E9D-56CF-4811-A21A-42E36D31419B} - EndGlobalSection -EndGlobal diff --git a/samples/message-error-handling/Core_8/PlatformLauncher/PlatformLauncher.csproj b/samples/message-error-handling/Core_8/PlatformLauncher/PlatformLauncher.csproj deleted file mode 100644 index 6602d2323fc..00000000000 --- a/samples/message-error-handling/Core_8/PlatformLauncher/PlatformLauncher.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - net7.0;net6.0;net48 - Exe - 10.0 - - - - - \ No newline at end of file diff --git a/samples/message-error-handling/Core_8/PlatformLauncher/Program.cs b/samples/message-error-handling/Core_8/PlatformLauncher/Program.cs deleted file mode 100644 index 3e5fb492b52..00000000000 --- a/samples/message-error-handling/Core_8/PlatformLauncher/Program.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace PlatformLauncher -{ - using System; - using System.Threading.Tasks; - - class Program - { - static async Task Main(string[] args) - { - Console.Title = "PlatformLauncher"; - await Particular.PlatformLauncher.Launch() - .ConfigureAwait(false); - } - } -} diff --git a/samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandling.csproj b/samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandling.csproj deleted file mode 100644 index 9eb76bfd3da..00000000000 --- a/samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandling.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - net8.0 - Exe - 12.0 - - - - - \ No newline at end of file diff --git a/samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandlingBehavior.cs b/samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandlingBehavior.cs deleted file mode 100644 index b3c4881dfc8..00000000000 --- a/samples/message-error-handling/Core_9/CustomErrorHandling/CustomErrorHandlingBehavior.cs +++ /dev/null @@ -1,40 +0,0 @@ - -using System; -using System.Threading.Tasks; -using NServiceBus; -using NServiceBus.Logging; -using NServiceBus.Pipeline; - -public class CustomErrorHandlingBehavior : - Behavior -{ - static ILog Log = LogManager.GetLogger(typeof(CustomErrorHandlingBehavior)); - - #region MoveToErrorQueue - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - try - { - await next() - .ConfigureAwait(false); - } - catch (MyCustomException) - { - // Ignore the exception, avoid doing this in a production code base - Log.WarnFormat("MyCustomException was thrown. Ignoring the error for message Id {0}.", context.Message.MessageId); - } - catch (MessageDeserializationException deserializationException) - { - // Custom processing that needs to occur when a serialization failure occurs. - Log.Error("Message deserialization failed", deserializationException); - throw; - } - catch (Exception ex) - { - //Throwing will eventually send the message to the error queue - Log.Error("Message failed.", ex); - throw; - } - } - #endregion -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_9/CustomErrorHandling/MyCustomException.cs b/samples/message-error-handling/Core_9/CustomErrorHandling/MyCustomException.cs deleted file mode 100644 index cf071554047..00000000000 --- a/samples/message-error-handling/Core_9/CustomErrorHandling/MyCustomException.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -public class MyCustomException : - Exception -{ - public MyCustomException() - { - } - - public MyCustomException(string message) : - base(message) - { - } - - public MyCustomException(string message, Exception innerException) : - base(message, innerException) - { - } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_9/CustomErrorHandling/MyMessage.cs b/samples/message-error-handling/Core_9/CustomErrorHandling/MyMessage.cs deleted file mode 100644 index 71cadabf5fc..00000000000 --- a/samples/message-error-handling/Core_9/CustomErrorHandling/MyMessage.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; -using NServiceBus; - -public class MyMessage : - ICommand -{ - public Guid Id { get; set; } - public bool ThrowCustomException { get; set; } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_9/CustomErrorHandling/MyMessageHandler.cs b/samples/message-error-handling/Core_9/CustomErrorHandling/MyMessageHandler.cs deleted file mode 100644 index 80edba81461..00000000000 --- a/samples/message-error-handling/Core_9/CustomErrorHandling/MyMessageHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Threading.Tasks; -using NServiceBus; - -public class MyMessageHandler : - IHandleMessages -{ - public Task Handle(MyMessage message, IMessageHandlerContext context) - { - if (message.ThrowCustomException) - { - throw new MyCustomException(); - } - - throw new Exception("An exception occurred in the handler."); - } -} \ No newline at end of file diff --git a/samples/message-error-handling/Core_9/CustomErrorHandling/Program.cs b/samples/message-error-handling/Core_9/CustomErrorHandling/Program.cs deleted file mode 100644 index a5df6dece9d..00000000000 --- a/samples/message-error-handling/Core_9/CustomErrorHandling/Program.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Threading.Tasks; -using NServiceBus; -using NServiceBus.Logging; - -static class Program -{ - static async Task Main() - { - Console.Title = "Samples.CustomErrorHandling"; - LogManager.Use() - .Level(LogLevel.Warn); - - var endpointConfiguration = new EndpointConfiguration("Samples.CustomErrorHandling"); - endpointConfiguration.UsePersistence(); - endpointConfiguration.UseSerialization(); - endpointConfiguration.UseTransport(new LearningTransport()); - - var recoverability = endpointConfiguration.Recoverability(); - recoverability.Delayed( - customizations: delayedRetriesSettings => - { - delayedRetriesSettings.NumberOfRetries(0); - }); - - #region Registering-Behavior - - var pipeline = endpointConfiguration.Pipeline; - pipeline.Register( - behavior: new CustomErrorHandlingBehavior(), - description: "Manages thrown exceptions instead of delayed retries."); - - #endregion - - var endpointInstance = await Endpoint.Start(endpointConfiguration) - .ConfigureAwait(false); - Console.WriteLine("Press enter to send a message that will throw an exception or \r\n" + - "Press [E] key to send a message failing with the custom exception."); - Console.WriteLine("Press [ESC] key to exit"); - - while (true) - { - var input = Console.ReadKey(); - - var myMessage = new MyMessage - { - Id = Guid.NewGuid(), - ThrowCustomException = input.Key == ConsoleKey.E - }; - - if (input.Key == ConsoleKey.Escape) - { - break; - } - await endpointInstance.SendLocal(myMessage) - .ConfigureAwait(false); - } - await endpointInstance.Stop() - .ConfigureAwait(false); - } -} diff --git a/samples/message-error-handling/Core_9/ErrorHandling.sln b/samples/message-error-handling/Core_9/ErrorHandling.sln deleted file mode 100644 index 766c1baab9c..00000000000 --- a/samples/message-error-handling/Core_9/ErrorHandling.sln +++ /dev/null @@ -1,25 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29728.190 -MinimumVisualStudioVersion = 15.0.26730.12 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomErrorHandling", "CustomErrorHandling\CustomErrorHandling.csproj", "{43CB6673-3AF0-4D97-AD9F-EB1B9403C768}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlatformLauncher", "PlatformLauncher\PlatformLauncher.csproj", "{4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {43CB6673-3AF0-4D97-AD9F-EB1B9403C768}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {43CB6673-3AF0-4D97-AD9F-EB1B9403C768}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4015F50C-50EC-4172-AEDC-DAC3E4A1D8CA}.Debug|Any CPU.Build.0 = Debug|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {68AC7E9D-56CF-4811-A21A-42E36D31419B} - EndGlobalSection -EndGlobal diff --git a/samples/message-error-handling/Core_9/PlatformLauncher/PlatformLauncher.csproj b/samples/message-error-handling/Core_9/PlatformLauncher/PlatformLauncher.csproj deleted file mode 100644 index 377763f8941..00000000000 --- a/samples/message-error-handling/Core_9/PlatformLauncher/PlatformLauncher.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - net8.0 - Exe - 12.0 - - - - - \ No newline at end of file diff --git a/samples/message-error-handling/Core_9/PlatformLauncher/Program.cs b/samples/message-error-handling/Core_9/PlatformLauncher/Program.cs deleted file mode 100644 index 2501b019cc6..00000000000 --- a/samples/message-error-handling/Core_9/PlatformLauncher/Program.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace PlatformLauncher -{ - using System; - - class Program - { - static void Main(string[] args) - { - Console.Title = "PlatformLauncher"; - Particular.PlatformLauncher.Launch(); - } - } -} diff --git a/samples/message-error-handling/Core_9/prerelease.txt b/samples/message-error-handling/Core_9/prerelease.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/samples/message-error-handling/sample.md b/samples/message-error-handling/sample.md deleted file mode 100644 index bc60487b703..00000000000 --- a/samples/message-error-handling/sample.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: Custom Exception Handling -summary: With custom exception handling, it is possible to fine-tune how exceptions should be handled after they have been retried -reviewed: 2024-02-28 -component: Core -related: - - nservicebus/recoverability - - nservicebus/pipeline/customizing-error-handling ---- - -This sample shows how a message can be either retried, sent to the error queue, or ignored based on the exception type. The portable Particular Service Platform will list the messages arriving in the error queue. - -include: platformlauncher-windows-required - -In Versions 6 and above, the `IManageMessageFailures` is deprecated, and there's no direct way to manage custom exceptions. The Recoverability API allows for a much easier configuration of immediate and delayed retries. However, finer-grain control can be achieved by writing a custom Behavior and executing it as a step in the message-handling pipeline. - -snippet: MoveToErrorQueue - -To register the new exception handler: - -snippet: registering-behavior - -Beware of swallowing exceptions, though, since it is rarely intended, and the message will be removed from the input queue as if it has been processed successfully. From db742f94770a1986ad5f73b533c1345c41dcecb7 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Thu, 7 Mar 2024 15:50:00 +0100 Subject: [PATCH 3/7] Remove custom error handling documentation In favor of a redirect to custom recoverability policies --- .../pipeline/customizing-error-handling.md | 11 ------ ...handling_content_core_[6.0,8.0).partial.md | 37 ------------------- ...or-handling_content_core_[8.0,).partial.md | 29 --------------- 3 files changed, 77 deletions(-) delete mode 100644 nservicebus/pipeline/customizing-error-handling.md delete mode 100644 nservicebus/pipeline/customizing-error-handling_content_core_[6.0,8.0).partial.md delete mode 100644 nservicebus/pipeline/customizing-error-handling_content_core_[8.0,).partial.md diff --git a/nservicebus/pipeline/customizing-error-handling.md b/nservicebus/pipeline/customizing-error-handling.md deleted file mode 100644 index f3c8a55e746..00000000000 --- a/nservicebus/pipeline/customizing-error-handling.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: Customizing Error Handling -summary: Extension point for handling message failures -component: Core -reviewed: 2021-04-09 -related: - - nservicebus/pipeline/manipulate-with-behaviors - - nservicebus/pipeline/features ---- - -partial: content diff --git a/nservicebus/pipeline/customizing-error-handling_content_core_[6.0,8.0).partial.md b/nservicebus/pipeline/customizing-error-handling_content_core_[6.0,8.0).partial.md deleted file mode 100644 index 4cebd197deb..00000000000 --- a/nservicebus/pipeline/customizing-error-handling_content_core_[6.0,8.0).partial.md +++ /dev/null @@ -1,37 +0,0 @@ -Custom exception handling can be implemented using pipeline behaviors. To learn more about pipeline and behaviors refer to the documentation on [how to manipulate the pipeline with behaviors](/nservicebus/pipeline/manipulate-with-behaviors.md). - -NOTE: Behaviors are meant to customize recoverability. For example, how many times and under which conditions a message should be re-tried. To read more about customizing recoverability refer to the [recoverability documentation](/nservicebus/recoverability/). - -### Create a new behavior - -Implement a new behavior, which extends the `ITransportReceiveContext` context interface. This context provides details about the message at the transport level. Calling `next()` in the pipeline will invoke the subsequent pipeline processing steps. - -snippet: ErrorHandlingBehavior - -#### Handling deserialization errors - -To handle deserialization errors, wrap the `next()` operation in a try-catch block and handle the `MessageDeserializationException` as shown: - -snippet: DeserializationCustomization - -WARNING: Throwing a `MessageDeserializationException` exception in the catch block will immediately forward the message to the error queue. A message that fails due to a `MessageDeserializationException` will not be retried. If the message must be consumed and removed from the queue, remove the `throw` from the catch block to indicate that the message has been successfully processed. - -#### Handling other errors - -To handle other errors, wrap the `next()` operation in a try-catch block and handle the `Exception` as shown: - -snippet: AllErrorsCustomization - -WARNING: Throwing the exception in the catch block will forward the message to the error queue after all the configured retry attempts. If the message must be consumed and removed from the queue then remove the `throw` from the catch block to indicate that the message has been successfully processed. - -#### Rolling back - -To rollback the receive operation instead of handling the message or to forward it to the error queue, invoke `AbortReceiveOperation` as shown below: - -snippet: RollbackMessage - -### Registering the behavior - -In the example below, the behavior `CustomErrorHandlingBehavior` is registered to be part of the message handling pipeline. This new behavior is placed at the very beginning of the pipeline. This placement allows inserting code right after a message has been received from the transport and right before the [recoverability](/nservicebus/recoverability/) policy is invoked. - -snippet: RegisterCustomErrorHandlingBehavior diff --git a/nservicebus/pipeline/customizing-error-handling_content_core_[8.0,).partial.md b/nservicebus/pipeline/customizing-error-handling_content_core_[8.0,).partial.md deleted file mode 100644 index fa7e65f99dc..00000000000 --- a/nservicebus/pipeline/customizing-error-handling_content_core_[8.0,).partial.md +++ /dev/null @@ -1,29 +0,0 @@ -Custom exception handling can be implemented using pipeline behaviors. To learn more about pipeline and behaviors refer to the documentation on [how to manipulate the pipeline with behaviors](/nservicebus/pipeline/manipulate-with-behaviors.md). - -### Create a new behavior - -Implement a new behavior, which extends the `ITransportReceiveContext` context interface. This context provides details about the message at the transport level. Calling `next()` in the pipeline will invoke the subsequent pipeline processing steps. - -snippet: ErrorHandlingBehavior - -#### Handling deserialization errors - -To handle any deserialization errors, wrap the `next()` operation in a try-catch block and handle the `MessageDeserializationException` as shown: - -snippet: DeserializationCustomization - -WARNING: Throwing a `MessageDeserializationException` exception in the catch block will immediately forward the message to the error queue. A message that fails due to a `MessageDeserializationException` will not be retried. If the message must be consumed and removed from the queue, remove the `throw` from the catch block to indicate that the message has been successfully processed. - -#### Handling other errors - -To handle other errors, wrap the `next()` operation in a try-catch block and handle the `Exception` as shown: - -snippet: AllErrorsCustomization - -WARNING: Throwing the exception in the catch block will forward the message to the error queue after all the configured retry attempts. If the message must be consumed and removed from the queue then remove the `throw` from the catch block to indicate that the message has been successfully processed. - -### Registering the behavior - -In the example below, the behavior `CustomErrorHandlingBehavior` is registered to be part of the message handling pipeline. This new behavior is placed at the very beginning of the pipeline. This placement allows inserting code right after a message has been received from the transport and right before the [recoverability](/nservicebus/recoverability/) policy is invoked. - -snippet: RegisterCustomErrorHandlingBehavior From 50c588edb1e433614b47c0ae2295298b179013b5 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Thu, 7 Mar 2024 16:06:12 +0100 Subject: [PATCH 4/7] Remove menu entry --- menu/menu.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/menu/menu.yaml b/menu/menu.yaml index 90f175b0dae..737fc161a63 100644 --- a/menu/menu.yaml +++ b/menu/menu.yaml @@ -627,8 +627,6 @@ Title: Subscribing to notification events - Url: nservicebus/pipeline/features Title: Features - - Url: nservicebus/pipeline/customizing-error-handling - Title: Customizing Error Handling - Url: nservicebus/satellites Title: Satellites - Title: Serialization From 0a2fcb1061ae62468be9633a13bffe05c515c843 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Thu, 7 Mar 2024 16:13:30 +0100 Subject: [PATCH 5/7] Fix link in upgrade guide --- nservicebus/upgrades/5to6/recoverability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nservicebus/upgrades/5to6/recoverability.md b/nservicebus/upgrades/5to6/recoverability.md index 6b0155eb195..50ec8f9a99d 100644 --- a/nservicebus/upgrades/5to6/recoverability.md +++ b/nservicebus/upgrades/5to6/recoverability.md @@ -243,7 +243,7 @@ In NServiceBus version 6, the only reason that the `.Retries` queue exists is so The `IManageMessageFailures` interface was the extension point to customize the handling of second level retries before a message failure is forwarded to the error queue. -This same functionality and more can be achieved using the [message processing pipeline](/nservicebus/pipeline/). See also: [Customizing error handling with the pipeline](/nservicebus/pipeline/customizing-error-handling.md). +This same functionality and more can be achieved using the [message processing pipeline](/nservicebus/pipeline/). See also: [Customizing error handling with with custom retry policies](/nservicebus/recoverability/custom-recoverability-policy.md). ## RepeatedFailuresOverTimeCircuitBreaker has been made internal From 8cd78e76d30eb6e30c7bc856a1a8292038b6cd00 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Thu, 7 Mar 2024 17:00:50 +0100 Subject: [PATCH 6/7] Remove not anymore used snippets --- .../Pipeline/CustomErrorHandlingBehavior.cs | 116 ------------------ .../Pipeline/CustomErrorHandlingBehavior.cs | 93 -------------- .../Pipeline/CustomErrorHandlingBehavior.cs | 93 -------------- 3 files changed, 302 deletions(-) delete mode 100644 Snippets/Core/Core_7/Pipeline/CustomErrorHandlingBehavior.cs delete mode 100644 Snippets/Core/Core_8/Pipeline/CustomErrorHandlingBehavior.cs delete mode 100644 Snippets/Core/Core_9/Pipeline/CustomErrorHandlingBehavior.cs diff --git a/Snippets/Core/Core_7/Pipeline/CustomErrorHandlingBehavior.cs b/Snippets/Core/Core_7/Pipeline/CustomErrorHandlingBehavior.cs deleted file mode 100644 index 0a257c59ece..00000000000 --- a/Snippets/Core/Core_7/Pipeline/CustomErrorHandlingBehavior.cs +++ /dev/null @@ -1,116 +0,0 @@ -namespace Core7.Pipeline -{ - using System; - using System.Threading.Tasks; - using NServiceBus; - using NServiceBus.Logging; - using NServiceBus.Pipeline; - - #region ErrorHandlingBehavior - - class CustomErrorHandlingBehavior : - Behavior - { - public override Task Invoke(ITransportReceiveContext context, Func next) - { - return next(); - } - } - - #endregion - - class CustomErrorHandlingBehaviorForDeserializationFailures : - Behavior - { - static ILog log = LogManager.GetLogger(); - - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - #region DeserializationCustomization - - try - { - await next() - .ConfigureAwait(false); - } - catch (MessageDeserializationException deserializationException) - { - // Custom processing that needs to occur when a serialization failure occurs. - log.Error("Message deserialization failed", deserializationException); - throw; - } - - #endregion - } - } - - class CustomErrorHandlingBehaviorForAllFailures : - Behavior - { - static ILog log = LogManager.GetLogger(); - - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - #region AllErrorsCustomization - - try - { - await next() - .ConfigureAwait(false); - } - catch (Exception exception) - { - // Custom processing that need to occur when a message always fails. - log.Error("Message processing failed", exception); - throw; - } - - #endregion - } - } - - class CustomErrorHandlingBehaviorRollbackOnFailures : - Behavior - { - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - #region RollbackMessage - - try - { - await next() - .ConfigureAwait(false); - } - catch (Exception) - { - // Custom processing that need to occur when a message always fails. - // To rollback the receive operation instead of mark as processed: - context.AbortReceiveOperation(); - } - - #endregion - } - } - - #region RegisterCustomErrorHandlingBehavior - - class NewMessageProcessingPipelineStep : - RegisterStep - { - public NewMessageProcessingPipelineStep() - : base( - stepId: "CustomErrorHandlingBehavior", - behavior: typeof(CustomErrorHandlingBehavior), - description: "Adds custom error behavior to pipeline") - { - // Within a stage it is sometimes necessary to configure a specific - // step order. This can be achieved by invoking one of the following methods: - // - InsertAfter, - // - InsertAfterIfExists, - // - InsertBefore, - // - InsertBeforeIfExists - } - } - - #endregion -} diff --git a/Snippets/Core/Core_8/Pipeline/CustomErrorHandlingBehavior.cs b/Snippets/Core/Core_8/Pipeline/CustomErrorHandlingBehavior.cs deleted file mode 100644 index 9f1bc9a6f77..00000000000 --- a/Snippets/Core/Core_8/Pipeline/CustomErrorHandlingBehavior.cs +++ /dev/null @@ -1,93 +0,0 @@ -namespace Core8.Pipeline -{ - using System; - using System.Threading.Tasks; - using NServiceBus; - using NServiceBus.Logging; - using NServiceBus.Pipeline; - - #region ErrorHandlingBehavior - - class CustomErrorHandlingBehavior : - Behavior - { - public override Task Invoke(ITransportReceiveContext context, Func next) - { - return next(); - } - } - - #endregion - - class CustomErrorHandlingBehaviorForDeserializationFailures : - Behavior - { - static ILog log = LogManager.GetLogger(); - - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - #region DeserializationCustomization - - try - { - await next() - .ConfigureAwait(false); - } - catch (MessageDeserializationException deserializationException) - { - // Custom processing that needs to occur when a serialization failure occurs. - log.Error("Message deserialization failed", deserializationException); - throw; - } - - #endregion - } - } - - class CustomErrorHandlingBehaviorForAllFailures : - Behavior - { - static ILog log = LogManager.GetLogger(); - - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - #region AllErrorsCustomization - - try - { - await next() - .ConfigureAwait(false); - } - catch (Exception exception) - { - // Custom processing that need to occur when a message always fails. - log.Error("Message processing failed", exception); - throw; - } - - #endregion - } - } - - #region RegisterCustomErrorHandlingBehavior - - class NewMessageProcessingPipelineStep : - RegisterStep - { - public NewMessageProcessingPipelineStep() - : base( - stepId: "CustomErrorHandlingBehavior", - behavior: typeof(CustomErrorHandlingBehavior), - description: "Adds custom error behavior to pipeline") - { - // Within a stage it is sometimes necessary to configure a specific - // step order. This can be achieved by invoking on of the following methods: - // - InsertAfter, - // - InsertAfterIfExists, - // - InsertBefore, - // - InsertBeforeIfExists - } - } - - #endregion -} diff --git a/Snippets/Core/Core_9/Pipeline/CustomErrorHandlingBehavior.cs b/Snippets/Core/Core_9/Pipeline/CustomErrorHandlingBehavior.cs deleted file mode 100644 index d388a1bbce1..00000000000 --- a/Snippets/Core/Core_9/Pipeline/CustomErrorHandlingBehavior.cs +++ /dev/null @@ -1,93 +0,0 @@ -namespace Core9.Pipeline -{ - using System; - using System.Threading.Tasks; - using NServiceBus; - using NServiceBus.Logging; - using NServiceBus.Pipeline; - - #region ErrorHandlingBehavior - - class CustomErrorHandlingBehavior : - Behavior - { - public override Task Invoke(ITransportReceiveContext context, Func next) - { - return next(); - } - } - - #endregion - - class CustomErrorHandlingBehaviorForDeserializationFailures : - Behavior - { - static ILog log = LogManager.GetLogger(); - - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - #region DeserializationCustomization - - try - { - await next() - .ConfigureAwait(false); - } - catch (MessageDeserializationException deserializationException) - { - // Custom processing that needs to occur when a serialization failure occurs. - log.Error("Message deserialization failed", deserializationException); - throw; - } - - #endregion - } - } - - class CustomErrorHandlingBehaviorForAllFailures : - Behavior - { - static ILog log = LogManager.GetLogger(); - - public override async Task Invoke(ITransportReceiveContext context, Func next) - { - #region AllErrorsCustomization - - try - { - await next() - .ConfigureAwait(false); - } - catch (Exception exception) - { - // Custom processing that need to occur when a message always fails. - log.Error("Message processing failed", exception); - throw; - } - - #endregion - } - } - - #region RegisterCustomErrorHandlingBehavior - - class NewMessageProcessingPipelineStep : - RegisterStep - { - public NewMessageProcessingPipelineStep() - : base( - stepId: "CustomErrorHandlingBehavior", - behavior: typeof(CustomErrorHandlingBehavior), - description: "Adds custom error behavior to pipeline") - { - // Within a stage it is sometimes necessary to configure a specific - // step order. This can be achieved by invoking on of the following methods: - // - InsertAfter, - // - InsertAfterIfExists, - // - InsertBefore, - // - InsertBeforeIfExists - } - } - - #endregion -} From ae19d730adb443f461c1a863758724d45bd6abb4 Mon Sep 17 00:00:00 2001 From: Daniel Marbach Date: Mon, 11 Mar 2024 10:14:12 +0100 Subject: [PATCH 7/7] Update nservicebus/upgrades/5to6/recoverability.md --- nservicebus/upgrades/5to6/recoverability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nservicebus/upgrades/5to6/recoverability.md b/nservicebus/upgrades/5to6/recoverability.md index 50ec8f9a99d..833e2fe7a9f 100644 --- a/nservicebus/upgrades/5to6/recoverability.md +++ b/nservicebus/upgrades/5to6/recoverability.md @@ -243,7 +243,7 @@ In NServiceBus version 6, the only reason that the `.Retries` queue exists is so The `IManageMessageFailures` interface was the extension point to customize the handling of second level retries before a message failure is forwarded to the error queue. -This same functionality and more can be achieved using the [message processing pipeline](/nservicebus/pipeline/). See also: [Customizing error handling with with custom retry policies](/nservicebus/recoverability/custom-recoverability-policy.md). +This same functionality and more can be achieved using the [message processing pipeline](/nservicebus/pipeline/). See also: [Customizing error handling with custom retry policies](/nservicebus/recoverability/custom-recoverability-policy.md). ## RepeatedFailuresOverTimeCircuitBreaker has been made internal