public async Task Handle(PingerBouncedBallEvent @event)
        {
            if (@event is null)
            {
                throw new ArgumentNullException(nameof(@event));
            }

            _logger.LogInformation($"CreatedAt: {@event.CreatedAt}, ball was bounced from {@event.From} to {@event.To} with message {@event.Message}");

            await Task.Delay(2500);

            var from = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
            var to   = "Pinger";

            var newEvent = new PongerBouncedBallEvent(from, to, "pong");

            _eventBus.SendMessageToQueue(newEvent);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Settings for IoC
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json");

            var configuration = configurationBuilder.Build();

            var services = new ServiceCollection()
                           .AddIntegrationServices(configuration)
                           .AddEventBus(configuration);


            var builder = new ContainerBuilder();

            builder.Populate(services);
            var serviceProvider = new AutofacServiceProvider(builder.Build());

            services.AddLogging(configure => configure.AddConsole());

            var eventBus = serviceProvider.GetService <IEventBus>();

            eventBus.ListenQueue <PingerBouncedBallEvent, PingerBouncedBallEventHandler>();

            var @event = new PongerBouncedBallEvent
            {
                From    = "Ponger",
                To      = "Pinger",
                Message = "pong"
            };

            eventBus.SendMessageToQueue(@event);

            Console.ReadLine();
        }