public void SetupSecondAzureServiceBusTestFixture() { _secondBus = CreateSecondBus(); _secondBusHandle = _secondBus.Start(); try { _secondBusSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondBus.Address)); _secondInputQueueSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondInputQueueAddress)); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { _secondBusHandle.Stop(tokenSource.Token); } } finally { _secondBusHandle = null; _secondBus = null; } throw; } }
private void InitializeMessageBus() { Log4NetLogger.Use(); _busControl = Bus.Factory.CreateUsingRabbitMq(x => x.Host(GetDefaultRabbitMqBusUri(), h => { })); _busHandle = _busControl.Start(); }
/// <summary> /// Stop a bus, throwing an exception if the bus does not stop in the specified timeout /// </summary> /// <param name="handle">The bus handle</param> /// <param name="stopTimeout">The wait time before throwing an exception</param> public static void Stop(this BusHandle handle, TimeSpan stopTimeout) { using (var cancellationTokenSource = new CancellationTokenSource(stopTimeout)) { handle.Stop(cancellationTokenSource.Token); } }
public async Task Should_work_with_lifecycle_managed_bus() { var bus = _container.Resolve <IBusControl>(); BusHandle busHandle = await bus.StartAsync(); try { ISendEndpoint endpoint = await bus.GetSendEndpoint(new Uri("loopback://localhost/input_queue")); const string name = "Joe"; await endpoint.Send(new SimpleMessageClass(name)); SimpleConsumer lastConsumer = await SimpleConsumer.LastConsumer; lastConsumer.ShouldNotBe(null); SimpleMessageInterface last = await lastConsumer.Last; last.Name .ShouldBe(name); bool wasDisposed = await lastConsumer.Dependency.WasDisposed; wasDisposed .ShouldBe(true); //Dependency was not disposed"); lastConsumer.Dependency.SomethingDone .ShouldBe(true); //Dependency was disposed before consumer executed"); } finally { await busHandle.StopAsync(); } }
public bool Start(HostControl hostControl) { _log.Info("Creating bus..."); _sagaRepository = GetSagaRepository(); ITrackingEventWriter writer = GetTrackingEventWriter(); _busControl = Bus.Factory.CreateUsingRabbitMq(x => { var host = x.Host(GetHostAddress(), h => { h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]); h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["BookingStateQueueName"], e => { e.StateMachineSaga(_stateMachine, _sagaRepository); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["EventTrackingQueueName"], e => { e.Consumer(() => new EventTrackingConsumer(writer)); }); }); _log.Info("Starting bus..."); _busHandle = _busControl.Start(); TaskUtil.Await(() => _busHandle.Ready); return(true); }
public void SetupAzureServiceBusTestFixture() { _bus = CreateBus(); _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver()); _busHandle = _bus.Start(); try { _busSendEndpoint = _bus.GetSendEndpoint(_bus.Address).Result; _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = _bus.GetSendEndpoint(_inputQueueAddress).Result; _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { _bus.Stop(tokenSource.Token); } } finally { _busHandle = null; _bus = null; } throw; } }
public async Task Should_not_create_bus_endpoint_queue_on_startup() { ServiceBusTokenProviderSettings settings = new TestAzureServiceBusAccountSettings(); Uri serviceUri = AzureServiceBusEndpointUriCreator.Create(Configuration.ServiceNamespace); IBusControl bus = Bus.Factory.CreateUsingAzureServiceBus(x => { BusTestFixture.ConfigureBusDiagnostics(x); x.Host(serviceUri, h => h.SharedAccessSignature(s => { s.KeyName = settings.KeyName; s.SharedAccessKey = settings.SharedAccessKey; s.TokenTimeToLive = settings.TokenTimeToLive; s.TokenScope = settings.TokenScope; })); }); BusHandle busHandle = await bus.StartAsync(); try { } finally { await busHandle.StopAsync(); } }
public void SetupAzureServiceBusTestFixture() { _bus = CreateBus(); _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver()); _busHandle = _bus.Start(); try { Await(() => _busHandle.Ready); _busSendEndpoint = _bus.GetSendEndpoint(_bus.Address).Result; _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = _bus.GetSendEndpoint(_inputQueueAddress).Result; _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception ex) { Console.WriteLine("The bus creation failed: {0}", ex); _busHandle.Stop(); throw; } }
public BusTestScenario(TimeSpan timeout, IBusControl busControl) { _timeout = timeout; _busControl = busControl; Received = new ReceivedMessageList(timeout); _skipped = new ReceivedMessageList(timeout); _published = new PublishedMessageList(timeout); _tokenSource = new CancellationTokenSource(timeout); CancellationToken = _tokenSource.Token; var testSendObserver = new TestSendObserver(timeout); Sent = testSendObserver.Messages; _subjectSendEndpoint = GetSendEndpoint(testSendObserver); var consumeObserver = new TestConsumeObserver(timeout); Received = consumeObserver.Messages; busControl.ConnectConsumeObserver(consumeObserver); _busHandle = _busControl.Start(); }
public async Task InitializeConsumer_WithFooCommandConsumer_ConsumeFooQueueAndWriteHelloToDebugWindow() { //Arrange, Act _busHandle = await MetroBusInitializer.Instance.UseRabbitMq(_rabbitMqUri, _rabbitMqUserName, _rabbitMqPassword) .InitializeConsumer <FooCommandConsumer>(_queueName) .Start(); }
public void SetupInMemoryTestFixture() { _bus = CreateBus(); _busHandle = _bus.Start(); try { _busSendEndpoint = Await(() => _bus.GetSendEndpoint(_bus.Address)); _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = Await(() => _bus.GetSendEndpoint(_inputQueueAddress)); _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { _busHandle?.Stop(tokenSource.Token); } } finally { _busHandle = null; _bus = null; } throw; } }
public async Task Should_fault_nicely() { var loggerFactory = new TestOutputLoggerFactory(true); LogContext.ConfigureCurrentLogContext(loggerFactory); DiagnosticListener.AllListeners.Subscribe(new DiagnosticListenerObserver()); IBusControl busControl = Bus.Factory.CreateUsingRabbitMq(x => { x.Host(new Uri("rabbitmq://unknownhost:32787"), h => { h.Username("whocares"); h.Password("Ohcrud"); h.RequestedConnectionTimeout(2000); }); x.AutoStart = false; }); Assert.That(async() => { BusHandle handle = await busControl.StartAsync(new CancellationTokenSource(20000).Token); try { TestContext.Out.WriteLine("Waiting for connection..."); await handle.Ready; } finally { await handle.StopAsync(); } }, Throws.TypeOf <RabbitMqConnectionException>()); }
public async Task Should_startup_and_shut_down_cleanly_with_an_endpoint() { IBusControl busControl = Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(new Uri("rabbitmq://localhost/"), h => { }); x.ReceiveEndpoint(host, "input_queue", e => { e.Handler <Test>(async context => { }); }); }); BusHandle handle = await busControl.StartAsync(TestCancellationToken); try { Console.WriteLine("Waiting for connection..."); await handle.Ready; await Task.Delay(60000); } finally { await handle.StopAsync(TestCancellationToken); } }
public bool Start(HostControl hostControl) { _log.Info("Creating bus..."); _sagaRepository = GetSagaRepository(); ITrackingEventWriter writer = GetTrackingEventWriter(); _busControl = Bus.Factory.CreateUsingRabbitMq(x => { var host = x.Host(GetHostAddress(), h => { h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]); h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["BookingStateQueueName"], e => { e.StateMachineSaga(_stateMachine, _sagaRepository); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["EventTrackingQueueName"], e => { e.Consumer(() => new EventTrackingConsumer(writer)); }); }); _log.Info("Starting bus..."); _busHandle = _busControl.Start(); TaskUtil.Await(() => _busHandle.Ready); return true; }
public async Task Should_fault_nicely() { IBusControl busControl = Bus.Factory.CreateUsingRabbitMq(x => { x.Host(new Uri("rabbitmq://unknownhost:32787"), h => { h.Username("whocares"); h.Password("Ohcrud"); }); }); Assert.That(async() => { BusHandle handle = await busControl.StartAsync(); try { Console.WriteLine("Waiting for connection..."); await handle.Ready; } finally { await handle.StopAsync(); } }, Throws.TypeOf <RabbitMqConnectionException>()); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifetime) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Hello World!"); }); }); var bus = app.ApplicationServices.GetService <IBusControl>(); // consume decorator bus.ConnectConsumeObserver(new ConsumeObserver()); var busHandle = TaskUtil.Await(async() => { BusHandle busHandle = await bus.StartAsync(); await busHandle.Ready; return(busHandle); }); lifetime.ApplicationStopping.Register(() => { busHandle.Stop(); }); }
public virtual async Task Stop() { try { _receiveEndpointObserver?.Disconnect(); _receiveEndpointObserver = null; _busSendObserver?.Disconnect(); _busSendObserver = null; _inputQueueSendObserver?.Disconnect(); _inputQueueSendObserver = null; _busPublishObserver?.Disconnect(); _busPublishObserver = null; _busConsumeObserver?.Disconnect(); _busConsumeObserver = null; using (var tokenSource = new CancellationTokenSource(TestTimeout)) { await(_busHandle?.StopAsync(tokenSource.Token) ?? TaskUtil.Completed).ConfigureAwait(false); } } catch (Exception ex) { _log.Error("Bus Stop Failed: ", ex); throw; } finally { _busHandle = null; _bus = null; } }
public virtual async Task Start() { _sent = new TestSendObserver(TestTimeout); _consumed = new BusTestConsumeObserver(TestTimeout); _published = new BusTestPublishObserver(TestTimeout); PreCreateBus?.Invoke(this); _bus = CreateBus(); ConnectObservers(_bus); _busHandle = await _bus.StartAsync().ConfigureAwait(false); BusSendEndpoint = await GetSendEndpoint(_bus.Address).ConfigureAwait(false); InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false); _inputQueueSendObserver = InputQueueSendEndpoint.ConnectSendObserver(_sent); _busConsumeObserver = _bus.ConnectConsumeObserver(_consumed); _busPublishObserver = _bus.ConnectPublishObserver(_published); _busSendObserver = _bus.ConnectSendObserver(_sent); }
/// <summary> /// Stop a bus, throwing an exception if the bus does not stop in the specified timeout /// </summary> /// <param name="handle">The bus handle</param> /// <param name="stopTimeout">The wait time before throwing an exception</param> public static async Task StopAsync(this BusHandle handle, TimeSpan stopTimeout) { using (var cancellationTokenSource = new CancellationTokenSource(stopTimeout)) { await handle.StopAsync(cancellationTokenSource.Token).ConfigureAwait(false); } }
public async Task Should_work_with_the_registry() { var bus = _container.GetInstance <IBusControl>(); BusHandle busHandle = await bus.StartAsync(); await busHandle.Ready; ISendEndpoint endpoint = await bus.GetSendEndpoint(new Uri("loopback://localhost/input_queue")); const string name = "Joe"; await endpoint.Send(new SimpleMessageClass(name)); var lastConsumer = await SimpleConsumer.LastConsumer; lastConsumer.ShouldNotBeNull(); var last = await lastConsumer.Last; last.Name .ShouldBe(name); var wasDisposed = await lastConsumer.Dependency.WasDisposed; wasDisposed .ShouldBeTrue(); // Dependency was not disposed"); lastConsumer.Dependency.SomethingDone .ShouldBeTrue(); // Dependency was disposed before consumer executed"); }
public bool Start(HostControl hostControl) { var bus = BusConfigurator.ConfigureBus((cfg, host) => { cfg.ReceiveEndpoint(host, RabbitMqConstants.RegisterOrderServiceQueue, e => { cfg.UseNLog(new LogFactory()); e.UseRateLimit(1, TimeSpan.FromSeconds(30)); e.UseRetry(Retry.Interval(5, TimeSpan.FromSeconds(5))); e.UseCircuitBreaker(cb => { cb.TripThreshold = 15; cb.ResetInterval(TimeSpan.FromMinutes(5)); cb.TrackingPeriod = TimeSpan.FromMinutes(1); cb.ActiveThreshold = 10; }); e.Consumer <OrderRegisteredConsumer>(); }); }); var consumeObserver = new LogConsumeObserver(); bus.ConnectConsumeObserver(consumeObserver); _busHandle = bus.Start(); return(true); }
public virtual async Task Start(CancellationToken cancellationToken = default) { _received = new BusTestReceiveObserver(TestInactivityTimeout); _received.ConnectInactivityObserver(InactivityObserver); _consumed = new BusTestConsumeObserver(TestTimeout, InactivityToken); _consumed.ConnectInactivityObserver(InactivityObserver); _published = new BusTestPublishObserver(TestTimeout, TestInactivityTimeout, InactivityToken); _published.ConnectInactivityObserver(InactivityObserver); _sent = new BusTestSendObserver(TestTimeout, TestInactivityTimeout, InactivityToken); _sent.ConnectInactivityObserver(InactivityObserver); PreCreateBus?.Invoke(this); BusControl = CreateBus(); ConnectObservers(BusControl); _busHandle = await BusControl.StartAsync(cancellationToken).ConfigureAwait(false); BusSendEndpoint = await GetSendEndpoint(BusControl.Address).ConfigureAwait(false); InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false); InputQueueSendEndpoint.ConnectSendObserver(_sent); BusControl.ConnectConsumeObserver(_consumed); BusControl.ConnectPublishObserver(_published); BusControl.ConnectReceiveObserver(_received); BusControl.ConnectSendObserver(_sent); }
public async Task SetupHttpTestFixture() { _bus = CreateBus(); _busHandle = await _bus.StartAsync(TestCancellationToken); try { _rootEndpoint = Await(() => _bus.GetSendEndpoint(_hostAddress)); _rootEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { await _busHandle?.StopAsync(tokenSource.Token); } } finally { _busHandle = null; _bus = null; } throw; } }
public async Task Should_fault_when_credentials_are_bad() { IBusControl busControl = Bus.Factory.CreateUsingRabbitMq(x => { x.Host(new Uri("rabbitmq://localhost/"), h => { h.Username("guest"); h.Password("guessed"); }); }); Assert.That(async() => { BusHandle handle = await busControl.StartAsync(); try { Console.WriteLine("Waiting for connection..."); await handle.Ready; } finally { await handle.StopAsync(); } }, Throws.TypeOf <RabbitMqConnectionException>()); }
public async Task Should_support_the_new_syntax() { ServiceBusTokenProviderSettings settings = new TestAzureServiceBusAccountSettings(); var serviceBusNamespace = Configuration.ServiceNamespace; Uri serviceUri = AzureServiceBusEndpointUriCreator.Create( serviceBusNamespace, "MassTransit.Azure.ServiceBus.Core.Tests" ); var completed = new TaskCompletionSource <A>(); IBusControl bus = Bus.Factory.CreateUsingAzureServiceBus(x => { IServiceBusHost host = x.Host(serviceUri, h => { h.SharedAccessSignature(s => { s.KeyName = settings.KeyName; s.SharedAccessKey = settings.SharedAccessKey; s.TokenTimeToLive = settings.TokenTimeToLive; s.TokenScope = settings.TokenScope; }); }); x.ReceiveEndpoint(host, "input_queue", e => { e.PrefetchCount = 16; e.UseLog(Console.Out, async l => string.Format("Logging: {0}", l.Context.MessageId.Value)); e.Handler <A>(async context => completed.TrySetResult(context.Message)); // Add a message handler and configure the pipeline to retry the handler // if an exception is thrown e.Handler <A>(Handle, h => { h.UseRetry(r => r.Interval(5, 100)); }); }); }); BusHandle busHandle = await bus.StartAsync(); try { } finally { await busHandle.StopAsync(); } // })) // { // var queueAddress = new Uri(hostAddress, "input_queue"); // ISendEndpoint endpoint = bus.GetSendEndpoint(queueAddress); // // await endpoint.Send(new A()); // } }
public bool Start(HostControl hostControl) { if (_log.IsInfoEnabled) { _log.InfoFormat("Creating bus for hosted service: {0}", _serviceName); } try { _busControl = _hostBusFactory.CreateBus(_serviceConfigurator, _serviceName); _busHandle = TaskUtil.Await(() => _busControl.StartAsync()); if (_log.IsInfoEnabled) { _log.InfoFormat("Created bus for hosted service: {0}", _serviceName); } return(true); } catch (Exception ex) { if (_log.IsErrorEnabled) { _log.Error($"Creating bus for hosted service: {_serviceName}", ex); } throw; } }
public bool Start(HostControl hostControl) { Console.WriteLine("Creating bus..."); _busControl = MassTransit.Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(new Uri(/*rabbitMQ server*/), h => { /*credentials*/ }); x.UseInMemoryScheduler(); x.UseMessageScheduler(new Uri(RabbitMqServerAddress)); x.ReceiveEndpoint(host, "validation_needed", e => { e.PrefetchCount = 1; e.Durable = true; //again this is how the consumer is registered e.Consumer <RequestConsumer>(); }); }); Console.WriteLine("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("Starting bus..."); _busHandle = _busControl.StartAsync().Result; return true; }
public virtual void Dispose() { if (_busHandle != null) { _busHandle.Stop(_timeout); _busHandle = null; } }
public bool Start(HostControl hostControl) { _log.Info("Starting bus..."); _busHandle = TaskUtil.Await(() => _busControl.StartAsync()); return(true); }
public bool Start(HostControl hostControl) { _busControl = _hostBusFactory.CreateBus(_serviceConfigurator, _serviceName); _busHandle = TaskUtil.Await(() => _busControl.StartAsync()); return(true); }
public bool Start(HostControl hostControl) { _log.Info("Starting bus..."); _busHandle = _busControl.Start(); return(true); }
public void Cleanup() { _producerBus = null; _busHandle?.Stop(); _busHandle = null; }
static MassTransitWithRabbitMQ() { _bus = Bus.Factory.CreateUsingRabbitMq(x => { x.Host(new Uri(_baseurl), h => { h.Username("iot"); h.Password("iot"); }); }); _handle = _bus.Start(); }
public bool Start(HostControl hostControl) { _settings = new Settings(); _fetchAvatarActivitySettings = new FetchAvatarSettings(); _log.Info("Creating bus..."); _busControl = Bus.Factory.CreateUsingRabbitMq(x => { var host = x.Host(GetHostAddress(), h => { h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]); h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["BookMeetingQueueName"], e => { e.Consumer(() => { var handler = new BookingRequestHandler(_settings); return new BookMeetingConsumer(handler); }); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["FetchAvatarActivityQueue"], e => { e.ExecuteActivityHost<FetchAvatarActivity, FetchAvatarArguments>(() => new FetchAvatarActivity(_fetchAvatarActivitySettings)); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ReserveRoomCompensateQueue"], c => { var compensateAddress = c.InputAddress; c.ExecuteActivityHost<ReserveRoomActivity, ReserveRoomArguments>(); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ReserveRoomExecuteQueue"], e => { e.ExecuteActivityHost<ReserveRoomActivity, ReserveRoomArguments>(compensateAddress); }); }); }); _log.Info("Starting bus..."); _busHandle = _busControl.Start(); TaskUtil.Await(() => _busHandle.Ready); return true; }
public void Start() { _busControl = Bus.Factory.CreateUsingRabbitMq(x => { _host = x.Host(new Uri(_baseurl), h => { h.Username("iot"); h.Password("iot"); }); x.ReceiveEndpoint(_host, "rest_requests", e => { e.Consumer<RequestConsumer>(); }); }); _busHandle = _busControl.Start(); }
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; }
public bool Start(HostControl hostControl) { int workerThreads; int completionPortThreads; ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads); Console.WriteLine("Min: {0}", workerThreads); ThreadPool.SetMinThreads(200, completionPortThreads); _log.Info("Creating bus..."); _busControl = Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h => { h.Username("guest"); h.Password("guest"); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ValidateActivityQueue"], e => { e.PrefetchCount = 100; e.ExecuteActivityHost<ValidateActivity, ValidateArguments>( DefaultConstructorExecuteActivityFactory<ValidateActivity, ValidateArguments>.ExecuteFactory); }); string compQueue = ConfigurationManager.AppSettings["CompensateRetrieveActivityQueue"]; Uri compAddress = host.Settings.GetQueueAddress(compQueue); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["RetrieveActivityQueue"], e => { e.PrefetchCount = 100; // e.Retry(Retry.Selected<HttpRequestException>().Interval(5, TimeSpan.FromSeconds(1))); e.ExecuteActivityHost<RetrieveActivity, RetrieveArguments>(compAddress); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["CompensateRetrieveActivityQueue"], e => e.CompensateActivityHost<RetrieveActivity, RetrieveLog>()); }); _log.Info("Starting bus..."); _busHandle = _busControl.Start(); return true; }
public void GivenARunningBusThatIsListeningToABigTestMessageThatIsUsingMongoMessageDataRepository() { _busControl = Bus.Factory.CreateUsingInMemory(cfg => { cfg.ReceiveEndpoint("test-" + new Guid().ToString(), ep => { ep.Handler<BigTestMessage>((context) => { _bigTestMessages.Add(context.Message); return Task.FromResult(0); }); ep.UseMessageData<BigTestMessage>(MessageDataRepository.Instance); }); }); _busHandle = _busControl.Start(); _busHandle.Ready.Wait(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); _bus = MassTransit.Bus.Factory.CreateUsingRabbitMq(x => { x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h => { h.Username("guest"); h.Password("guest"); }); }); _busHandle = _bus.Start(); }
private void ConfigureServiceBus() { _busControl = Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h => { h.Username(ConfigurationManager.AppSettings["RabbitMQUser"]); h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); }); x.ReceiveEndpoint(host, "clearing", e => { e.Durable = true; e.StateMachineSaga(_machine, _repository.Value); e.UseConsoleLog(async (ev, lc) => string.Format("Received message Id:{0} of type: {1}", ev.MessageId, string.Join(",",ev.SupportedMessageTypes))); }); }); _busHandle = _busControl.Start(); }
public void SetupSecondAzureServiceBusTestFixture() { _secondBus = CreateSecondBus(); _secondBusHandle = _secondBus.Start(); try { _secondBusSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondBus.Address)); _secondInputQueueSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondInputQueueAddress)); } catch (Exception ex) { Console.WriteLine("The bus creation failed: {0}", ex); _secondBusHandle.Stop(); throw; } }
public bool Start(HostControl hostControl) { try { Uri serviceBusUri = _configurationProvider.GetServiceBusUri(); if (serviceBusUri.Scheme.Equals("rabbitmq", StringComparison.OrdinalIgnoreCase)) { _bus = Bus.Factory.CreateUsingRabbitMq(busConfig => { IRabbitMqHost host = busConfig.Host(serviceBusUri, h => _configurationProvider.GetHostSettings(h)); busConfig.UseJsonSerializer(); busConfig.ReceiveEndpoint(host, _queueName, endpoint => { endpoint.PrefetchCount = (ushort)_consumerLimit; var partitioner = endpoint.CreatePartitioner(_consumerLimit); endpoint.Consumer(() => new ScheduleMessageConsumer(_scheduler), x => x.ConfigureMessage<ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId))); endpoint.Consumer(() => new CancelScheduledMessageConsumer(_scheduler), x => x.ConfigureMessage<CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId))); }); }); } _busHandle = _bus.Start(); _scheduler.JobFactory = new MassTransitJobFactory(_bus); _scheduler.Start(); } catch (Exception) { _scheduler.Shutdown(); throw; } return true; }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); _bus = MassTransit.Bus.Factory.CreateUsingRabbitMq(x => { x.Host(GetHostAddress(), h => { h.Username(ConfigurationManager.AppSettings["RabbitMQUsername"]); h.Password(ConfigurationManager.AppSettings["RabbitMQPassword"]); }); }); _busHandle = _bus.Start(); TaskUtil.Await(() => _busHandle.Ready); }
public bool Start(HostControl hostControl) { _log.Info("Creating bus..."); _busControl = Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(new Uri(ConfigurationManager.AppSettings["RabbitMQHost"]), h => { h.Username("guest"); h.Password("guest"); }); x.ReceiveEndpoint(host, ConfigurationManager.AppSettings["ServiceQueueName"], e => { e.Consumer<RequestConsumer>(); }); }); _log.Info("Starting bus..."); _busHandle = _busControl.Start(); return true; }
public bool Start(HostControl hostControl) { try { Uri serviceBusUri = _configurationProvider.GetServiceBusUri(); if (serviceBusUri.Scheme.Equals("rabbitmq", StringComparison.OrdinalIgnoreCase)) { _bus = Bus.Factory.CreateUsingRabbitMq(x => { IRabbitMqHost host = x.Host(serviceBusUri, h => _configurationProvider.GetHostSettings(h)); x.UseJsonSerializer(); x.ReceiveEndpoint(host, _queueName, e => { e.PrefetchCount = (ushort)_consumerLimit; e.Consumer(() => new ScheduleMessageConsumer(_scheduler)); e.Consumer(() => new CancelScheduledMessageConsumer(_scheduler)); }); }); } _busHandle = _bus.Start(); _scheduler.JobFactory = new MassTransitJobFactory(_bus); _scheduler.Start(); } catch (Exception) { _scheduler.Shutdown(); throw; } return true; }
public bool Start(HostControl hostControl) { if (_log.IsInfoEnabled) _log.InfoFormat("Creating bus for hosted service: {0}", _serviceName); try { _busControl = _hostBusFactory.CreateBus(_serviceConfigurator, _serviceName); _busHandle = _busControl.Start(); if (_log.IsInfoEnabled) _log.InfoFormat("Created bus for hosted service: {0}", _serviceName); return true; } catch (Exception ex) { if (_log.IsErrorEnabled) _log.Error($"Creating bus for hosted service: {_serviceName}", ex); throw; } }
public async Task SetupAzureServiceBusTestFixture() { _bus = CreateBus(); _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver()); _busHandle = await _bus.StartAsync(); try { _busSendEndpoint = await _bus.GetSendEndpoint(_bus.Address); _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = await _bus.GetSendEndpoint(_inputQueueAddress); _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { await _bus.StopAsync(tokenSource.Token); } } finally { _busHandle = null; _bus = null; } throw; } }
public async Task TearDownInMemoryTestFixture() { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { await _busHandle?.StopAsync(tokenSource.Token); } } catch (Exception ex) { _log.Error("Bus Stop Failed", ex); } finally { _busHandle = null; _bus = null; } }
public void TearDownTwoScopeTestFixture() { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { _secondBusHandle?.Stop(tokenSource.Token); } } catch (Exception ex) { _log.Error("SecondBus Stop Failed", ex); } finally { _secondBusHandle = null; _secondBus = null; } }
public void TearDownTwoScopeTestFixture() { _secondBusHandle?.Stop(); _secondBusHandle = null; }
public void Start() { _busHandle = _busControl.Start(); }
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; }