From 83f9aec85d7b471e3122c41892b7d21a52df9d78 Mon Sep 17 00:00:00 2001 From: Christopher Zell Date: Fri, 26 Feb 2021 20:05:38 +0100 Subject: [PATCH] chore(client): introduce new interface for sendWithRetry * avoids not implemented methods on commands - only commands which implement this interface support send with retry --- .../ICancelWorkflowInstanceCommandStep1.cs | 2 +- Client/Api/Commands/IFinalCommandStep.cs | 21 -------------- .../Commands/IFinalCommandWithRetryStep.cs | 29 +++++++++++++++++++ Client/Impl/Commands/CompleteJobCommand.cs | 5 ---- .../Commands/CreateWorkflowInstanceCommand.cs | 5 ---- ...CreateWorkflowInstanceCommandWithResult.cs | 5 ---- Client/Impl/Commands/DeployWorkflowCommand.cs | 5 ---- Client/Impl/Commands/FailJobCommand.cs | 5 ---- Client/Impl/Commands/PublishMessageCommand.cs | 5 ---- .../Impl/Commands/ResolveIncidentCommand.cs | 5 ---- Client/Impl/Commands/SetVariablesCommand.cs | 5 ---- Client/Impl/Commands/ThrowErrorCommand.cs | 5 ---- .../Impl/Commands/TopologyRequestCommand.cs | 5 ---- Client/Impl/Commands/UpdateRetriesCommand.cs | 5 ---- Client/ZeebeClient.cs | 1 - 15 files changed, 30 insertions(+), 78 deletions(-) create mode 100644 Client/Api/Commands/IFinalCommandWithRetryStep.cs diff --git a/Client/Api/Commands/ICancelWorkflowInstanceCommandStep1.cs b/Client/Api/Commands/ICancelWorkflowInstanceCommandStep1.cs index 57fd7bb4..5783f54b 100644 --- a/Client/Api/Commands/ICancelWorkflowInstanceCommandStep1.cs +++ b/Client/Api/Commands/ICancelWorkflowInstanceCommandStep1.cs @@ -2,7 +2,7 @@ namespace Zeebe.Client.Api.Commands { - public interface ICancelWorkflowInstanceCommandStep1 : IFinalCommandStep + public interface ICancelWorkflowInstanceCommandStep1 : IFinalCommandWithRetryStep { // the place for new optional parameters } diff --git a/Client/Api/Commands/IFinalCommandStep.cs b/Client/Api/Commands/IFinalCommandStep.cs index a6713622..d12f4a37 100644 --- a/Client/Api/Commands/IFinalCommandStep.cs +++ b/Client/Api/Commands/IFinalCommandStep.cs @@ -39,26 +39,5 @@ public interface IFinalCommandStep /// the time span after request should be timed out /// a task tracking state of success/failure of the command. Task Send(TimeSpan? timeout = null); - - /// - /// Sends the command with retry to the Zeebe broker. This operation is asynchronous. In case of success, the - /// task returns the event that was generated by the Zeebe broker in response to the command. - /// If the sending of the command fails, because of broker back pressure or network issues the request is - /// retried until the command succeeds. The wait time between retries can be configured on the - /// ZeebeClientBuilder. Per default the wait time is based on power two, which means 2^1 seconds, 2^2 seconds - /// etc. until it reaches the maximum of one minute. - /// - /// Use await ...SendWithRetry(); to wait until the response is available. - /// - /// - /// - /// T response = await command.SendWithRetry(); - /// - /// - /// - /// - /// the time span after request should be timed out - /// a task tracking state of success/failure of the command. - Task SendWithRetry(TimeSpan? timeout = null); } } diff --git a/Client/Api/Commands/IFinalCommandWithRetryStep.cs b/Client/Api/Commands/IFinalCommandWithRetryStep.cs new file mode 100644 index 00000000..017c2e41 --- /dev/null +++ b/Client/Api/Commands/IFinalCommandWithRetryStep.cs @@ -0,0 +1,29 @@ +using System; +using System.Threading.Tasks; + +namespace Zeebe.Client.Api.Commands +{ + public interface IFinalCommandWithRetryStep : IFinalCommandStep + { + /// + /// Sends the command with retry to the Zeebe broker. This operation is asynchronous. In case of success, the + /// task returns the event that was generated by the Zeebe broker in response to the command. + /// If the sending of the command fails, because of broker back pressure or network issues the request is + /// retried until the command succeeds. The wait time between retries can be configured on the + /// ZeebeClientBuilder. Per default the wait time is based on power two, which means 2^1 seconds, 2^2 seconds + /// etc. until it reaches the maximum of one minute. + /// + /// Use await ...SendWithRetry(); to wait until the response is available. + /// + /// + /// + /// T response = await command.SendWithRetry(); + /// + /// + /// + /// + /// the time span after request should be timed out + /// a task tracking state of success/failure of the command. + Task SendWithRetry(TimeSpan? timeout = null); + } +} \ No newline at end of file diff --git a/Client/Impl/Commands/CompleteJobCommand.cs b/Client/Impl/Commands/CompleteJobCommand.cs index f1877dcd..34aaa27f 100644 --- a/Client/Impl/Commands/CompleteJobCommand.cs +++ b/Client/Impl/Commands/CompleteJobCommand.cs @@ -48,10 +48,5 @@ public async Task Send(TimeSpan? timeout = null) await asyncReply.ResponseAsync; return new Responses.CompleteJobResponse(); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } diff --git a/Client/Impl/Commands/CreateWorkflowInstanceCommand.cs b/Client/Impl/Commands/CreateWorkflowInstanceCommand.cs index f2708007..176965b3 100644 --- a/Client/Impl/Commands/CreateWorkflowInstanceCommand.cs +++ b/Client/Impl/Commands/CreateWorkflowInstanceCommand.cs @@ -65,10 +65,5 @@ public async Task Send(TimeSpan? timeout = null) var response = await asyncReply.ResponseAsync; return new WorkflowInstanceResponse(response); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } \ No newline at end of file diff --git a/Client/Impl/Commands/CreateWorkflowInstanceCommandWithResult.cs b/Client/Impl/Commands/CreateWorkflowInstanceCommandWithResult.cs index 3f247fe2..73f4ae79 100644 --- a/Client/Impl/Commands/CreateWorkflowInstanceCommandWithResult.cs +++ b/Client/Impl/Commands/CreateWorkflowInstanceCommandWithResult.cs @@ -51,10 +51,5 @@ public async Task Send(TimeSpan? timeout = null) var response = await asyncReply.ResponseAsync; return new WorkflowInstanceResultResponse(response); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } \ No newline at end of file diff --git a/Client/Impl/Commands/DeployWorkflowCommand.cs b/Client/Impl/Commands/DeployWorkflowCommand.cs index 8611f87c..6ea22ba7 100644 --- a/Client/Impl/Commands/DeployWorkflowCommand.cs +++ b/Client/Impl/Commands/DeployWorkflowCommand.cs @@ -86,10 +86,5 @@ private void AddWorkflow(ByteString resource, string resourceName) request.Workflows.Add(requestObject); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } diff --git a/Client/Impl/Commands/FailJobCommand.cs b/Client/Impl/Commands/FailJobCommand.cs index ed40fb3d..8dcce66a 100644 --- a/Client/Impl/Commands/FailJobCommand.cs +++ b/Client/Impl/Commands/FailJobCommand.cs @@ -55,10 +55,5 @@ public async Task Send(TimeSpan? timeout = null) await asyncReply.ResponseAsync; return new FailJobResponse(); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } diff --git a/Client/Impl/Commands/PublishMessageCommand.cs b/Client/Impl/Commands/PublishMessageCommand.cs index 44a30972..62f18dd8 100644 --- a/Client/Impl/Commands/PublishMessageCommand.cs +++ b/Client/Impl/Commands/PublishMessageCommand.cs @@ -70,10 +70,5 @@ public async Task Send(TimeSpan? timeout = null) await asyncReply.ResponseAsync; return new PublishMessageResponse(); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } diff --git a/Client/Impl/Commands/ResolveIncidentCommand.cs b/Client/Impl/Commands/ResolveIncidentCommand.cs index 51d7be12..cb8c36b9 100644 --- a/Client/Impl/Commands/ResolveIncidentCommand.cs +++ b/Client/Impl/Commands/ResolveIncidentCommand.cs @@ -27,10 +27,5 @@ public async Task Send(TimeSpan? timeout = null) await asyncReply.ResponseAsync; return new ResolveIncidentResponse(); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } \ No newline at end of file diff --git a/Client/Impl/Commands/SetVariablesCommand.cs b/Client/Impl/Commands/SetVariablesCommand.cs index a9abc2dc..4d495744 100644 --- a/Client/Impl/Commands/SetVariablesCommand.cs +++ b/Client/Impl/Commands/SetVariablesCommand.cs @@ -39,10 +39,5 @@ public async Task Send(TimeSpan? timeout = null) var response = await asyncReply.ResponseAsync; return new SetVariablesResponse(response); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } \ No newline at end of file diff --git a/Client/Impl/Commands/ThrowErrorCommand.cs b/Client/Impl/Commands/ThrowErrorCommand.cs index 910760b9..a88e0988 100644 --- a/Client/Impl/Commands/ThrowErrorCommand.cs +++ b/Client/Impl/Commands/ThrowErrorCommand.cs @@ -54,10 +54,5 @@ public async Task Send(TimeSpan? timeout = null) await asyncReply.ResponseAsync; return new Responses.ThrowErrorResponse(); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } diff --git a/Client/Impl/Commands/TopologyRequestCommand.cs b/Client/Impl/Commands/TopologyRequestCommand.cs index 85f1be42..3eead054 100644 --- a/Client/Impl/Commands/TopologyRequestCommand.cs +++ b/Client/Impl/Commands/TopologyRequestCommand.cs @@ -39,10 +39,5 @@ public async Task Send(TimeSpan? timeout = null) return new Topology(response); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } diff --git a/Client/Impl/Commands/UpdateRetriesCommand.cs b/Client/Impl/Commands/UpdateRetriesCommand.cs index 7b5b99a6..e8981f56 100644 --- a/Client/Impl/Commands/UpdateRetriesCommand.cs +++ b/Client/Impl/Commands/UpdateRetriesCommand.cs @@ -33,10 +33,5 @@ public async Task Send(TimeSpan? timeout = null) await asyncReply.ResponseAsync; return new UpdateRetriesResponse(); } - - public Task SendWithRetry(TimeSpan? timespan = null) - { - throw new NotImplementedException(); - } } } \ No newline at end of file diff --git a/Client/ZeebeClient.cs b/Client/ZeebeClient.cs index f70ef92c..cea697af 100644 --- a/Client/ZeebeClient.cs +++ b/Client/ZeebeClient.cs @@ -66,7 +66,6 @@ internal ZeebeClient(string address, new Channel(address, credentials, channelOptions); gatewayClient = new Gateway.GatewayClient(channelToGateway); - asyncRetryStrategy = new TransientGrpcErrorRetryStrategy(sleepDurationProvider ?? DefaultWaitTimeProvider);