private Connection GetConnection(RabbitMQServiceInfo info, IConfiguration configuration)
        {
            var rabbitConfig = new RabbitMQProviderConnectorOptions(configuration);
            var configurer   = new RabbitMQProviderConfigurer();

            return(new Connection(configurer.Configure(info, rabbitConfig), "RabbitMQ", info));
        }
Exemple #2
0
        internal void UpdateConfiguration(RabbitMQServiceInfo si, RabbitMQProviderConnectorOptions configuration)
        {
            if (si == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(si.Uri))
            {
                if (si.Scheme.Equals(RabbitMQProviderConnectorOptions.Default_SSLScheme, System.StringComparison.OrdinalIgnoreCase))
                {
                    configuration.SslEnabled = true;
                    configuration.SslPort    = si.Port;
                }
                else
                {
                    configuration.Port = si.Port;
                }

                if (configuration.UrlEncodedCredentials)
                {
                    configuration.Username = WebUtility.UrlDecode(si.UserName);
                    configuration.Password = WebUtility.UrlDecode(si.Password);
                }
                else
                {
                    configuration.Username = si.UserName;
                    configuration.Password = si.Password;
                }

                configuration.Server      = si.Host;
                configuration.VirtualHost = si.Path;
            }
        }
Exemple #3
0
 public RabbitMQProviderConnectorFactory(RabbitMQServiceInfo sinfo, RabbitMQProviderConnectorOptions config, Type connectFactory)
 {
     _config       = config ?? throw new ArgumentNullException(nameof(config));
     ConnectorType = connectFactory ?? throw new ArgumentNullException(nameof(connectFactory));
     _info         = sinfo;
     _setUri       = FindSetUriMethod(ConnectorType);
     if (_setUri == null)
     {
         throw new ConnectorException("Unable to find ConnectionFactory.SetUri(), incompatible RabbitMQ assembly");
     }
 }
        public Connection Get(IConfiguration configuration, string serviceName)
        {
            var info = serviceName == null
              ? configuration.GetSingletonServiceInfo <RabbitMQServiceInfo>()
              : configuration.GetRequiredServiceInfo <RabbitMQServiceInfo>(serviceName);

            var rabbitConfig = new RabbitMQProviderConnectorOptions(configuration);
            var configurer   = new RabbitMQProviderConfigurer();

            return(new Connection
            {
                ConnectionString = configurer.Configure(info, rabbitConfig),
                Name = "RabbitMQ" + serviceName?.Insert(0, "-")
            });
        }
Exemple #5
0
        private static void DoAdd(IServiceCollection services, RabbitMQServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, bool addSteeltoeHealthChecks)
        {
            var rabbitMQInterfaceType      = RabbitMQTypeLocator.IConnectionFactory;
            var rabbitMQImplementationType = RabbitMQTypeLocator.ConnectionFactory;

            var rabbitMQConfig = new RabbitMQProviderConnectorOptions(config);
            var factory        = new RabbitMQProviderConnectorFactory(info, rabbitMQConfig, rabbitMQImplementationType);

            services.Add(new ServiceDescriptor(rabbitMQInterfaceType, factory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(rabbitMQImplementationType, factory.Create, contextLifetime));
            if (!services.Any(s => s.ServiceType == typeof(HealthCheckService)) || addSteeltoeHealthChecks)
            {
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RabbitMQHealthContributor(factory, ctx.GetService <ILogger <RabbitMQHealthContributor> >()), ServiceLifetime.Singleton));
            }
        }
Exemple #6
0
        public static IHealthContributor GetRabbitMQContributor(IConfiguration configuration, ILogger <RabbitMQHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var rabbitMQImplementationType = RabbitMQTypeLocator.ConnectionFactory;

            var info = configuration.GetSingletonServiceInfo <RabbitMQServiceInfo>();

            var rabbitMQConfig = new RabbitMQProviderConnectorOptions(configuration);
            var factory        = new RabbitMQProviderConnectorFactory(info, rabbitMQConfig, rabbitMQImplementationType);

            return(new RabbitMQHealthContributor(factory, logger));
        }
Exemple #7
0
 internal string Configure(RabbitMQServiceInfo si, RabbitMQProviderConnectorOptions configuration)
 {
     UpdateConfiguration(si, configuration);
     return(configuration.ToString());
 }