Esempio n. 1
0
        public static IHealthContributor GetRabbitMQContributor(IConfiguration configuration, ILogger <RabbitMQHealthContributor> logger = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            Type rabbitMQInterfaceType      = RabbitMQTypeLocator.IConnectionFactory;
            Type rabbitMQImplementationType = RabbitMQTypeLocator.ConnectionFactory;

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

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

            return(new RabbitMQHealthContributor(factory, logger));
        }
        private static void DoAdd(IServiceCollection services, RabbitMQServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime, IHealthChecksBuilder healthChecksBuilder)
        {
            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));
            if (healthChecksBuilder == null)
            {
                services.Add(new ServiceDescriptor(typeof(IHealthContributor), ctx => new RabbitMQHealthContributor(factory, ctx.GetService <ILogger <RabbitMQHealthContributor> >()), ServiceLifetime.Singleton));
            }
            else
            {
                var connectionString = factory.CreateConnectionString();
                healthChecksBuilder.AddRabbitMQ(connectionString);
            }
        }
Esempio n. 3
0
 public RabbitMQHealthContributor(RabbitMQProviderConnectorFactory factory, ILogger <RabbitMQHealthContributor> logger = null)
 {
     _factory     = factory;
     _logger      = logger;
     _connFactory = _factory.Create(null);
 }