Exemplo n.º 1
0
        public bool Start(HostControl hostControl)
        {
            this.log.Info("Creating bus...");

            this.metrics         = new RoutingSlipMetrics("Routing Slip");
            this.activityMetrics = new RoutingSlipMetrics("Validate Activity");

            this.machine        = new RoutingSlipStateMachine();
            this.provider       = new SqLiteSessionFactoryProvider(false, typeof(RoutingSlipStateSagaMap));
            this.sessionFactory = this.provider.GetSessionFactory();

            this.repository = new NHibernateSagaRepository <RoutingSlipState>(this.sessionFactory);

            this.busControl = Bus.Factory.CreateUsingRabbitMq(x =>
            {
                var host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });

                x.UseSerilog();

                x.EnabledPerformanceCounters();

                x.ReceiveEndpoint(host, "routing_slip_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(Retry.None);
                    e.Consumer(() => new RoutingSlipMetricsConsumer(this.metrics));
                });

                x.ReceiveEndpoint(host, "routing_slip_activity_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(Retry.None);
                    e.Consumer(() => new RoutingSlipActivityConsumer(this.activityMetrics, "Validate"));
                });

                x.ReceiveEndpoint(host, "routing_slip_state", e =>
                {
                    e.PrefetchCount = 8;
                    e.UseConcurrencyLimit(1);
                    e.StateMachineSaga(this.machine, this.repository);
                });
            });

            this.log.Info("Starting bus...");

            this.busControl.Start();

            return(true);
        }
        public bool Start(HostControl hostControl)
        {
            _log.Info("Creating bus...");

            _metrics         = new RoutingSlipMetrics("Routing Slip");
            _activityMetrics = new RoutingSlipMetrics("Validate Activity");

            _machine = new RoutingSlipStateMachine();

            SagaDbContextFactory sagaDbContextFactory =
                () => new SagaDbContext <RoutingSlipState, RoutingSlipStateSagaMap>(SagaDbContextFactoryProvider.ConnectionString);

            _repository = new Lazy <ISagaRepository <RoutingSlipState> >(
                () => new EntityFrameworkSagaRepository <RoutingSlipState>(sagaDbContextFactory));

            _busControl = Bus.Factory.CreateUsingRabbitMq(x =>
            {
                IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h =>
                {
                    h.Username("samplecourier");
                    h.Password("samplecourier");
                });

                x.ReceiveEndpoint(host, "routing_slip_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(Retry.None);
                    e.Consumer(() => new RoutingSlipMetricsConsumer(_metrics));
                });

                x.ReceiveEndpoint(host, "routing_slip_activity_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(Retry.None);
                    e.Consumer(() => new RoutingSlipActivityConsumer(_activityMetrics, "Validate"));
                });

                x.ReceiveEndpoint(host, "routing_slip_state", e =>
                {
                    e.PrefetchCount = 8;
                    e.UseConcurrencyLimit(1);
                    e.StateMachineSaga(_machine, _repository.Value);
                });
            });

            _log.Info("Starting bus...");

            _busControl.StartAsync().Wait();

            return(true);
        }
Exemplo n.º 3
0
        public bool Start(HostControl hostControl)
        {
            _log.Info("Creating bus...");

            _metrics         = new RoutingSlipMetrics("Routing Slip");
            _activityMetrics = new RoutingSlipMetrics("Validate Activity");

            _machine        = new RoutingSlipStateMachine();
            _provider       = new SQLiteSessionFactoryProvider(false, typeof(RoutingSlipStateSagaMap));
            _sessionFactory = _provider.GetSessionFactory();

            _repository = new NHibernateSagaRepository <RoutingSlipState>(_sessionFactory);

            _busControl = Bus.Factory.CreateUsingRabbitMq(x =>
            {
                IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });

                x.ReceiveEndpoint(host, "routing_slip_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(r => r.None());
                    e.Consumer(() => new RoutingSlipMetricsConsumer(_metrics));
                });

                x.ReceiveEndpoint(host, "routing_slip_activity_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(r => r.None());
                    e.Consumer(() => new RoutingSlipActivityConsumer(_activityMetrics, "Validate"));
                });

                x.ReceiveEndpoint(host, "routing_slip_state", e =>
                {
                    e.PrefetchCount = 8;
                    e.UseConcurrencyLimit(1);
                    e.StateMachineSaga(_machine, _repository);
                });
            });

            _log.Info("Starting bus...");

            TaskUtil.Await(() => _busControl.StartAsync());

            return(true);
        }
Exemplo n.º 4
0
        public bool Start(HostControl hostControl)
        {
            _log.Info("Creating bus...");

            _metrics = new RoutingSlipMetrics("Routing Slip");
            _activityMetrics = new RoutingSlipMetrics("Validate Activity");

            _machine = new RoutingSlipStateMachine();
            _provider = new SQLiteSessionFactoryProvider(false, typeof(RoutingSlipStateSagaMap));
            _sessionFactory = _provider.GetSessionFactory();

            _repository = new NHibernateSagaRepository<RoutingSlipState>(_sessionFactory);

            _busControl = Bus.Factory.CreateUsingRabbitMq(x =>
            {
                IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });

                x.ReceiveEndpoint(host, "routing_slip_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(Retry.None);
                    e.Consumer(() => new RoutingSlipMetricsConsumer(_metrics));
                });

                x.ReceiveEndpoint(host, "routing_slip_activity_metrics", e =>
                {
                    e.PrefetchCount = 100;
                    e.UseRetry(Retry.None);
                    e.Consumer(() => new RoutingSlipActivityConsumer(_activityMetrics, "Validate"));
                });

                x.ReceiveEndpoint(host, "routing_slip_state", e =>
                {
                    e.PrefetchCount = 8;
                    e.UseConcurrencyLimit(1);
                    e.StateMachineSaga(_machine, _repository);
                });
            });

            _log.Info("Starting bus...");

            _busHandle = _busControl.Start();

            return true;
        }
Exemplo n.º 5
0
        private void ConfigureMassTransit(IServiceCollection services, IServiceProvider serviceProvider, IRabbitMqHost host, IRabbitMqBusFactoryConfigurator cfg)
        {
            var machine = new RoutingSlipStateMachine();

            services.AddSingleton <ISagaRepository <RoutingSlipState> >(sp => new EntityFrameworkSagaRepository <RoutingSlipState>(() => sp.GetRequiredService <OperationsDbContext>(), optimistic: true));

            cfg.ReceiveEndpoint(host, "routing_slip_state", e =>
            {
                e.PrefetchCount = 8;
                e.UseConcurrencyLimit(1);
                e.UseRetry(x =>
                {
                    x.Handle <DbUpdateConcurrencyException>();
                    x.Interval(5, TimeSpan.FromMilliseconds(100));
                }); // Add the retry middleware for optimistic concurrency
                e.StateMachineSaga(machine, new EntityFrameworkSagaRepository <RoutingSlipState>(() => new OperationsDbContext(new DbContextOptionsBuilder().UseMySql(Configuration.GetConnectionString("DatabaseConnection")).Options), optimistic: true));
            });

            cfg.ConfigureActivities(host, serviceProvider, Configuration);
        }