Пример #1
0
        private static IHost BuildHost()
        {
            var host = new HostBuilder()
                       .ConfigureLogging(loggingBuilder => loggingBuilder.AddConsole())
                       .ConfigureHostConfiguration((configurationBuilder) =>
            {
                configurationBuilder.SetBasePath(Directory.GetCurrentDirectory());
                configurationBuilder.AddEnvironmentVariables(prefix: "CCP_");
            })
                       .ConfigureServices((hostContext, services) =>

            {
                var connections = new Connection[]
                {
                    new Connection <GuestRoomBookingMade>(
                        new ConnectionName("credit.card.booking.event"),
                        new ChannelName("credit.card.booking.event"),
                        new RoutingKey("booking.event"),
                        timeoutInMilliseconds: 200,
                        isDurable: true,
                        highAvailability: true)
                };

                var rmqConnection = new RmqMessagingGatewayConnection
                {
                    AmpqUri  = new AmqpUriSpecification(new Uri("amqp://*****:*****@localhost:5672")),
                    Exchange = new Exchange("hotel.booking.exchange")
                };

                var rmqMessageConsumerFactory = new RmqMessageConsumerFactory(rmqConnection);

                var inboxConfiguration = new MySqlInboxConfiguration
                                         (
                    hostContext.Configuration["Database:CardDetails"],
                    hostContext.Configuration["Database:InboxTableName"]
                                         );

                var inbox = new MySqlInbox(inboxConfiguration);
                services.AddSingleton <IAmAnInbox>(inbox);

                services.AddServiceActivator(options =>
                {
                    options.Connections       = connections;
                    options.ChannelFactory    = new ChannelFactory(rmqMessageConsumerFactory);
                    options.BrighterMessaging = new BrighterMessaging(new InMemoryOutbox(),
                                                                      new RmqMessageProducer(rmqConnection));
                }).AutoFromAssemblies();

                services.AddHostedService <ServiceActivatorHostedService>();

                services.AddDbContext <CardDetailsContext>(options =>
                                                           options.UseMySql(hostContext.Configuration["Database:CardDetails"]));
            })
                       .UseSerilog()
                       .UseConsoleLifetime()
                       .Build();

            return(host);
        }
        public SqlInboxEmptyWhenSearchedTests()
        {
            _mysqlTestHelper = new MySqlTestHelper();
            _mysqlTestHelper.SetupCommandDb();

            _mysqlInBox = new MySqlInbox(_mysqlTestHelper.InboxConfiguration);
            _contextKey = "test-context";
        }
Пример #3
0
        public SqlInboxDuplicateMessageAsyncTests()
        {
            _mysqlTestHelper = new MySqlTestHelper();
            _mysqlTestHelper.SetupCommandDb();

            _mysqlInbox    = new MySqlInbox(_mysqlTestHelper.InboxConfiguration);
            _raisedCommand = new MyCommand {
                Value = "Test"
            };
            _contextKey = "test-context";
        }
        public SqlInboxAddMessageTests()
        {
            _mysqlTestHelper = new MySqlTestHelper();
            _mysqlTestHelper.SetupCommandDb();

            _mysqlInbox    = new MySqlInbox(_mysqlTestHelper.InboxConfiguration);
            _raisedCommand = new MyCommand {
                Value = "Test"
            };
            _contextKey = "test-context";
            _mysqlInbox.Add(_raisedCommand, _contextKey);
        }