private static void RunLocalDispatch() { var bus = new BusFactory() .WithHandlers(typeof(BusPerformanceTests.PerfHandler)) .CreateAndStartInMemoryBus(); Console.WriteLine("Press any key to start"); Console.ReadKey(); var running = true; var runTask = Task.Run(() => { using (DispatchQueue.SetCurrentDispatchQueueName(DispatchQueueNameScanner.DefaultQueueName)) using (MessageContext.SetCurrent(MessageContext.CreateTest())) { while (running) { bus.Send(new BusPerformanceTests.PerfCommand(42)); } } }); Console.WriteLine("Press any key to exit"); Console.ReadKey(); running = false; runTask.Wait(); bus.Stop(); }
public void MeasureLocalDispatch() { // 25/11/2013 - PC CAO: 190k/s var bus = new BusFactory() .WithHandlers(typeof(PerfCommandHandler), typeof(PerfEventHandler)) .CreateAndStartInMemoryBus(); using (MessageContext.SetCurrent(MessageContext.CreateTest().WithDispatchQueueName(DispatchQueueNameScanner.DefaultQueueName))) { Measure.Execution(500000, () => bus.Send(new PerfCommand(42))); } bus.Stop(); }
public void should_dispatch_message_locally() { var handler = new Handler(); var bus = new BusFactory() .WithHandlers(typeof(Handler)) .ConfigureContainer(x => x.ForSingletonOf <Handler>().Use(handler)) .CreateAndStartInMemoryBus(); var task = bus.Send(new FakeCommand(123)); task.Wait(); task.IsCompleted.ShouldBeTrue(); handler.FakeId.ShouldEqual(123); }
public void should_send_message_to_peer() { var directory = new TestPeerDirectory(); var transport = new TestTransport(); var bus = new BusFactory().CreateAndStartInMemoryBus(directory, transport); var otherPeer = new Peer(new PeerId("Abc.Testing.Other.0"), "tcp://other-peer:1234"); directory.Peers[otherPeer.Id] = otherPeer.ToPeerDescriptor(false, typeof(CommandWithRemoteHandler)); bus.Send(new CommandWithRemoteHandler()); var sentMessage = transport.Messages.ExpectedSingle(); sentMessage.TransportMessage.MessageTypeId.GetMessageType().ShouldEqual(typeof(CommandWithRemoteHandler)); var target = sentMessage.Targets.ExpectedSingle(); target.Id.ShouldEqual(otherPeer.Id); }