Esempio n. 1
0
        public static void RegisterHystrixMetricsStream(this ContainerBuilder container, IConfiguration config)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            Type rabbitFactory = ConnectorHelpers.FindType(rabbitAssemblies, rabbitTypeNames);

            if (rabbitFactory == null)
            {
                throw new ConnectorException("Unable to find ConnectionFactory, are you missing RabbitMQ assembly");
            }
            container.RegisterOptions();
            container.RegisterInstance(HystrixDashboardStream.GetInstance()).SingleInstance();

            HystrixRabbitServiceInfo        info          = config.GetSingletonServiceInfo <HystrixRabbitServiceInfo>();
            HystrixProviderConnectorOptions hystrixConfig = new HystrixProviderConnectorOptions(config);
            HystrixProviderConnectorFactory factory       = new HystrixProviderConnectorFactory(info, hystrixConfig, rabbitFactory);

            container.Register(c => (HystrixConnectionFactory)factory.Create(null)).SingleInstance();

            container.Configure <HystrixMetricsStreamOptions>(config.GetSection(HYSTRIX_STREAM_PREFIX));

            container.RegisterType <HystrixMetricsStreamPublisher>().SingleInstance();
        }
Esempio n. 2
0
        /// <summary>
        /// Add a HystrixConnectionFactory to your Autofac Container
        /// </summary>
        /// <param name="container">Your Autofac Container Builder</param>
        /// <param name="config">Application configuration</param>
        /// <param name="serviceName">Cloud Foundry service name binding</param>
        /// <returns>the RegistrationBuilder for (optional) additional configuration</returns>
        public static IRegistrationBuilder <object, SimpleActivatorData, SingleRegistrationStyle> RegisterHystrixConnection(this ContainerBuilder container, IConfiguration config, string serviceName = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            Type rabbitFactory = ConnectorHelpers.FindType(rabbitAssemblies, rabbitTypeNames);

            if (rabbitFactory == null)
            {
                throw new ConnectorException("Unable to find RabbitMQ ConnectionFactory type. RabbitMQ.Client assembly may be missing");
            }

            HystrixRabbitMQServiceInfo info;

            if (serviceName == null)
            {
                info = config.GetSingletonServiceInfo <HystrixRabbitMQServiceInfo>();
            }
            else
            {
                info = config.GetRequiredServiceInfo <HystrixRabbitMQServiceInfo>(serviceName);
            }

            HystrixProviderConnectorOptions hystrixConfig = new HystrixProviderConnectorOptions(config);
            HystrixProviderConnectorFactory factory       = new HystrixProviderConnectorFactory(info, hystrixConfig, rabbitFactory);

            return(container.Register(c => factory.Create(null)).As <HystrixConnectionFactory>());
        }
Esempio n. 3
0
        public void Create_ReturnsRabbitMQConnection()
        {
            var config = new HystrixProviderConnectorOptions()
            {
                Server      = "localhost",
                Port        = 5672,
                Password    = "******",
                Username    = "******",
                VirtualHost = "vhost"
            };
            var si         = new HystrixRabbitMQServiceInfo("MyId", "amqp://*****:*****@example.com:5672/si_vhost", false);
            var factory    = new HystrixProviderConnectorFactory(si, config, typeof(ConnectionFactory));
            var connection = factory.Create(null);

            Assert.NotNull(connection);
        }
Esempio n. 4
0
        /// <summary>
        /// Add a HystrixConnectionFactory to your Autofac Container
        /// </summary>
        /// <param name="container">Your Autofac Container Builder</param>
        /// <param name="config">Application configuration</param>
        /// <param name="serviceName">Cloud Foundry service name binding</param>
        /// <returns>the RegistrationBuilder for (optional) additional configuration</returns>
        public static IRegistrationBuilder <object, SimpleActivatorData, SingleRegistrationStyle> RegisterHystrixConnection(this ContainerBuilder container, IConfiguration config, string serviceName = null)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            HystrixRabbitMQServiceInfo info = serviceName == null
                ? config.GetSingletonServiceInfo <HystrixRabbitMQServiceInfo>()
                : config.GetRequiredServiceInfo <HystrixRabbitMQServiceInfo>(serviceName);

            Type rabbitFactory = RabbitMQTypeLocator.ConnectionFactory;
            var  hystrixConfig = new HystrixProviderConnectorOptions(config);
            var  factory       = new HystrixProviderConnectorFactory(info, hystrixConfig, rabbitFactory);

            return(container.Register(c => factory.Create(null)).As <HystrixConnectionFactory>());
        }