Skip to content

Commit

Permalink
ability to make a global latch on sending failure acks. Closes GH-1249
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Jan 24, 2025
1 parent f6e6c6d commit 3b7ac85
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Testing/CoreTests/Runtime/MoveToErrorQueueTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
6 changes: 6 additions & 0 deletions src/Testing/CoreTests/WolverineOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Wolverine/ErrorHandling/MoveToErrorQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
4 changes: 4 additions & 0 deletions src/Wolverine/Transports/Sending/InlineSendingAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ private async Task sendWithTracing(Envelope e, CancellationToken cancellationTok
await _sender.SendAsync(e);
_messageLogger.Sent(e);
}
catch (NotSupportedException)
{
// ignore it
}
finally
{
activity?.Stop();
Expand Down
4 changes: 4 additions & 0 deletions src/Wolverine/Transports/Sending/SendingAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ private async Task sendWithExplicitHandlingAsync(Envelope envelope, Cancellation

await MarkSuccessfulAsync(envelope);
}
catch (NotSupportedException)
{
// Ignore it, most likely a failure ack that should not have been sent
}
catch (Exception e)
{
try
Expand Down
6 changes: 6 additions & 0 deletions src/Wolverine/WolverineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public MultipleHandlerBehavior MultipleHandlerBehavior
/// </summary>
public bool EnableRemoteInvocation { get; set; } = true;

/// <summary>
/// Should message failures automatically try to send a failure acknowledgement message back to the
/// original caller. Default is true.
/// </summary>
public bool EnableAutomaticFailureAcks { get; set; } = true;

private void deriveServiceName()
{
if (GetType() == typeof(WolverineOptions))
Expand Down

0 comments on commit 3b7ac85

Please sign in to comment.