示例#1
0
        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();
            }
        }
示例#2
0
 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));
             }
         }
     }
 }
示例#3
0
 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));
             });
         }
     }
 }