internal void UpdateConfiguration(HystrixRabbitMQServiceInfo si, HystrixProviderConnectorOptions configuration) { if (si == null) { return; } if (!string.IsNullOrEmpty(si.Uri)) { if (si.Scheme.Equals(HystrixProviderConnectorOptions.Default_SSLScheme, System.StringComparison.OrdinalIgnoreCase)) { configuration.SslEnabled = true; configuration.SslPort = si.Port; } else { configuration.Port = si.Port; } configuration.Username = si.UserName; configuration.Password = si.Password; configuration.Server = si.Host; configuration.VirtualHost = si.Path; } }
private static void DoAdd(IServiceCollection services, HystrixRabbitMQServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) { var rabbitFactory = RabbitMQTypeLocator.ConnectionFactory; var hystrixConfig = new HystrixProviderConnectorOptions(config); var factory = new HystrixProviderConnectorFactory(info, hystrixConfig, rabbitFactory); services.Add(new ServiceDescriptor(typeof(HystrixConnectionFactory), factory.Create, contextLifetime)); }
public void Constructor_ThrowsIfConfigNull() { HystrixProviderConnectorOptions config = null; HystrixRabbitMQServiceInfo si = null; var ex = Assert.Throws <ArgumentNullException>(() => new HystrixProviderConnectorFactory(si, config, typeof(ConnectionFactory))); Assert.Contains(nameof(config), ex.Message); }
public HystrixProviderConnectorFactory(HystrixRabbitMQServiceInfo sinfo, HystrixProviderConnectorOptions config, Type connectFactory) { _info = sinfo; _config = config ?? throw new ArgumentNullException(nameof(config)); _type = connectFactory ?? throw new ArgumentNullException(nameof(connectFactory)); _setUri = FindSetUriMethod(_type); if (_setUri == null) { throw new ConnectorException("Unable to find ConnectionFactory.SetUri(), incompatible RabbitMQ assembly"); } }
private static void DoAdd(IServiceCollection services, HystrixRabbitMQServiceInfo info, IConfiguration config, ServiceLifetime contextLifetime) { Type rabbitFactory = ConnectorHelpers.FindType(rabbitAssemblies, rabbitTypeNames); if (rabbitFactory == null) { throw new ConnectorException("Unable to find ConnectionFactory, are you missing RabbitMQ assembly"); } HystrixProviderConnectorOptions hystrixConfig = new HystrixProviderConnectorOptions(config); HystrixProviderConnectorFactory factory = new HystrixProviderConnectorFactory(info, hystrixConfig, rabbitFactory); services.Add(new ServiceDescriptor(typeof(HystrixConnectionFactory), factory.Create, contextLifetime)); }
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); }
/// <summary> /// Adds HystrixConnectionFactory to your ServiceCollection /// </summary> /// <param name="services">Your Service Collection</param> /// <param name="config">Application Configuration</param> /// <param name="contextLifetime">Lifetime of the service to inject</param> /// <param name="logFactory">Not implemented</param> /// <returns>IServiceCollection for chaining</returns> public static IServiceCollection AddHystrixConnection(this IServiceCollection services, IConfiguration config, ServiceLifetime contextLifetime = ServiceLifetime.Singleton, ILoggerFactory logFactory = null) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } HystrixRabbitMQServiceInfo info = config.GetSingletonServiceInfo <HystrixRabbitMQServiceInfo>(); DoAdd(services, info, config, contextLifetime); return(services); }
/// <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>()); }
public void UpdateConfiguration_WithHystrixRabbitMQSSLServiceInfo_UpdatesConfigurationFromServiceInfo() { var configurer = new HystrixProviderConfigurer(); var config = new HystrixProviderConnectorOptions() { Server = "localhost", Port = 1234, Username = "******", Password = "******", VirtualHost = "vhost" }; var si = new HystrixRabbitMQServiceInfo("MyId", "amqps://*****:*****@example.com:5671/si_vhost", false); configurer.UpdateConfiguration(si, config); Assert.True(config.SslEnabled); Assert.Equal("example.com", config.Server); Assert.Equal(5671, config.SslPort); Assert.Equal("si_username", config.Username); Assert.Equal("si_password", config.Password); Assert.Equal("si_vhost", config.VirtualHost); }
public void Configure_SSLServiceInfoOveridesConfig_ReturnsOverriddenConnectionString() { var config = new HystrixProviderConnectorOptions() { Server = "localhost", Port = 1234, Username = "******", Password = "******", VirtualHost = "vhost" }; var configurer = new HystrixProviderConfigurer(); var si = new HystrixRabbitMQServiceInfo("MyId", "amqps://*****:*****@example.com/si_vhost", false); var opts = configurer.Configure(si, config); var uri = new UriInfo(opts); Assert.Equal("example.com", uri.Host); Assert.Equal("amqps", uri.Scheme); Assert.Equal("si_username", uri.UserName); Assert.Equal("si_password", uri.Password); Assert.Equal("si_vhost", uri.Path); }
public void Constructor_CreatesExpected() { string uri = "amqp://*****:*****@192.168.0.81:5672/fb03d693-91fe-4dc5-8203-ff7a6390df66"; List <string> uris = new List <string>() { "amqp://*****:*****@192.168.0.81:5672/fb03d693-91fe-4dc5-8203-ff7a6390df66" }; // string managementUri = "https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/"; // List<string> managementUris = new List<string>() { "https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/" }; bool isSSLEnabled = false; HystrixRabbitMQServiceInfo r1 = new HystrixRabbitMQServiceInfo("myId", uri, isSSLEnabled); HystrixRabbitMQServiceInfo r2 = new HystrixRabbitMQServiceInfo("myId", uri, uris, isSSLEnabled); Assert.Equal("myId", r1.Id); Assert.Equal("amqp", r1.Scheme); Assert.Equal("192.168.0.81", r1.Host); Assert.Equal(5672, r1.Port); Assert.Equal("l5oq2q0unl35s6urfsuib0jvpo", r1.Password); Assert.Equal("03c7a684-6ff1-4bd0-ad45-d10374ffb2af", r1.UserName); Assert.Equal("fb03d693-91fe-4dc5-8203-ff7a6390df66", r1.Path); Assert.Null(r1.Query); Assert.Null(r1.Uris); Assert.Equal(uri, r1.Uri); Assert.Equal("myId", r2.Id); Assert.Equal("amqp", r2.Scheme); Assert.Equal("192.168.0.81", r2.Host); Assert.Equal(5672, r2.Port); Assert.Equal("l5oq2q0unl35s6urfsuib0jvpo", r2.Password); Assert.Equal("03c7a684-6ff1-4bd0-ad45-d10374ffb2af", r2.UserName); Assert.Equal("fb03d693-91fe-4dc5-8203-ff7a6390df66", r2.Path); Assert.Null(r2.Query); Assert.Equal(uris[0], r2.Uris[0]); Assert.Equal(uri, r2.Uri); }
internal string Configure(HystrixRabbitMQServiceInfo si, HystrixProviderConnectorOptions configuration) { UpdateConfiguration(si, configuration); return(configuration.ToString()); }