Пример #1
0
        private static void Main(string[] args)
        {
            using (var container = new Container())
            {
                Console.WriteLine("Starting command sender host...");

                container.Options.AllowResolvingFuncFactories();

                container.RegisterSingleton(RabbitMqConfiguration.ConfigureBus());
                container.RegisterSingleton <ICommandBus, AdvancedBus>();

                Console.WriteLine("Press ENTER to send commands");
                Console.ReadLine();
                Console.WriteLine("Sending commands...");

                var bus = container.GetInstance <ICommandBus>();

                bus.Send(new AddNewKmStand(1000, DateTime.Now, Guid.Empty));
                Console.WriteLine("AddNewKmStand 1 Command was send");

                Console.WriteLine("Press ENTER to send commands");
                Console.ReadLine();
                Console.WriteLine("Sending commands...");

                bus.Send(new AddNewKmStand(1100, DateTime.Now, Guid.Empty));
                Console.WriteLine("AddNewKmStand 2 Command was send");

                ////d30780b9-e989-43f9-9fea-f14dfec58fee
                //bus.Send(new UpdateKmStand(Guid.Parse("d30780b9-e989-43f9-9fea-f14dfec58fee"), 2000, DateTime.Now, Guid.Empty));
                //Console.WriteLine("UpdateKmStand Command was send");

                //bus.Send(new UpdateKmStand(Guid.Parse("d6a8eb8e-690a-4eea-94ab-d300458c4b10"), 2000, DateTime.Now, Guid.Empty));
                //Console.WriteLine("UpdateKmStand Command was send");

                Console.WriteLine("Press ENTER to quit");
                Console.ReadLine();
            }
        }
Пример #2
0
        public void TestMethod1()
        {
            ICommandBus bus = new AdvancedBus(RabbitMqConfiguration.ConfigureBus());

            Task.Factory.StartNew(() => bus.Send(new AddNewKmStand(1000, DateTime.Now, Guid.Empty)));

            var bus2 = RabbitMqConfiguration.ConfigureBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host,
                                    RabbitMqConstants.CommandsQueue, e =>
                {
                    //e.Consumer<MassTransitConsumer<AddNewKmStand>>();
                });
            });

            bus2.StartAsync();

            Console.WriteLine("Listening for Register order commands.. " +
                              "Press enter to exit");
            Console.ReadLine();

            bus2.StopAsync();
        }
Пример #3
0
        private static void Main()
        {
            using (var container = new Container())
            {
                container.Options.AllowResolvingFuncFactories();
                // configuration appsettings convention
                IConfiguration config = new ConfigurationBuilder()
                                        .SetBasePath(Directory.GetCurrentDirectory())
                                        .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
                                        .AddEnvironmentVariables()
                                        .Build();
                container.Options.RegisterParameterConvention(new AppSettingsConvention(key => config[key]));

                ILoggerFactory loggerFactory = new LoggerFactory()
                                               .AddConsole()
                                               .AddDebug();
                container.Options.DependencyInjectionBehavior = new MsContextualLoggerInjectionBehavior(loggerFactory, container);

                ILogger logger = loggerFactory.CreateLogger <Program>();
                //container.RegisterSingleton<ILogger>(logger);
                logger.LogInformation("Starting BC 'Ritten' host...");

                ExampleCQRS.Infrastructure.Registrations.InfrastructureModule.RegisterEventBus(container, config);

                DomainModule.RegisterAll(container);
                ApplicationModule.RegisterAll(container);
                InfrastructureModule.RegisterAll(container);
                InfrastructureModule.RegisterEventForwarder(container);
                RabbitMqModule.RegisterCommandConsumers(container);
                RabbitMqModule.RegisterEventConsumers(container);

                //ReadModel.Infrastructure.Registrations.InfrastructureModule.RegisterAll(container);

                container.RegisterSingleton(RabbitMqConfiguration.ConfigureBus((cfg, host) =>
                {
                    // command queue
                    //cfg.ReceiveEndpoint(host,
                    //    RabbitMqConstants.CommandsQueue, e =>
                    //    {
                    //        e.Handler<ICommand>(context =>
                    //        Console.Out.WriteLineAsync($"Command received : {context.Message.GetType()}"));
                    //        //e.LoadFrom(container);// TODO: prevent receiving same events
                    //    });
                    // events queue
                    cfg.ReceiveEndpoint(host, RabbitMqConstants.GetEventsQueue(BoundedContextName), e =>
                    {
                        e.Handler <IDomainEvent>(context =>
                                                 Console.Out.WriteLineAsync($"Event received : {context.Message.GetType()}"));
                        e.LoadFrom(container);
                    });
                }));

                EventMappings.Configure();

                var eventBus = container.GetInstance <IIntegrationEventBus>();
                eventBus.Subscribe <KmStandCreated, RitService>();

                //var bus = container.GetInstance<IBusControl>();

                //bus.StartAsync();

                Console.WriteLine("Listening for commands.. Press enter to exit");
                Console.ReadLine();

                //bus.StopAsync();
            }
        }