Пример #1
0
        public async Task Test1()
        {
            //Larva.MessageProcess.LoggerManager.SetLoggerProvider(new Log4NetLoggerProvider());
            var consumer1 = new EventConsumer();

            consumer1.Initialize(new ConsumerSettings
            {
                AmqpUri = new Uri("amqp://*****:*****@localhost/test")
            }, "MessageProcess_EventTopic", 4, false, 1, null, typeof(DomainEventTests).Assembly);
            consumer1.Start();

            var consumer2 = new EventConsumer();

            consumer2.Initialize(new ConsumerSettings
            {
                AmqpUri   = new Uri("amqp://*****:*****@localhost/test"),
                GroupName = "Subscriber2"
            }, "MessageProcess_EventTopic", 4, true, 1, null, typeof(DomainEventTests).Assembly);
            consumer2.Start();

            var eventBus = new EventBus();

            eventBus.Initialize(new ProducerSettings
            {
                AmqpUri = new Uri("amqp://*****:*****@localhost/test")
            }, "MessageProcess_EventTopic");
            eventBus.Start();
            for (var i = 1; i <= 5; i++)
            {
                for (var j = 1; j <= 5; j++)
                {
                    await eventBus.PublishAsync(new DomainEvent1($"Test{i}"));
                }
            }
            Thread.Sleep(1000);
            eventBus.Shutdown();

            Thread.Sleep(10000);
            consumer1.Shutdown();
            consumer2.Shutdown();
        }