public bool Stop(HostControl hostControl) { MassTransitConfigConstants massTransitConfigConstants = _massTransitConfigConstantsOptions.Value; _logger.LogInformation($"{AppConstants.WinServiceProjectName} will be stop"); try { double milliSeconds = TimeSpan.FromSeconds(massTransitConfigConstants.BusStartStopTimeoutSeconds) .TotalMilliseconds; CancellationToken cancellationToken = new CancellationTokenSource(Convert.ToInt32(milliSeconds)).Token; _busControl.StopAsync(cancellationToken) .GetAwaiter() .GetResult(); } catch (Exception e) { string message = $"Bus could not started in {AppConstants.WinServiceProjectName}"; _logger.Log(LogLevel.Critical, default(EventId), GetType(), e, (type, exception) => message); } _logger.LogInformation($"{AppConstants.WinServiceProjectName} stopped"); return(true); }
public IBusControl ConfigureBus( Action <IRabbitMqBusFactoryConfigurator, IRabbitMqHost> registrationAction = null) { MassTransitConfigConstants massTransitConfigConstants = _massTransitConfigOptions.Value; IBusControl busControl = Bus.Factory.CreateUsingRabbitMq(cfg => { IRabbitMqHost host = cfg.Host(new Uri(massTransitConfigConstants.HostAddress), hst => { hst.Username(massTransitConfigConstants.Username); hst.Password(massTransitConfigConstants.Password); }); registrationAction?.Invoke(cfg, host); }); return(busControl); }
private static void AddMassTransit(IServiceCollection serviceCollection, MassTransitConfigConstants massTransitConfigConstants) { // serviceCollection.AddTransient<IConsumeObserver, BasicConsumeObserver>(); // serviceCollection.AddTransient<IPublishObserver, BasicPublishObservers>(); serviceCollection.AddSingleton <BusConfigurator>(); serviceCollection.AddMassTransit(x => { x.AddConsumer <BookCreatedEventConsumer>(); x.AddBus(provider => { var busConfigurator = provider.GetRequiredService <BusConfigurator>(); IBusControl busControl = busConfigurator.ConfigureBus((cfg, host) => { cfg.ReceiveEndpoint(host, massTransitConfigConstants .QueueNames .BookCreatedEvent, e => { e.UseConcurrencyLimit(massTransitConfigConstants .ConcurrencyLimit); e.UseMessageRetry(r => r.Incremental(massTransitConfigConstants.RetryLimitCount, TimeSpan .FromSeconds(massTransitConfigConstants .InitialIntervalSeconds), TimeSpan .FromSeconds(massTransitConfigConstants .IntervalIncrementSeconds) )); e.ConfigureConsumer < BookCreatedEventConsumer >(provider); }); }); return(busControl); }); } ); }