Beispiel #1
0
        public async Task InvokeNow(Envelope envelope)
        {
            if (envelope.Message == null)
            {
                throw new ArgumentNullException(nameof(envelope.Message));
            }

            var handler = _graph.HandlerFor(envelope.Message.GetType());

            if (handler == null)
            {
                throw new ArgumentOutOfRangeException(nameof(envelope),
                                                      $"No known handler for message type {envelope.Message.GetType().FullName}");
            }


            var context = _root.ContextFor(envelope);

            envelope.StartTiming();

            try
            {
                await handler.Handle(context, _cancellation);

                await context.SendAllQueuedOutgoingMessages();

                envelope.MarkCompletion(true);
            }
            catch (Exception e)
            {
                envelope.MarkCompletion(false);
                Logger.LogException(e, message: $"Invocation of {envelope} failed!");
                throw;
            }
        }
Beispiel #2
0
        private async Task invoke(Envelope envelope, DateTime now)
        {
            var context = _root.ContextFor(envelope);

            envelope.StartTiming();

            try
            {
                deserialize(envelope);
            }
            catch (Exception e)
            {
                envelope.MarkCompletion(false);
                Logger.MessageFailed(envelope, e);
                await envelope.Callback.MoveToErrors(envelope, e);

                return;
            }
            finally
            {
                Logger.Received(envelope);
            }

            await ProcessMessage(envelope, context).ConfigureAwait(false);
        }