private async Task invoke(Envelope envelope, ChannelNode receiver, DateTime now) { using (var context = new EnvelopeContext(this, envelope, _sender)) { if (envelope.IsDelayed(now)) { moveToDelayedMessageQueue(envelope, context); } else if (envelope.ResponseId.IsNotEmpty()) { completeRequestWithRequestedResponse(envelope, receiver); } else { try { deserialize(envelope, receiver); } catch (Exception e) { Logger.MessageFailed(envelope, e); envelope.Callback.MoveToErrors(new ErrorReport(envelope, e)); return; } finally { Logger.Received(envelope); } await ProcessMessage(envelope, context).ConfigureAwait(false); } } }
// TODO -- think this is gonna die private static void moveToDelayedMessageQueue(Envelope envelope, EnvelopeContext context) { try { envelope.Callback.MoveToDelayedUntil(envelope.ExecutionTime.Value); } catch (Exception e) { envelope.Callback.MarkFailed(e); context.Logger.LogException(e, envelope.CorrelationId, "Failed to move delayed message to the delayed message queue"); } }
public Task InvokeNow(object message) { var envelope = new Envelope { Message = message, Callback = new InlineMessageCallback(message) }; using (var context = new EnvelopeContext(this, envelope, _sender)) { return(ProcessMessage(envelope, context)); } }
private async Task <IContinuation> executeChain(MessageHandler handler, EnvelopeContext context) { try { context.Envelope.Attempts++; await handler.Handle(context).ConfigureAwait(false); Logger.ExecutionFinished(context.Envelope); return(MessageSucceededContinuation.Instance); } catch (Exception e) { Logger.LogException(e, context.Envelope.CorrelationId, "Failure during message processing execution"); return(context.DetermineContinuation(e, handler.Chain, _graph)); } }
public async Task ProcessMessage(Envelope envelope, EnvelopeContext context) { Logger.ExecutionStarted(envelope); var handler = _graph.HandlerFor(envelope.Message.GetType()); if (handler == null) { processNoHandlerLogic(envelope); } else { // TODO -- have the EnvelopeContext.Retry be able to skip right down // to the executeChain method here var continuation = await executeChain(handler, context).ConfigureAwait(false); await continuation.Execute(envelope, context, DateTime.UtcNow).ConfigureAwait(false); } }