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 #2
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");
     }
 }
        private static void DoAdd(IServiceCollection services, RabbitMQServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
        {
            Type rabbitMQInterfaceType      = RabbitMQTypeLocator.IConnectionFactory;
            Type rabbitMQImplementationType = RabbitMQTypeLocator.ConnectionFactory;

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

            services.Add(new ServiceDescriptor(rabbitMQInterfaceType, factory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(rabbitMQImplementationType, factory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RabbitMQHealthContributor(factory, ctx.GetService <ILogger <RabbitMQHealthContributor> >()), ServiceLifetime.Singleton));
        }
Exemple #4
0
        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, "-")
            });
        }
        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
        private static void DoAdd(IServiceCollection services, RabbitMQServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime)
        {
            Type rabbitMQInterfaceType      = ConnectorHelpers.FindType(rabbitMQAssemblies, rabbitMQInterfaceTypeNames);
            Type rabbitMQImplementationType = ConnectorHelpers.FindType(rabbitMQAssemblies, rabbitMQImplementationTypeNames);

            if (rabbitMQInterfaceType == null || rabbitMQImplementationType == null)
            {
                throw new ConnectorException("Unable to find ConnectionFactory, are you missing RabbitMQ assembly");
            }

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

            services.Add(new ServiceDescriptor(rabbitMQInterfaceType, factory.Create, contextLifetime));
            services.Add(new ServiceDescriptor(rabbitMQImplementationType, factory.Create, contextLifetime));
        }
Exemple #7
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));
        }
 internal string Configure(RabbitMQServiceInfo si, RabbitMQProviderConnectorOptions configuration)
 {
     UpdateConfiguration(si, configuration);
     return(configuration.ToString());
 }