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); } } }
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); }
public void CorrelatedMessageShouldFindTheCorrectSaga() { var repository = new MongoDbStateMachineSagaRepository <TestSaga>(this._db); var initiatePolicy = new InitiatingSagaPolicy <TestSaga, InitiateSimpleSaga>(x => x.CorrelationId, x => false); var message = new InitiateSimpleSaga(this._sagaId); var context = new ConsumeContext <InitiateSimpleSaga>(ReceiveContext.Empty(), message); repository.GetSaga(context, message.CorrelationId, this.GetHandlers, initiatePolicy).Each(x => x(context)); List <TestSaga> sagas = repository.ByCorrelationId(this._sagaId).ToList(); Assert.AreEqual(1, sagas.Count); Assert.IsNotNull(sagas[0]); Assert.AreEqual(this._sagaId, sagas[0].CorrelationId); }
public static IConsumeContext <T> ToConsumeContext <T>(this T message) where T : class { return(new ConsumeContext <T>(ReceiveContext.Empty(), message)); }