static void Main(string[] args) { DataBus bus = null; DependencyResolver.SetDependencyResolver(new NinjectBusDependencyResolver()); try { EndpointConvention.Map <TestMessage>(new Uri("rabbitmq://localhost/testmessage_queue")); MessageCorrelation.UseCorrelationId <TestMessage>(x => x.CorrelationId); bus = new DataBus("domer"); bus.Start(); for (int i = 0; i < MessageCount; i++) { bus.Publish <TestMessage>(new TestMessage() { Message = $"Hello World{i}" }).Wait(); } //Thread.Sleep(TimeSpan.FromSeconds(20)); Console.WriteLine($"Количество обработанных сообщений: {TestMessageHandler.Counter}"); Console.WriteLine($"Время затрачено: {TestMessageHandler.WorkTime}"); Console.ReadLine(); } finally { bus?.Stop(); } }
public void ReceiveMessage_StressTest() { using (var bus = new DataBus()) { using (var executionContext = new TestExecutionContext(bus)) { DatabusExecutionContext.SetExecutionContext(executionContext); bus.Start(); for (int i = 0; i < 1000; i++) { executionContext.Publish <TestMessage>(new { Message = "Hello Test World!" }) .Wait(message => Console.Out.WriteLineAsync(message.Message)); } } } }
public void ReceiveMessage_Test() { using (var bus = new DataBus()) { using (var executionContext = new TestExecutionContext(bus)) { DatabusExecutionContext.SetExecutionContext(executionContext); bus.Start(); executionContext.Publish <TestMessage>(new { Message = "Hello Test World!" }).Wait(message => { Assert.AreEqual("Hello Test World!", message.Message); return(Console.Out.WriteLineAsync(message.Message)); }); } } }