public bool Start(HostControl hostControl) { _log.Info("Creating bus..."); _machine = new ShoppingCartStateMachine(); SagaDbContextFactory sagaDbContextFactory = () => new SagaDbContext <ShoppingCart, ShoppingCartMap>(SagaDbContextFactoryProvider.ConnectionString); _repository = new Lazy <ISagaRepository <ShoppingCart> >( () => new EntityFrameworkSagaRepository <ShoppingCart>(sagaDbContextFactory)); _busControl = Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h => { h.Username("guest"); h.Password("guest"); }); x.ReceiveEndpoint(host, "shopping_cart_state", e => { e.PrefetchCount = 8; e.StateMachineSaga(_machine, _repository.Value); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["SchedulerQueueName"], e => { // For MT4.0, prefetch must be set for Quartz prior to anything else e.PrefetchCount = 1; x.UseMessageScheduler(e.InputAddress); e.Consumer(() => new ScheduleMessageConsumer(_scheduler)); e.Consumer(() => new CancelScheduledMessageConsumer(_scheduler)); }); }); _log.Info("Starting bus..."); try { _busHandle = MassTransit.Util.TaskUtil.Await <BusHandle>(() => _busControl.StartAsync()); _scheduler.JobFactory = new MassTransitJobFactory(_busControl); _scheduler.Start(); } catch (Exception) { _scheduler.Shutdown(); throw; } return(true); }
public bool Start(HostControl hostControl) { _log.Info("Creating bus..."); _machine = new ShoppingCartStateMachine(); SagaDbContextFactory sagaDbContextFactory = () => new SagaDbContext<ShoppingCart, ShoppingCartMap>(SagaDbContextFactoryProvider.ConnectionString); _repository = new Lazy<ISagaRepository<ShoppingCart>>( () => new EntityFrameworkSagaRepository<ShoppingCart>(sagaDbContextFactory)); _busControl = Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h => { h.Username("guest"); h.Password("guest"); }); x.ReceiveEndpoint(host, "shopping_cart_state", e => { e.PrefetchCount = 8; e.StateMachineSaga(_machine, _repository.Value); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["SchedulerQueueName"], e => { x.UseMessageScheduler(e.InputAddress); e.PrefetchCount = 1; e.Consumer(() => new ScheduleMessageConsumer(_scheduler)); e.Consumer(() => new CancelScheduledMessageConsumer(_scheduler)); }); }); _log.Info("Starting bus..."); try { _busHandle = _busControl.Start(); _scheduler.JobFactory = new MassTransitJobFactory(_busControl); _scheduler.Start(); } catch (Exception) { _scheduler.Shutdown(); throw; } return true; }
public bool Start(HostControl hostControl) { _log.Info("Creating bus..."); _machine = new ShoppingCartStateMachine(); SagaDbContextFactory sagaDbContextFactory = () => new SagaDbContext <ShoppingCart, ShoppingCartMap>(SagaDbContextFactoryProvider.ConnectionString); _repository = new Lazy <ISagaRepository <ShoppingCart> >(() => new EntityFrameworkSagaRepository <ShoppingCart>(sagaDbContextFactory)); _busControl = Bus.Factory.CreateUsingAzureServiceBus(x => { var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", ConfigurationManager.AppSettings["AzureSbNamespace"], ""); var host = x.Host(serviceUri, h => { h.OperationTimeout = TimeSpan.FromMinutes(5); h.TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(ConfigurationManager.AppSettings["AzureSbKeyName"], ConfigurationManager.AppSettings["AzureSbSharedAccessKey"], TimeSpan.FromDays(1), TokenScope.Namespace); }); x.ReceiveEndpoint(host, "shopping_cart_state", e => { e.PrefetchCount = 8; e.StateMachineSaga(_machine, _repository.Value); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["SchedulerQueueName"], e => { e.PrefetchCount = 1; x.UseMessageScheduler(e.InputAddress); e.Consumer(() => new ScheduleMessageConsumer(_scheduler)); e.Consumer(() => new CancelScheduledMessageConsumer(_scheduler)); }); }); _log.Info("Starting bus..."); try { _busHandle = MassTransit.Util.TaskUtil.Await <BusHandle>(() => _busControl.StartAsync()); _scheduler.JobFactory = new MassTransitJobFactory(_busControl); _scheduler.Start(); } catch (Exception) { _scheduler.Shutdown(); throw; } return(true); }