public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, object instance) { var consumer = instance as TConsumer; if (consumer == null) { throw new NullReferenceException("The consumer instance cannot be null."); } var correlatedConfigurator = new InboundCorrelatedMessageRouterConfigurator(configurator.Pipeline); CorrelatedMessageRouter <IConsumeContext <TMessage>, TMessage, TKey> router = correlatedConfigurator.FindOrCreate <TMessage, TKey>(); var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler( HandlerSelector.ForHandler <TMessage>(consumer.Consume))); TKey correlationId = consumer.CorrelationId; UnsubscribeAction result = router.Connect(correlationId, sink); UnsubscribeAction remove = configurator.SubscribedTo <TMessage, TKey>(correlationId); return(() => result() && (router.SinkCount(correlationId) == 0) && remove()); }
public IEnumerable <Action <IConsumeContext <Distributed <TMessage> > > > GetWorker( IConsumeContext <Distributed <TMessage> > context, MultipleHandlerSelector <Distributed <TMessage> > selector) { _pending.Viewed(context.Message.CorrelationId); return(selector(context) .Select(handler => (Action <IConsumeContext <Distributed <TMessage> > >)(x => Handle(x, handler)))); }
private static MessageRouter <IConsumeContext <PingMessage> > SetupRouterOnly() { _consumer = new PerformantConsumer <PingMessage>(1500000); var messageSink = new InstanceMessageSink <PingMessage>(MultipleHandlerSelector.ForHandler( HandlerSelector.ForHandler <PingMessage>(_consumer.Consume))); var router = new MessageRouter <IConsumeContext <PingMessage> >(); router.Connect(messageSink); return(router); }
public ISubscriptionReference Connect(IInboundPipelineConfigurator configurator, IWorker worker) { IWorkerLoad <TMessage> workerLoad = worker.GetWorkerLoad <TMessage>(); var handlerSink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(_handler)); var sink = new WorkerMessageSink <TMessage>(workerLoad, handlerSink); UnsubscribeAction unsubscribeAction = configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <Distributed <TMessage> >()); return(_referenceFactory(unsubscribeAction)); }
public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, object instance) { var worker = instance as IWorker <TMessage>; if (worker == null) { throw new ConfigurationException("The instance is not a distributor worker"); } var sink = new WorkerMessageSink <Distributed <TMessage> >(MultipleHandlerSelector.ForHandler( HandlerSelector.ForSelectiveHandler <Distributed <TMessage> >(worker.Accept, worker.Consume))); return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <Distributed <TMessage> >())); }
public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, object instance) { var consumer = instance as TConsumer; if (consumer == null) { throw new NullReferenceException("The consumer instance cannot be null."); } var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler( HandlerSelector.ForSelectiveHandler <TMessage>(consumer.Accept, consumer.Consume))); return(configurator.Pipeline.ConnectToRouter(sink, () => configurator.SubscribedTo <TMessage>())); }
public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, HandlerSelector <TMessage> handler) { var routerConfigurator = new InboundMessageRouterConfigurator(configurator.Pipeline); MessageRouter <IConsumeContext <TMessage> > router = routerConfigurator.FindOrCreate <TMessage>(); var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(handler)); UnsubscribeAction result = router.Connect(sink); UnsubscribeAction remove = configurator.SubscribedTo <TMessage>(); return(() => result() && (router.SinkCount == 0) && remove()); }
public void How_many_messages_can_the_pipe_send_per_second() { long count = 0; long count2 = 0; long limit = 2500000; var messageSink = new InstanceMessageSink <ClaimModified>(MultipleHandlerSelector.ForHandler( HandlerSelector.ForHandler <ClaimModified>(m => { count++; }))); var messageSink2 = new InstanceMessageSink <ClaimModified>(MultipleHandlerSelector.ForHandler( HandlerSelector.ForHandler <ClaimModified>(m => { count2++; }))); var router = new MessageRouter <IConsumeContext <ClaimModified> >(); router.Connect(messageSink); router.Connect(messageSink2); var translater = new InboundConvertMessageSink <ClaimModified>(router); var objectRouter = new MessageRouter <IConsumeContext>(); objectRouter.Connect(translater); var pipeline = new InboundMessagePipeline(objectRouter, MockRepository.GenerateMock <IInboundPipelineConfigurator>()); var message = new ClaimModified(); var context = new ConsumeContext <ClaimModified>(ReceiveContext.Empty(), message); for (int i = 0; i < 100; i++) { pipeline.Dispatch(context); } count = 0; count2 = 0; Stopwatch timer = Stopwatch.StartNew(); for (int i = 0; i < limit; i++) { pipeline.Dispatch(context); } timer.Stop(); Trace.WriteLine("Received: " + (count + count2) + ", expected " + limit * 2); Trace.WriteLine("Elapsed Time: " + timer.ElapsedMilliseconds + "ms"); Trace.WriteLine("Messages Per Second: " + limit * 1000 / timer.ElapsedMilliseconds); }
private static MessageRouter <IConsumeContext> SetupTwoRoutersOnly() { _consumer = new PerformantConsumer <PingMessage>(1500000); var messageSink = new InstanceMessageSink <PingMessage>(MultipleHandlerSelector.ForHandler( HandlerSelector.ForHandler <PingMessage>(_consumer.Consume))); var router = new MessageRouter <IConsumeContext <PingMessage> >(); router.Connect(messageSink); var translater = new InboundConvertMessageSink <PingMessage>(router); var nextRouter = new MessageRouter <IConsumeContext>(); nextRouter.Connect(translater); return(nextRouter); }
public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, string requestId, HandlerSelector <TMessage> handler) { if (handler == null) { throw new ArgumentNullException("handler", "The handler cannot be null."); } var correlatedConfigurator = new InboundRequestMessageRouterConfigurator(configurator.Pipeline); RequestMessageRouter <IConsumeContext <TMessage>, TMessage> router = correlatedConfigurator.FindOrCreate <TMessage>(); var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(handler)); UnsubscribeAction result = router.Connect(requestId, sink); return(() => result() && (router.SinkCount(requestId) == 0)); // && remove(); }
public UnsubscribeAction Connect(IInboundPipelineConfigurator configurator, string requestId, HandlerSelector <TMessage> handler) { if (handler == null) { throw new NullReferenceException("The handler cannot be null."); } var correlatedConfigurator = new InboundRequestMessageRouterConfigurator(configurator.Pipeline); RequestMessageRouter <IConsumeContext <TMessage>, TMessage> router = correlatedConfigurator.FindOrCreate <TMessage>(); var sink = new InstanceMessageSink <TMessage>(MultipleHandlerSelector.ForHandler(handler)); UnsubscribeAction result = router.Connect(requestId, sink); // TODO this should NOT publish a correlated subscription, in fact, do we even need to subscribe? //UnsubscribeAction remove = configurator.SubscribedTo<TMessage>(); return(() => result() && (router.SinkCount(requestId) == 0));// && remove(); }
public InstanceMessageSink(MultipleHandlerSelector <TMessage> acceptor) : base(acceptor) { }
public InstanceMessageSinkBase(MultipleHandlerSelector <TMessage> selector) { _selector = selector; }
public DistributorMessageSink(MultipleHandlerSelector <TMessage> selector) : base(selector) { }
public WorkerMessageSink(MultipleHandlerSelector <TMessage> selector) : base(selector) { }