Example #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();
                    }
                });
            }
        }
Example #2
0
        IEnumerable <Action <IConsumeContext <Distributed <TMessage> > > > Handle(
            IConsumeContext <Distributed <TMessage> > context)
        {
            TMessage payload        = context.Message.Payload;
            var      payloadContext = new ConsumeContext <TMessage>(context.BaseContext, payload);

            return(_output.Enumerate(payloadContext)
                   .Select(handler => (Action <IConsumeContext <Distributed <TMessage> > >)(x => handler(payloadContext))));
        }
Example #3
0
        public IEnumerable <Action <IConsumeContext> > Enumerate(IConsumeContext context)
        {
            _interceptor.PreDispatch(context);

            foreach (var consumer in _output.Enumerate(context))
            {
                yield return(consumer);
            }

            _interceptor.PostDispatch(context);
        }
        public IEnumerable <Action <ISendContext> > Enumerate(ISendContext context)
        {
            IBusPublishContext <TMessage> outputContext;

            if (!context.TryGetContext(out outputContext))
            {
                return(Enumerable.Empty <Action <ISendContext> >());
            }

            return(_output.Enumerate(outputContext).Select(consumer => (Action <ISendContext>)(x => consumer(outputContext))));
        }
 private static void SendMessages(IPipelineSink <object> sink, int primeLoopCount)
 {
     for (int i = 0; i < primeLoopCount; i++)
     {
         var message = new PingMessage();
         foreach (var item in sink.Enumerate(message))
         {
             item(message);
         }
     }
 }
Example #6
0
        private static void SendMessages(IPipelineSink <IConsumeContext> sink, int primeLoopCount)
        {
            var message = new PingMessage();
            var context = new ConsumeContext <PingMessage>(ReceiveContext.Empty(), message);

            for (int i = 0; i < primeLoopCount; i++)
            {
                foreach (var item in sink.Enumerate(context))
                {
                    item(context);
                }
            }
        }
Example #7
0
        public override IEnumerable <Action <TMessage> > Enumerate(TMessage message)
        {
            IPipelineSink <TMessage> sink = null;

            _sinks.UpgradeableReadLock(x =>
            {
                if (x.TryGetValue(message.BatchId, out sink) == false)
                {
                    _sinks.WriteLock(y =>
                    {
                        if (x.TryGetValue(message.BatchId, out sink) == false)
                        {
                            _log.Debug("Adding a new message router for batchId " + message.BatchId);
                            var batchMessage = new Batch <TMessage, TBatchId>(message.BatchId, message.BatchLength, null);

                            // we need to create a sink for this batch and get it wired up
                            var router = new MessageRouter <TMessage>();
                            foreach (var messageSink in _consumerSinks.ReadLock(z => z))
                            {
                                foreach (var consumes in messageSink.Enumerate(batchMessage))
                                {
                                    router.Connect(new BatchCombiner <TMessage, TBatchId>(message.BatchId, message.BatchLength, consumes));
                                }
                            }

                            x.Add(message.BatchId, router);

                            sink = router;
                        }
                    });
                }
            });

            if (sink == null)
            {
                yield break;
            }

            foreach (var consumer in sink.Enumerate(message))
            {
                yield return(consumer);
            }
        }
Example #8
0
        protected IEnumerable <Action <TMessage> > EnumerateSinks(TMessage message, TKey batchId)
        {
            IPipelineSink <TMessage> sink = null;

            if (_sinks.ReadLock(x => x.TryGetValue(batchId, out sink)) == false)
            {
                yield break;
            }

            if (sink == null)
            {
                yield break;
            }

            foreach (var consumer in sink.Enumerate(message))
            {
                yield return(consumer);
            }
        }
        public IEnumerable <Action <IConsumeContext> > Enumerate(IConsumeContext context)
        {
            IConsumeContext <TMessage> outputContext;

            if (!context.TryGetContext(out outputContext))
            {
                return(Enumerable.Empty <Action <IConsumeContext> >());
            }

            return(_output.Enumerate(outputContext).Select(consumer => (Action <IConsumeContext>)(x =>
            {
                try
                {
                    consumer(outputContext);
                }
                catch (Exception ex)
                {
                    outputContext.GenerateFault(ex);
                    throw;
                }
            })));
        }