/// <summary> /// Use RabbitMQ. /// Pass IApplicationLifetime.ApplicationStopping to this method. /// </summary> /// <param name="app"></param> /// <returns></returns> public static IApplicationBuilder UseConsul(this IApplicationBuilder app, CancellationToken applicationStopping) { _serviceDiscoveryHelper = _serviceDiscoveryHelper ?? app.ApplicationServices.GetRequiredService <IServiceDiscoveryHelper>(); _serviceDiscoveryHelper.RegisterAsync().GetAwaiter().GetResult(); applicationStopping.Register(() => { try { _serviceDiscoveryHelper.DeregisterAsync().GetAwaiter().GetResult(); } catch { // No action. } }); return(app); }
public ConnectionFactoryResolver( IMessageBusOptions messageBusOptions, IServiceDiscoveryHelper serviceDiscoveryHelper) { _messageBusOptions = messageBusOptions; _serviceDiscoveryHelper = serviceDiscoveryHelper; _connectionFactory_singleton_lazy = new Lazy <IConnectionFactory>(() => { var factory = new ConnectionFactory { UserName = _messageBusOptions.UserName, Password = _messageBusOptions.Password, VirtualHost = _messageBusOptions.VirtualHost, HostName = _messageBusOptions.HostName, DispatchConsumersAsync = true }; if (_messageBusOptions.Port > 0 && _messageBusOptions.Port < 65536) { factory.Port = _messageBusOptions.Port; } return(factory); }, false); }
public override void PostInitialize() { consulHelper = IocManager.Resolve <IServiceDiscoveryHelper>(); AsyncHelper.RunSync(async() => await consulHelper.RegisterAsync()); }