public void Should_parse_host_with_separate_port() { var connectionConfiguration = ConnectionConfiguration.Create("host=my.host.com;port=1234"); Assert.AreEqual(connectionConfiguration.Host, "my.host.com"); Assert.AreEqual(connectionConfiguration.Port, 1234); }
public void SetUp() { var connectionString = Environment.GetEnvironmentVariable("RabbitMQTransport_ConnectionString") ?? "host=localhost"; connectionFactory = new RabbitMQ.ConnectionFactory("unit-tests", ConnectionConfiguration.Create(connectionString), null, true, false, TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(30), null); connection = connectionFactory.CreateAdministrationConnection(); }
public void Should_determine_if_tls_should_be_used_from_connection_string(string scheme, uint port, bool useTls) { var connectionConfiguration = ConnectionConfiguration.Create($"{scheme}://guest:guest@localhost/"); Assert.AreEqual(connectionConfiguration.UseTls, useTls); Assert.AreEqual(connectionConfiguration.Port, port); }
public void Should_list_all_invalid_options() { var connectionString = "host=:notaport1,host=localhost2;" + "port=notaport2;" + "useTls=notusetls;" + "requestedHeartbeat=60;" + "retryDelay=10;" + "usePublisherConfirms=true;" + "prefetchcount=100;" + "maxWaitTimeForConfirms=02:03:39;" + "dequeuetimeout=1;" + "certPath =/path/to/client/keycert.p12;" + "certPassPhrase = abc123;"; var exception = Assert.Throws <NotSupportedException>(() => ConnectionConfiguration.Create(connectionString)); Assert.That(exception.Message, Does.Contain("Multiple hosts are no longer supported")); Assert.That(exception.Message, Does.Contain("consider using a load balancer")); Assert.That(exception.Message, Does.Contain("Empty host name in 'host' connection string option.")); Assert.That(exception.Message, Does.Contain("'notaport1' is not a valid Int32 value for the port in the 'host' connection string option.")); Assert.That(exception.Message, Does.Contain("'notaport2' is not a valid Int32 value for the 'port' connection string option.")); Assert.That(exception.Message, Does.Contain("'notusetls' is not a valid Boolean value for the 'useTls' connection string option.")); Assert.That(exception.Message, Does.Contain("The 'UsePublisherConfirms' connection string option has been removed")); Assert.That(exception.Message, Does.Contain("The 'PrefetchCount' connection string option has been removed")); Assert.That(exception.Message, Does.Contain("The 'MaxWaitTimeForConfirms' connection string option has been removed")); Assert.That(exception.Message, Does.Contain("The 'DequeueTimeout' connection string option has been removed")); Assert.That(exception.Message, Does.Contain("The 'requestedHeartbeat' connection string option has been removed")); Assert.That(exception.Message, Does.Contain("The 'retryDelay' connection string option has been removed")); Assert.That(exception.Message, Does.Contain("The 'certPath' connection string option has been removed")); Assert.That(exception.Message, Does.Contain("The 'certPassphrase' connection string option has been removed")); }
public void Should_parse_use_tls() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;useTls=true"); Assert.AreEqual(true, connectionConfiguration.UseTls); Assert.AreEqual(5671, connectionConfiguration.Port); }
public void Should_parse_host_without_port() { var connectionConfiguration = ConnectionConfiguration.Create("amqp://my.host.com/"); Assert.AreEqual(connectionConfiguration.Host, "my.host.com"); Assert.AreEqual(connectionConfiguration.Port, 5672); }
public void Should_parse_host_without_port() { var connectionConfiguration = ConnectionConfiguration.Create("host=my.host.com", endpointName); Assert.AreEqual(connectionConfiguration.Host, "my.host.com"); Assert.AreEqual(connectionConfiguration.Port, 5672); }
public void Should_parse_host() { var connectionConfiguration = ConnectionConfiguration.Create("host=host.one:1001;port=1002"); Assert.AreEqual(connectionConfiguration.Host, "host.one"); Assert.AreEqual(connectionConfiguration.Port, 1001); }
public void Should_throw_on_invalid_port() { var connectionString = "amqp://localhost:notaport/"; var exception = Assert.Throws <UriFormatException>(() => ConnectionConfiguration.Create(connectionString)); Assert.That(exception.Message, Does.Contain("Invalid URI: Invalid port specified.")); }
public void Should_correctly_parse_full_connection_string() { var connectionConfiguration = ConnectionConfiguration.Create(connectionString); Assert.AreEqual(connectionConfiguration.Host, "192.168.1.1"); Assert.AreEqual(connectionConfiguration.Port, 1234); Assert.AreEqual(connectionConfiguration.VirtualHost, "Copa"); Assert.AreEqual(connectionConfiguration.UserName, "Copa"); Assert.AreEqual(connectionConfiguration.Password, "abc_xyz"); Assert.AreEqual(connectionConfiguration.UseTls, true); }
public void Should_correctly_parse_full_connection_string() { const string connectionString = "amqp://*****:*****@192.168.1.1:5672/Copa"; var connectionConfiguration = ConnectionConfiguration.Create(connectionString); Assert.AreEqual(connectionConfiguration.Host, "192.168.1.1"); Assert.AreEqual(connectionConfiguration.Port, 5672); Assert.AreEqual(connectionConfiguration.VirtualHost, "Copa"); Assert.AreEqual(connectionConfiguration.UserName, "Copa"); Assert.AreEqual(connectionConfiguration.Password, "abc_xyz"); }
public void Should_correctly_parse_full_connection_string() { var connectionConfiguration = ConnectionConfiguration.Create(connectionString, endpointName); Assert.AreEqual(connectionConfiguration.Host, "192.168.1.1"); Assert.AreEqual(connectionConfiguration.Port, 1234); Assert.AreEqual(connectionConfiguration.VirtualHost, "Copa"); Assert.AreEqual(connectionConfiguration.UserName, "Copa"); Assert.AreEqual(connectionConfiguration.Password, "abc_xyz"); Assert.AreEqual(connectionConfiguration.RequestedHeartbeat, 3); Assert.AreEqual(connectionConfiguration.RetryDelay, new TimeSpan(1, 2, 3)); //01:02:03 Assert.AreEqual(connectionConfiguration.UseTls, true); Assert.AreEqual(connectionConfiguration.CertPath, "/path/to/client/keycert.p12"); Assert.AreEqual(connectionConfiguration.CertPassphrase, "abc123"); }
public void SetUp() { routingTopology = new ConventionalRoutingTopology(true); receivedMessages = new BlockingCollection <IncomingMessage>(); var connectionString = Environment.GetEnvironmentVariable("RabbitMQTransport_ConnectionString"); if (string.IsNullOrEmpty(connectionString)) { throw new Exception("The 'RabbitMQTransport_ConnectionString' environment variable is not set."); } var config = ConnectionConfiguration.Create(connectionString, ReceiverQueue); connectionFactory = new ConnectionFactory(ReceiverQueue, config, default, false, false, default, default);
public static Broker GetBroker() { var connectionString = Environment.GetEnvironmentVariable("RabbitMQTransport_ConnectionString") ?? "host=localhost"; var connectionConfiguration = ConnectionConfiguration.Create(connectionString); string hostName = connectionConfiguration.Host; string username = connectionConfiguration.UserName ?? "guest"; string password = connectionConfiguration.Password ?? "guest"; string virtualHost = connectionConfiguration.VirtualHost ?? "/"; int port = connectionConfiguration.UseTls ? 443 : 15672; return(new Broker { UserName = username, Password = password, VirtualHost = virtualHost, HostName = hostName, Port = port, }); }
void ValidateAndApplyLegacyConfiguration() { if (!legacyMode) { return; } if (TopologyFactory == null) { throw new Exception("A routing topology must be configured with one of the 'EndpointConfiguration.UseTransport<RabbitMQTransport>().UseXXXXRoutingTopology()` methods. Most new projects should use the Conventional routing topology."); } RoutingTopology = TopologyFactory(UseDurableExchangesAndQueues); if (string.IsNullOrEmpty(LegacyApiConnectionString)) { throw new Exception("A connection string must be configured with 'EndpointConfiguration.UseTransport<RabbitMQTransport>().ConnectionString()` method."); } ConnectionConfiguration = ConnectionConfiguration.Create(LegacyApiConnectionString); }
public void SetUp() { routingTopology = new ConventionalRoutingTopology(true); receivedMessages = new BlockingCollection <IncomingMessage>(); var connectionString = Environment.GetEnvironmentVariable("RabbitMQTransport_ConnectionString"); if (string.IsNullOrEmpty(connectionString)) { throw new Exception("The 'RabbitMQTransport_ConnectionString' environment variable is not set."); } var config = ConnectionConfiguration.Create(connectionString, ReceiverQueue); connectionFactory = new ConnectionFactory(ReceiverQueue, config, null, false, false); channelProvider = new ChannelProvider(connectionFactory, config.RetryDelay, routingTopology, true); channelProvider.CreateConnection(); messageDispatcher = new MessageDispatcher(channelProvider); var purger = new QueuePurger(connectionFactory); messagePump = new MessagePump(connectionFactory, new MessageConverter(), "Unit test", channelProvider, purger, TimeSpan.FromMinutes(2), 3, 0); routingTopology.Reset(connectionFactory, new[] { ReceiverQueue }.Concat(AdditionalReceiverQueues), new[] { ErrorQueue }); subscriptionManager = new SubscriptionManager(connectionFactory, routingTopology, ReceiverQueue); messagePump.Init(messageContext => { receivedMessages.Add(new IncomingMessage(messageContext.MessageId, messageContext.Headers, messageContext.Body)); return(TaskEx.CompletedTask); }, ErrorContext => Task.FromResult(ErrorHandleResult.Handled), new CriticalError(_ => TaskEx.CompletedTask), new PushSettings(ReceiverQueue, ErrorQueue, true, TransportTransactionMode.ReceiveOnly) ).GetAwaiter().GetResult(); messagePump.Start(new PushRuntimeSettings(MaximumConcurrency)); }
protected override ConnectionFactory GetBoundValue(BindingContext bindingContext) { var connectionStringOptionValue = bindingContext.ParseResult.GetValueForOption(connectionStringOption); var connectionStringEnvOptionValue = bindingContext.ParseResult.GetValueForOption(connectionStringEnvOption); var certPath = bindingContext.ParseResult.GetValueForOption(certPathOption); var certPassphrase = bindingContext.ParseResult.GetValueForOption(certPassphraseOption); var disableCertificateValidation = bindingContext.ParseResult.GetValueForOption(disableCertificateValidationOption); var useExternalAuth = bindingContext.ParseResult.GetValueForOption(useExternalAuthOption); var connectionString = GetConnectionString(connectionStringOptionValue, connectionStringEnvOptionValue); var connectionConfiguration = ConnectionConfiguration.Create(connectionString); var certificateCollection = new X509Certificate2Collection(); if (certPath != null) { var certificate = new X509Certificate2(certPath, certPassphrase); certificateCollection.Add(certificate); } var connectionFactory = new ConnectionFactory("rabbitmq-transport", connectionConfiguration, certificateCollection, disableCertificateValidation, useExternalAuth, TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(10), new List <(string, int)>()); return(connectionFactory); }
public void Should_parse_the_requestedHeartbeat() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;requestedHeartbeat=5", endpointName); Assert.AreEqual(5, connectionConfiguration.RequestedHeartbeat); }
public void Should_use_explicit_port_setting_over_scheme_default() { var connectionConfiguration = ConnectionConfiguration.Create("amqp://localhost:1234/"); Assert.AreEqual(connectionConfiguration.Port, 1234); }
public void Should_fail_if_host_is_not_present() { Assert.Throws <UriFormatException>(() => ConnectionConfiguration.Create("amqp://:1234/")); }
public void Should_throw_on_malformed_string() { Assert.Throws <ArgumentException>(() => ConnectionConfiguration.Create("not a well formed name value pair;")); }
public void Should_parse_the_virtual_hostname() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;virtualHost=myVirtualHost"); Assert.AreEqual("myVirtualHost", connectionConfiguration.VirtualHost); }
public void Should_parse_the_username() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;username=test"); Assert.AreEqual("test", connectionConfiguration.UserName); }
public void Should_parse_the_port() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;port=8181"); Assert.AreEqual(8181, connectionConfiguration.Port); }
public void Should_parse_the_password() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;password=test"); Assert.AreEqual("test", connectionConfiguration.Password); }
public void Should_fail_if_host_is_not_present() { Assert.Throws <NotSupportedException>(() => ConnectionConfiguration.Create("virtualHost=Copa;username=Copa;password=abc_xyz;port=12345;requestedHeartbeat=3")); }
public void Should_parse_the_cert_path() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;certPath=/path/keyfile.p12", endpointName); Assert.AreEqual("/path/keyfile.p12", connectionConfiguration.CertPath); }
public void Should_parse_the_cert_passphrase() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;certPassphrase=abc123", endpointName); Assert.AreEqual("abc123", connectionConfiguration.CertPassphrase); }
public void Should_parse_the_hostname() { var connectionConfiguration = ConnectionConfiguration.Create("host=myHost"); Assert.AreEqual("myHost", connectionConfiguration.Host); }
public void Should_parse_the_retry_delay() { var connectionConfiguration = ConnectionConfiguration.Create("host=localhost;retryDelay=00:00:10", endpointName); Assert.AreEqual(TimeSpan.FromSeconds(10), connectionConfiguration.RetryDelay); }