public async override Task OnMessageAsync(T message, IMessageFeedbackSender feedbackSender, CancellationToken cancellationToken) { var invocationSuccess = false; var exceptions = new List <Exception>(); var tryCount = 0; while (tryCount == 0 || (!invocationSuccess && ShouldRetry(tryCount, exceptions))) { if (tryCount > 0 && InvokeRetryWaitMilliseconds > 0) { await Task.Delay(InvokeRetryWaitMilliseconds, cancellationToken).ConfigureAwait(false); } tryCount++; invocationSuccess = await TryInvokeAsync(message, exceptions, cancellationToken).ConfigureAwait(false); } if (invocationSuccess) { feedbackSender.Ack(); } else if (ShouldRequeue(exceptions)) { feedbackSender.Nack(true); } else { feedbackSender.Nack(false); } }
public void OnMessage(object request, IMessageFeedbackSender feedbackSender) { RetryEntryPoint: InvokeResult invokeResult = this.InvokeListenerMethodOnListenerObject(request); if (invokeResult.Success) { List <object> responses = new List <object>(); if (invokeResult.HasValue) { if (invokeResult.ReturnedValue is IEnumerable) { foreach (var itemOfReturnedValue in invokeResult.ReturnedValue.To <IEnumerable>()) { responses.Add(itemOfReturnedValue); } } else { responses.Add(invokeResult.ReturnedValue); } } else if (this._canUseRequestAsResponse) { responses.Add(request); } else { throw new InvalidCastException("Unsupported queued method result"); } this.HandleResult(this._successResponseRoute, responses); } else if (invokeResult.Exception != null) { bool exemptionClaimedRequeue = this.ExemptionClaimedRequeue(invokeResult.Exception); bool exemptionClaimedRetry = this.ExemptionClaimedRetry(invokeResult.Exception); if (exemptionClaimedRequeue) { this.HandleResult(this.ReceiveRoute, new List <object>() { request }); } else if (exemptionClaimedRetry) { goto RetryEntryPoint; } else { this.HandleResult(this._failureResponseRoute, new List <object>() { request }); } } }
public override Task OnMessageAsync(T message, IMessageFeedbackSender feedbackSender, CancellationToken cancellationToken) { try { CallbackAction(message); feedbackSender.Ack(); } catch (Exception) { feedbackSender.Nack(true); } return(Task.FromResult(0)); }
public async override Task OnMessageAsync(T message, IMessageFeedbackSender feedbackSender, CancellationToken cancellationToken) { try { var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); tokenSource.CancelAfter(_processingTimeout); await _callbackFunc(message, tokenSource.Token).ConfigureAwait(false); feedbackSender.Ack(); } catch (Exception) { feedbackSender.Nack(true); } }
public virtual void OnMessage(object message, IMessageFeedbackSender feedbackSender) { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.TargetObject = this.Service; methodInvoker.TargetMethod = this.ServiceMethod; methodInvoker.Arguments = new object[] { message }; methodInvoker.Prepare(); try { object returnValue = methodInvoker.Invoke(); feedbackSender.Ack(); } catch (Exception) { feedbackSender.Nack(true); } }
public override void OnMessage(object message, IMessageFeedbackSender feedbackSender) { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.TargetObject = this.Service; methodInvoker.TargetMethod = this.ServiceMethod; methodInvoker.Arguments = new object[] { message }; methodInvoker.Prepare(); bool invocationSuccess = false; var exceptions = new List <Exception>(); int tryCount = 0; while (tryCount == 0 || (!invocationSuccess && this.ShouldRetry(tryCount, exceptions))) { if (tryCount > 0 && this.InvokeRetryWaitMilliseconds > 0) { Thread.Sleep(this.InvokeRetryWaitMilliseconds); } tryCount++; this.TryInvoke(methodInvoker, exceptions, out invocationSuccess); } if (invocationSuccess) { feedbackSender.Ack(); } else if (this.ShouldRequeue(exceptions)) { feedbackSender.Nack(true); } else { feedbackSender.Nack(false); } }
public abstract Task OnMessageAsync(T message, IMessageFeedbackSender feedbackSender, CancellationToken cancellationToken);