From e83645cdc4b10ee070fa78b1783aaf3cbcb789b1 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 5 Sep 2021 10:03:29 +0200 Subject: [PATCH 1/2] Changed IExceptionStrategy to async --- Tapeti/Connection/TapetiConsumer.cs | 9 +++++---- Tapeti/Default/NackExceptionStrategy.cs | 6 ++++-- Tapeti/Default/RequeueExceptionStrategy.cs | 6 ++++-- Tapeti/IExceptionStrategy.cs | 5 +++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Tapeti/Connection/TapetiConsumer.cs b/Tapeti/Connection/TapetiConsumer.cs index 58fddeb..6d67241 100644 --- a/Tapeti/Connection/TapetiConsumer.cs +++ b/Tapeti/Connection/TapetiConsumer.cs @@ -78,7 +78,8 @@ namespace Tapeti.Connection }; var exceptionContext = new ExceptionStrategyContext(emptyContext, dispatchException); - HandleException(exceptionContext); + await HandleException(exceptionContext); + return exceptionContext.ConsumeResult; } } @@ -132,7 +133,7 @@ namespace Tapeti.Connection catch (Exception invokeException) { var exceptionContext = new ExceptionStrategyContext(context, invokeException); - HandleException(exceptionContext); + await HandleException(exceptionContext); await binding.Cleanup(context, exceptionContext.ConsumeResult); return exceptionContext.ConsumeResult; @@ -140,7 +141,7 @@ namespace Tapeti.Connection } - private void HandleException(ExceptionStrategyContext exceptionContext) + private async Task HandleException(ExceptionStrategyContext exceptionContext) { if (cancellationToken.IsCancellationRequested && IgnoreExceptionDuringShutdown(exceptionContext.Exception)) { @@ -151,7 +152,7 @@ namespace Tapeti.Connection try { - exceptionStrategy.HandleException(exceptionContext); + await exceptionStrategy.HandleException(exceptionContext); } catch (Exception strategyException) { diff --git a/Tapeti/Default/NackExceptionStrategy.cs b/Tapeti/Default/NackExceptionStrategy.cs index 06510f2..e760e20 100644 --- a/Tapeti/Default/NackExceptionStrategy.cs +++ b/Tapeti/Default/NackExceptionStrategy.cs @@ -1,4 +1,5 @@ -using Tapeti.Config; +using System.Threading.Tasks; +using Tapeti.Config; namespace Tapeti.Default { @@ -9,9 +10,10 @@ namespace Tapeti.Default public class NackExceptionStrategy : IExceptionStrategy { /// - public void HandleException(IExceptionStrategyContext context) + public Task HandleException(IExceptionStrategyContext context) { context.SetConsumeResult(ConsumeResult.Error); + return Task.CompletedTask; } } } diff --git a/Tapeti/Default/RequeueExceptionStrategy.cs b/Tapeti/Default/RequeueExceptionStrategy.cs index 87fa8a2..f91922b 100644 --- a/Tapeti/Default/RequeueExceptionStrategy.cs +++ b/Tapeti/Default/RequeueExceptionStrategy.cs @@ -1,4 +1,5 @@ -using Tapeti.Config; +using System.Threading.Tasks; +using Tapeti.Config; // ReSharper disable UnusedMember.Global @@ -20,9 +21,10 @@ namespace Tapeti.Default public class RequeueExceptionStrategy : IExceptionStrategy { /// - public void HandleException(IExceptionStrategyContext context) + public Task HandleException(IExceptionStrategyContext context) { context.SetConsumeResult(ConsumeResult.Requeue); + return Task.CompletedTask; } } } diff --git a/Tapeti/IExceptionStrategy.cs b/Tapeti/IExceptionStrategy.cs index 5aeb5e1..b498cf1 100644 --- a/Tapeti/IExceptionStrategy.cs +++ b/Tapeti/IExceptionStrategy.cs @@ -1,4 +1,5 @@ -using Tapeti.Config; +using System.Threading.Tasks; +using Tapeti.Config; namespace Tapeti { @@ -12,6 +13,6 @@ namespace Tapeti /// /// The exception strategy context containing the necessary data including the message context and the thrown exception. /// Also proivdes methods for the exception strategy to indicate how the message should be handled. - void HandleException(IExceptionStrategyContext context); + Task HandleException(IExceptionStrategyContext context); } } From 66a0ec116b02ca965b30af0325eeacc1033a223c Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 5 Sep 2021 10:05:04 +0200 Subject: [PATCH 2/2] Fixed a few code hints --- Tapeti.Cmd/ConsoleHelper/ConsoleWrapper.cs | 2 +- Tapeti.Cmd/Verbs/PurgeVerb.cs | 3 +-- Tapeti.Cmd/Verbs/RemoveQueueVerb.cs | 3 +-- Tapeti.Flow/Default/FlowStore.cs | 2 +- Tapeti.Flow/FlowHelpers/MethodSerializer.cs | 3 +-- Tapeti/Config/IMessageContext.cs | 1 + Tapeti/Default/ConsoleLogger.cs | 5 ++--- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Tapeti.Cmd/ConsoleHelper/ConsoleWrapper.cs b/Tapeti.Cmd/ConsoleHelper/ConsoleWrapper.cs index 05f8541..4f5aaee 100644 --- a/Tapeti.Cmd/ConsoleHelper/ConsoleWrapper.cs +++ b/Tapeti.Cmd/ConsoleHelper/ConsoleWrapper.cs @@ -144,7 +144,7 @@ namespace Tapeti.Cmd.ConsoleHelper public void Confirm(string message) { WriteLine(message); - TryReadKey(false, out var _); + TryReadKey(false, out _); } diff --git a/Tapeti.Cmd/Verbs/PurgeVerb.cs b/Tapeti.Cmd/Verbs/PurgeVerb.cs index bd99cd2..9d7edd2 100644 --- a/Tapeti.Cmd/Verbs/PurgeVerb.cs +++ b/Tapeti.Cmd/Verbs/PurgeVerb.cs @@ -1,5 +1,4 @@ -using System; -using CommandLine; +using CommandLine; using RabbitMQ.Client; using Tapeti.Cmd.ConsoleHelper; diff --git a/Tapeti.Cmd/Verbs/RemoveQueueVerb.cs b/Tapeti.Cmd/Verbs/RemoveQueueVerb.cs index 59066c3..9b7695b 100644 --- a/Tapeti.Cmd/Verbs/RemoveQueueVerb.cs +++ b/Tapeti.Cmd/Verbs/RemoveQueueVerb.cs @@ -1,5 +1,4 @@ -using System; -using CommandLine; +using CommandLine; using RabbitMQ.Client; using RabbitMQ.Client.Exceptions; using Tapeti.Cmd.ConsoleHelper; diff --git a/Tapeti.Flow/Default/FlowStore.cs b/Tapeti.Flow/Default/FlowStore.cs index 2a9a8ad..9f3b508 100644 --- a/Tapeti.Flow/Default/FlowStore.cs +++ b/Tapeti.Flow/Default/FlowStore.cs @@ -30,7 +30,7 @@ namespace Tapeti.Flow.Default private readonly ConcurrentDictionary flowStates = new ConcurrentDictionary(); private readonly ConcurrentDictionary continuationLookup = new ConcurrentDictionary(); private readonly LockCollection locks = new LockCollection(EqualityComparer.Default); - private HashSet validatedMethods = null; + private HashSet validatedMethods; private readonly IFlowRepository repository; private readonly ITapetiConfig config; diff --git a/Tapeti.Flow/FlowHelpers/MethodSerializer.cs b/Tapeti.Flow/FlowHelpers/MethodSerializer.cs index 1784873..9f8b09e 100644 --- a/Tapeti.Flow/FlowHelpers/MethodSerializer.cs +++ b/Tapeti.Flow/FlowHelpers/MethodSerializer.cs @@ -1,5 +1,4 @@ -using System; -using System.Reflection; +using System.Reflection; using System.Text.RegularExpressions; namespace Tapeti.Flow.FlowHelpers diff --git a/Tapeti/Config/IMessageContext.cs b/Tapeti/Config/IMessageContext.cs index e3a0e05..ac6a0e5 100644 --- a/Tapeti/Config/IMessageContext.cs +++ b/Tapeti/Config/IMessageContext.cs @@ -1,6 +1,7 @@ using System; // ReSharper disable UnusedMemberInSuper.Global - public API +// ReSharper disable UnusedMember.Global namespace Tapeti.Config { diff --git a/Tapeti/Default/ConsoleLogger.cs b/Tapeti/Default/ConsoleLogger.cs index d2787f3..ff1f626 100644 --- a/Tapeti/Default/ConsoleLogger.cs +++ b/Tapeti/Default/ConsoleLogger.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Text; using Tapeti.Config; +// ReSharper disable UnusedMember.Global - public API + namespace Tapeti.Default { /// @@ -17,9 +19,6 @@ namespace Tapeti.Default /// public class WithMessageLogging : ConsoleLogger { - /// - public WithMessageLogging() : base() { } - internal override bool IncludeMessageBody() => true; }