Exemple #1
0
        public IEnumerable <Action <Distributed <TMessage> > > Enumerate(Distributed <TMessage> item)
        {
            if (!_worker.CanAcceptMessage(item))
            {
                yield break;
            }

            RewriteResponseAddress(item.ResponseAddress);

            foreach (var sinkAction in _sink.Enumerate(item.Payload))
            {
                Action <TMessage> action = sinkAction;

                yield return(message =>
                {
                    _worker.IncrementInProgress();
                    try
                    {
                        _worker.ConsumingMessage(message);

                        action(message.Payload);
                    }
                    finally
                    {
                        _worker.DecrementInProgress();
                    }
                });
            }
        }
        public IEnumerable <Action <IConsumeContext <Distributed <TMessage> > > > Enumerate(
            IConsumeContext <Distributed <TMessage> > context)
        {
            if (!_worker.CanAcceptMessage(context.Message))
            {
                return(Enumerable.Empty <Action <IConsumeContext <Distributed <TMessage> > > >());
            }

            var payloadContext = new ConsumeContext <TMessage>(context.BaseContext, context.Message.Payload);

            payloadContext.SetResponseAddress(context.Message.ResponseAddress);

            return(_sink.Enumerate(payloadContext).Select(action => (Action <IConsumeContext <Distributed <TMessage> > >)(m =>
            {
                _worker.IncrementInProgress();
                try
                {
                    _worker.ConsumingMessage(context.Message);

                    using (payloadContext.CreateScope())
                    {
                        action(payloadContext);
                    }
                }
                finally
                {
                    _worker.DecrementInProgress();
                }
            })));
        }