public void TestMultipleOne() { AmqpTcpEndpoint[] es = AmqpTcpEndpoint.ParseMultiple(" host:1234 "); Assert.Single(es); Assert.Equal("host", es[0].HostName); Assert.Equal(1234, es[0].Port); }
public void TestMultipleOne() { AmqpTcpEndpoint[] es = AmqpTcpEndpoint.ParseMultiple(" host:1234 "); Assert.AreEqual(1, es.Length); Assert.AreEqual("host", es[0].HostName); Assert.AreEqual(1234, es[0].Port); }
///<summary>Uses AmqpTcpEndpoint.Parse and .ParseMultiple to ///convert the strings, and then passes them to the other ///overload of the constructor.</summary> public RedirectException(IProtocol protocol, string host, string knownHosts) : this(ParseHost(protocol, host), AmqpTcpEndpoint.ParseMultiple(protocol, knownHosts)) { }
public IConnection CreateConnection() { var connectionString = _configuration.RabbitMqConnectionString; if (connectionString == null) { _logger?.Fatal("Not connection string found for RabbitMQ. Can not create a bus. Aborting..."); throw new ConfigurationErrorsException("Could not find a connection string for RabbitMQ. Please add a connection string in the <connectionStrings> section of the application's configuration file. For example: <add name=\"RabbitMQ\" connectionString=\"host=localhost\" />"); } try { _factory.Uri = new Uri(connectionString); if (_configuration.RabbitMqClusterHosts == null) { _logger?.Verbose("Creating RabbitMQ connection. connection-string={RabbitConnectionString}", _configuration.RabbitMqConnectionString); return(_factory.CreateConnection()); } _logger?.Verbose("Creating RabbitMQ cluster connection. connection-string={RabbitConnectionString}, cluster-hosts={RabbitClusterHosts}", _configuration.RabbitMqConnectionString, _configuration.RabbitMqClusterHosts); return(_factory.CreateConnection(AmqpTcpEndpoint.ParseMultiple(_configuration.RabbitMqClusterHosts))); } catch (Exception ex) { _logger?.Fatal(ex, "Cannot connect to RabbitMQ using the provided configuration."); throw; } }
public void Open(bool insist) { BlockingCell connectionStartCell = new BlockingCell(); m_model0.m_connectionStartCell = connectionStartCell; m_frameHandler.Timeout = HandshakeTimeout; m_frameHandler.SendHeader(); ConnectionStartDetails connectionStart = (ConnectionStartDetails) connectionStartCell.Value; AmqpVersion serverVersion = new AmqpVersion(connectionStart.m_versionMajor, connectionStart.m_versionMinor); if (!serverVersion.Equals(Protocol.Version)) { TerminateMainloop(); FinishClose(); throw new ProtocolVersionMismatchException(Protocol.MajorVersion, Protocol.MinorVersion, serverVersion.Major, serverVersion.Minor); } // FIXME: check that PLAIN is supported. // FIXME: parse out locales properly! ConnectionTuneDetails connectionTune = m_model0.ConnectionStartOk(BuildClientPropertiesTable(), "PLAIN", Encoding.UTF8.GetBytes("\0" + m_parameters.UserName + "\0" + m_parameters.Password), "en_US"); ushort channelMax = (ushort)NegotiatedMaxValue(m_parameters.RequestedChannelMax, connectionTune.m_channelMax); ChannelMax = channelMax; uint frameMax = NegotiatedMaxValue(m_parameters.RequestedFrameMax, connectionTune.m_frameMax); FrameMax = frameMax; ushort heartbeat = (ushort)NegotiatedMaxValue(m_parameters.RequestedHeartbeat, connectionTune.m_heartbeat); Heartbeat = heartbeat; m_model0.ConnectionTuneOk(channelMax, frameMax, heartbeat); string knownHosts = m_model0.ConnectionOpen(m_parameters.VirtualHost, "", // FIXME: make configurable? insist); KnownHosts = AmqpTcpEndpoint.ParseMultiple(Protocol, knownHosts); }
public void TestMultipleTwoMultipleCommas() { AmqpTcpEndpoint[] es = AmqpTcpEndpoint.ParseMultiple(", host:1234,, ,,, other:2345,, "); Assert.AreEqual(2, es.Length); Assert.AreEqual("host", es[0].HostName); Assert.AreEqual(1234, es[0].Port); Assert.AreEqual("other", es[1].HostName); Assert.AreEqual(2345, es[1].Port); }
public static void Start(string hostUri) { factory = new ConnectionFactory() { AutomaticRecoveryEnabled = true, NetworkRecoveryInterval = TimeSpan.FromSeconds(5) }; connection = factory.CreateConnection(AmqpTcpEndpoint.ParseMultiple(ConfigHelper.RabbitMQURI)); }
public static void Start() { factory = new ConnectionFactory() { UserName = ConfigHelper.RabbitUserName, Password = ConfigHelper.RabbitPassword, AutomaticRecoveryEnabled = true, NetworkRecoveryInterval = TimeSpan.FromSeconds(5) }; connection = factory.CreateConnection(AmqpTcpEndpoint.ParseMultiple(ConfigHelper.RabbitMqUri)); }
///<summary>Conservative extension to the spec, supporting ///multiple interfaces in the "host" field of the ///connection.redirect method.</summary> ///<remarks> /// We use ParseMultiple rather than Parse, because a single /// host may have multiple interfaces. The spec doesn't say /// what to do here, so this is a conservative extension (as /// in, if a broker only returns a single address, we handle /// that fine). We arbitrarily take the first element of the /// array. ///</remarks> public static AmqpTcpEndpoint ParseHost(IProtocol protocol, string host) { AmqpTcpEndpoint[] addresses = AmqpTcpEndpoint.ParseMultiple(protocol, host); if (addresses.Length == 0) { return(AmqpTcpEndpoint.Parse(protocol, "")); // ^^ effectively, a (kind of useless) default or null result } else { return(addresses[0]); } }
public virtual void SetAddresses(string addresses) { if (!string.IsNullOrEmpty(addresses)) { var endpoints = AmqpTcpEndpoint.ParseMultiple(addresses); if (endpoints.Length > 0) { Addresses = endpoints.ToList(); if (PublisherConnectionFactory != null) { AbstractPublisherConnectionFactory.SetAddresses(addresses); } return; } } _logger?.LogInformation("SetAddresses() called with an empty value, will be using the host+port properties for connections"); Addresses = null; }
public IConnection CreateConnection() { var connectionString = _configuration.RabbitMqConnectionString; if (connectionString == null) { _logger?.Fatal("Not connection string found for RabbitMQ. Can not create a bus. Aborting..."); throw new ConfigurationErrorsException("Could not find a connection string for RabbitMQ. Please add a connection string in the <connectionStrings> section of the application's configuration file. For example: <add name=\"RabbitMQ\" connectionString=\"host=localhost\" />"); } try { _factory.Uri = new Uri(connectionString); if (!_configuration.LogSensitiveData && !String.IsNullOrWhiteSpace(_factory.Uri.UserInfo)) { connectionString = connectionString.Replace($"{_factory.Uri.UserInfo}@", "*** BLOCKED ***@"); } if (_configuration.RabbitMqAutomaticRecoveryEnabled && _factory is ConnectionFactory connectionFactory) { connectionFactory.AutomaticRecoveryEnabled = true; } if (_configuration.RabbitMqClusterHosts == null) { _logger?.Verbose("Creating RabbitMQ connection. connection-string={RabbitConnectionString}, automatic-recovery-enabled={RabbitAutomaticRecoveryEnabled}", connectionString, _configuration.RabbitMqAutomaticRecoveryEnabled); return(_factory.CreateConnection()); } _logger?.Verbose("Creating RabbitMQ cluster connection. connection-string={RabbitConnectionString}, cluster-hosts={RabbitClusterHosts}, automatic-recovery-enabled={RabbitAutomaticRecoveryEnabled}", connectionString, _configuration.RabbitMqClusterHosts, _configuration.RabbitMqAutomaticRecoveryEnabled); return(_factory.CreateConnection(AmqpTcpEndpoint.ParseMultiple(_configuration.RabbitMqClusterHosts))); } catch (Exception ex) { _logger?.Fatal(ex, "Cannot connect to RabbitMQ using the provided configuration."); throw; } }
public void TestMultipleNone() { AmqpTcpEndpoint[] es = AmqpTcpEndpoint.ParseMultiple(" "); Assert.AreEqual(0, es.Length); }
public void TestMultipleNone() { AmqpTcpEndpoint[] es = AmqpTcpEndpoint.ParseMultiple(" "); Assert.Empty(es); }
public void Open(bool insist) { BlockingCell connectionStartCell = new BlockingCell(); m_model0.m_connectionStartCell = connectionStartCell; m_frameHandler.Timeout = HandshakeTimeout; m_frameHandler.SendHeader(); ConnectionStartDetails connectionStart = (ConnectionStartDetails) connectionStartCell.Value; ServerProperties = connectionStart.m_serverProperties; AmqpVersion serverVersion = new AmqpVersion(connectionStart.m_versionMajor, connectionStart.m_versionMinor); if (!serverVersion.Equals(Protocol.Version)) { TerminateMainloop(); FinishClose(); throw new ProtocolVersionMismatchException(Protocol.MajorVersion, Protocol.MinorVersion, serverVersion.Major, serverVersion.Minor); } m_clientProperties = new Hashtable(m_factory.ClientProperties); // FIXME: check that PLAIN is supported. // FIXME: parse out locales properly! ConnectionTuneDetails connectionTune = default(ConnectionTuneDetails); try { connectionTune = m_model0.ConnectionStartOk(m_clientProperties, "PLAIN", Encoding.UTF8.GetBytes( "\0" + m_factory.UserName + "\0" + m_factory.Password), "en_US"); } catch (OperationInterruptedException e) { throw new PossibleAuthenticationFailureException( "Possibly caused by authentication failure", e); } ushort channelMax = (ushort)NegotiatedMaxValue(m_factory.RequestedChannelMax, connectionTune.m_channelMax); m_sessionManager = new SessionManager(this, channelMax); uint frameMax = NegotiatedMaxValue(m_factory.RequestedFrameMax, connectionTune.m_frameMax); FrameMax = frameMax; ushort heartbeat = (ushort)NegotiatedMaxValue(m_factory.RequestedHeartbeat, connectionTune.m_heartbeat); Heartbeat = heartbeat; m_model0.ConnectionTuneOk(channelMax, frameMax, heartbeat); string knownHosts = m_model0.ConnectionOpen(m_factory.VirtualHost, "", // FIXME: make configurable? insist); KnownHosts = AmqpTcpEndpoint.ParseMultiple(Protocol, knownHosts); }