From 39d788a0c62c5d4ee45f00218d615284fbf38e29 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Fri, 24 Jan 2025 14:28:56 -0600 Subject: [PATCH] ability to make a global latch on sending failure acks. Closes GH-1249 --- .../CoreTests/Runtime/MoveToErrorQueueTester.cs | 14 ++++++++++++++ src/Testing/CoreTests/WolverineOptionsTests.cs | 6 ++++++ src/Wolverine/ErrorHandling/MoveToErrorQueue.cs | 2 +- src/Wolverine/WolverineOptions.cs | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Testing/CoreTests/Runtime/MoveToErrorQueueTester.cs b/src/Testing/CoreTests/Runtime/MoveToErrorQueueTester.cs index 0ab4e7e0e..5890196cb 100644 --- a/src/Testing/CoreTests/Runtime/MoveToErrorQueueTester.cs +++ b/src/Testing/CoreTests/Runtime/MoveToErrorQueueTester.cs @@ -33,6 +33,20 @@ await theLifecycle ; } + [Fact] + public async Task should_not_send_a_failure_ack_if_wolverine_options_latches_that() + { + theEnvelope.Destination = new Uri("local://foo"); + theRuntime.Options.EnableAutomaticFailureAcks = false; + + await theContinuation.ExecuteAsync(theLifecycle, theRuntime, DateTimeOffset.Now, null); + + await theLifecycle + .DidNotReceive() + .SendFailureAcknowledgementAsync($"Moved message {theEnvelope.Id} to the Error Queue.\n{theException}") + ; + } + [Fact] public async Task should_not_send_a_failure_ack_if_local() { diff --git a/src/Testing/CoreTests/WolverineOptionsTests.cs b/src/Testing/CoreTests/WolverineOptionsTests.cs index 1534897b2..b18c4958e 100644 --- a/src/Testing/CoreTests/WolverineOptionsTests.cs +++ b/src/Testing/CoreTests/WolverineOptionsTests.cs @@ -19,6 +19,12 @@ public class WolverineOptionsTests { private readonly WolverineOptions theSettings = new(); + [Fact] + public void failure_acks_are_enabled_by_default() + { + new WolverineOptions().EnableAutomaticFailureAcks.ShouldBeTrue(); + } + [Fact] public void multiple_handler_behavior_is_classic_mode_by_default() { diff --git a/src/Wolverine/ErrorHandling/MoveToErrorQueue.cs b/src/Wolverine/ErrorHandling/MoveToErrorQueue.cs index b015089ea..a864de071 100644 --- a/src/Wolverine/ErrorHandling/MoveToErrorQueue.cs +++ b/src/Wolverine/ErrorHandling/MoveToErrorQueue.cs @@ -31,7 +31,7 @@ public async ValueTask ExecuteAsync(IEnvelopeLifecycle lifecycle, { // TODO -- at some point, we need a more systematic way of doing this var scheme = lifecycle.Envelope.Destination.Scheme; - if (scheme != TransportConstants.Local && scheme != "external-table") + if (runtime.Options.EnableAutomaticFailureAcks && scheme != TransportConstants.Local && scheme != "external-table") { await lifecycle.SendFailureAcknowledgementAsync( $"Moved message {lifecycle.Envelope!.Id} to the Error Queue.\n{Exception}"); diff --git a/src/Wolverine/WolverineOptions.cs b/src/Wolverine/WolverineOptions.cs index 0be85db28..57d808d4f 100644 --- a/src/Wolverine/WolverineOptions.cs +++ b/src/Wolverine/WolverineOptions.cs @@ -159,6 +159,12 @@ public MultipleHandlerBehavior MultipleHandlerBehavior /// public bool EnableRemoteInvocation { get; set; } = true; + /// + /// Should message failures automatically try to send a failure acknowledgement message back to the + /// original caller. Default is true. + /// + public bool EnableAutomaticFailureAcks { get; set; } = true; + private void deriveServiceName() { if (GetType() == typeof(WolverineOptions))