public static RabbitMqHostSettings ToRabbitMqHostSettings(this RabbitMqBusConfiguration configuration) { var hostConfiguration = new RabbitMqHostConfigurator(configuration.Host, configuration.VirtualHost, (ushort)configuration.Port) { PublisherConfirmation = true }; if (!string.IsNullOrEmpty(configuration.Username)) { hostConfiguration.Username(configuration.Username); } if (!string.IsNullOrEmpty(configuration.Password)) { hostConfiguration.Password(configuration.Password); } if (configuration.UseSsl) { hostConfiguration.UseSsl((x) => { x.Protocol = System.Security.Authentication.SslProtocols.Tls12; }); } return(hostConfiguration.Settings); }
/// <summary> /// Initializes a new instance of the <see cref="RabbitMqHostBuilder"/> class. /// </summary> /// <param name="services"><see cref="IServiceCollection"/></param> /// <param name="connectionName">The client-provided connection name.</param> /// <param name="configuration">The <see cref="IConfiguration"/> being bound.</param> public RabbitMqHostBuilder(IServiceCollection services, string connectionName, IConfiguration configuration) : this(services, connectionName) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } services.AddOptions(); services.Configure <RabbitMqOptions>(ConnectionName, configuration); _hostConfiguratorFactory = serviceProvider => { var optionsSnapshot = serviceProvider.GetRequiredService <IOptionsSnapshot <RabbitMqOptions> >(); var options = optionsSnapshot.Get(ConnectionName); var hostConfigurator = new RabbitMqHostConfigurator(options.HostAddress, ConnectionName); if (options.Heartbeat.HasValue) { hostConfigurator.Heartbeat(options.Heartbeat.Value); } if (!string.IsNullOrEmpty(options.Username)) { hostConfigurator.Username(options.Username); } if (!string.IsNullOrEmpty(options.Password)) { hostConfigurator.Password(options.Password); } return(hostConfigurator); }; }
/// <inheritdoc /> public virtual IRabbitMqHostBuilder UseUsername(string username) { _hostConfigurator.Username(username); return(this); }