Пример #1
0
        GetConsumer <TMessage>(IConsumeContext <TMessage> context,
                               InstanceHandlerSelector <TConsumer, TMessage> selector)
            where TMessage : class
        {
            IEnumerable <Action <IConsumeContext <TMessage> > > consumers = _consumerFactory.GetConsumer(context, selector);

            foreach (var action in consumers)
            {
                Action <IConsumeContext <TMessage> > consumer = action;

                yield return(message =>
                {
                    var received = new ReceivedMessageImpl <TMessage>(message);

                    try
                    {
                        consumer(message);
                    }
                    catch (Exception ex)
                    {
                        received.SetException(ex);
                    }
                    finally
                    {
                        _received.Add(received);
                    }
                });
            }
        }
        void HandleMessage(IConsumeContext <TSubject> context)
        {
            var received = new ReceivedMessageImpl <TSubject>(context);

            try
            {
                using (context.CreateScope())
                {
                    _handler(context, context.Message);
                }
            }
            catch (Exception ex)
            {
                received.SetException(ex);
            }
            finally
            {
                _received.Add(received);
            }
        }
        public IEnumerable <Action <IConsumeContext <TMessage> > > GetSaga <TMessage>(IConsumeContext <TMessage> context, Guid sagaId,
                                                                                      InstanceHandlerSelector <TSaga, TMessage>
                                                                                      selector, ISagaPolicy <TSaga, TMessage> policy)
            where TMessage : class
        {
            ISagaPolicy <TSaga, TMessage> sagaPolicy = new SagaPolicyTestDecorator <TSaga, TMessage>(policy, sagaId, _created);

            InstanceHandlerSelector <TSaga, TMessage> interceptSelector = (s, c) =>
            {
                IEnumerable <Action <IConsumeContext <TMessage> > > result = selector(s, c);

                return(DecorateSelector(s, result));
            };

            IEnumerable <Action <IConsumeContext <TMessage> > > consumers = _sagaRepository.GetSaga(context, sagaId, interceptSelector,
                                                                                                    sagaPolicy);

            foreach (var action in consumers)
            {
                Action <IConsumeContext <TMessage> > consumer = action;

                yield return(message =>
                {
                    var received = new ReceivedMessageImpl <TMessage>(message);

                    try
                    {
                        consumer(message);
                    }
                    catch (Exception ex)
                    {
                        received.SetException(ex);
                    }
                    finally
                    {
                        _received.Add(received);
                    }
                });
            }
        }
        public void Receive(Func <IReceiveContext, Action <IReceiveContext> > receiver, TimeSpan timeout)
        {
            _endpoint.Receive(receiveContext =>
            {
                var decoratedReceiveContext = new ReceiveContextTestDecorator(receiveContext, _scenario);

                Action <IReceiveContext> receive = receiver(decoratedReceiveContext);
                if (receive == null)
                {
                    var skipped = new ReceivedMessageImpl(receiveContext);
                    _scenario.AddSkipped(skipped);

                    return(null);
                }

                return(context =>
                {
                    decoratedReceiveContext = new ReceiveContextTestDecorator(context, _scenario);
                    var received = new ReceivedMessageImpl(context);
                    try
                    {
                        receive(decoratedReceiveContext);
                    }
                    catch (Exception ex)
                    {
                        received.SetException(ex);
                        throw;
                    }
                    finally
                    {
                        _received.Add(received);
                        _scenario.AddReceived(received);
                    }
                });
            }, timeout);
        }
Пример #5
0
 public void AddSkipped(ReceivedMessage message)
 {
     _skipped.Add(message);
 }
Пример #6
0
        public void AddReceived(ReceivedMessage message)
        {
            _received.Add(message);

            _skipped.Remove(message);
        }