public void FailoverURL()
        {
            //String url = "amqp://*****:*****@/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'";
            String url = "amqp://*****:*****@default/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.AreEqual("roundrobin", connectionurl.FailoverMethod);
            Assert.IsTrue(connectionurl.Username.Equals("ritchiem"));
            Assert.IsTrue(connectionurl.Password.Equals("bob"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));

            Assert.IsTrue(connectionurl.BrokerCount == 2);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);

            service = connectionurl.GetBrokerInfo(1);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("fancyserver"));
            Assert.IsTrue(service.Port == 3000);
        }
        public void SetBroker(IBrokerInfo broker)
        {
            if (broker == null)
            {
                throw new ArgumentException("BrokerInfo details cannot be null");
            }
            _brokerDetail = broker;

            String retries = broker.GetOption(BrokerInfoConstants.OPTIONS_RETRY);

            if (retries != null)
            {
                try
                {
                    _retries = int.Parse(retries);
                }
                catch (FormatException)
                {
                    _retries = DEFAULT_SERVER_RETRIES;
                }
            }
            else
            {
                _retries = DEFAULT_SERVER_RETRIES;
            }

            Reset();
        }
 public void AddBrokerInfo(IBrokerInfo brokerInfo)
 {
     if (!_brokerInfos.Contains(brokerInfo))
     {
         _brokerInfos.Add(brokerInfo);
     }
 }
        public void CheckDefaultPort()
        {
            String url = "amqp://*****:*****@default/test=:?brokerlist='tcp://localhost'";

            IConnectionInfo connection = QpidConnectionInfo.FromUrl(url);

            IBrokerInfo broker = connection.GetBrokerInfo(0);

            Assert.IsTrue(broker.Port == BrokerInfoConstants.DEFAULT_PORT);
        }
        public override bool Equals(object obj)
        {
            if (!(obj is IBrokerInfo))
            {
                return(false);
            }

            IBrokerInfo bd = (IBrokerInfo)obj;

            return(StringEqualsIgnoreCase(_host, bd.Host) &&
                   _port == bd.Port &&
                   StringEqualsIgnoreCase(_transport, bd.Transport) &&
                   UseSSL == bd.UseSSL);
        }
Exemple #6
0
        private IoHandler MakeBrokerConnection(IBrokerInfo broker, AMQConnection connection)
        {
            if (broker.UseSSL)
            {
                _connector = new SslSocketConnector();
            }
            else
            {
                _connector = new SocketConnector();
            }

            Stream stream = _connector.Connect(broker);

            return(new IoHandler(stream, connection.ProtocolListener));
        }
 private static MCertificate GetClientCert(IBrokerInfo broker)
 {
    // if a client certificate is configured, 
    // use that to enable mutual authentication
    MCertificate cert = null;
    if ( broker.SslOptions != null 
       && broker.SslOptions.ClientCertificate != null )
    {
       cert = MCertificate.CreateFromX509Certificate(
          broker.SslOptions.ClientCertificate
          );
       _logger.DebugFormat("Using Client Certificate for SSL '{0}'", cert.ToString(true));
    }
    return cert;
 }
Exemple #8
0
        private static MCertificate GetClientCert(IBrokerInfo broker)
        {
            // if a client certificate is configured,
            // use that to enable mutual authentication
            MCertificate cert = null;

            if (broker.SslOptions != null &&
                broker.SslOptions.ClientCertificate != null)
            {
                cert = MCertificate.CreateFromX509Certificate(
                    broker.SslOptions.ClientCertificate
                    );
                _logger.DebugFormat("Using Client Certificate for SSL '{0}'", cert.ToString(true));
            }
            return(cert);
        }
      public Stream Connect(IBrokerInfo broker)
      {
         MCertificate cert = GetClientCert(broker);
         SecurityOptions options = new SecurityOptions(
            SecureProtocol.Tls1, cert, ConnectionEnd.Client
            );
         if ( broker.SslOptions != null 
            && broker.SslOptions.IgnoreValidationErrors )
         {
            _logger.Warn("Ignoring any certificate validation errors during SSL handshake...");
            options.VerificationType = CredentialVerification.None;
         }

         _tcpClient = new MyTcpClient(broker.Host, broker.Port, options);
         return _tcpClient.GetStream();
      }
      /// <summary>
      /// Connect to the specified broker
      /// </summary>
      /// <param name="broker">The broker to connect to</param>
      /// <param name="connection">The AMQ connection</param>
      public void Connect(IBrokerInfo broker, AMQConnection connection)
      {
         _stopEvent = new ManualResetEvent(false);
         _protocolListener = connection.ProtocolListener;

         _ioHandler = MakeBrokerConnection(broker, connection);
         // todo: get default read size from config!

         IProtocolDecoderOutput decoderOutput =
            new ProtocolDecoderOutput(_protocolListener);
         _amqpChannel = 
            new AmqpChannel(new ByteChannel(_ioHandler), decoderOutput);

         // post an initial async read
         _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), this);
      }
        public AMQConnection(IConnectionInfo connectionInfo)
        {
            if (connectionInfo == null)
            {
                throw new ArgumentException("ConnectionInfo must be specified");
            }
            _log.Debug("ConnectionInfo: " + connectionInfo);
            _connectionInfo = connectionInfo;
            _log.Debug("password = "******"Connecting to " + brokerInfo);
                    MakeBrokerConnection(brokerInfo);
                    break;
                }
                catch (Exception e)
                {
                    lastException = e;
                    _log.Error("Unable to connect to broker " + _failoverPolicy.GetCurrentBrokerInfo(), e);
                    // XXX: Should perhaps break out of the do/while here if not a SocketException...
                }
            } while (!_connected && _failoverPolicy.FailoverAllowed());

            _log.Debug("Are we connected:" + _connected);

            if (!_connected)
            {
                if (lastException is AMQException)
                {
                    throw lastException;
                }
                else
                {
                    throw new AMQConnectionException("Unable to connect", lastException);
                }
            }
        }
Exemple #12
0
        public Stream Connect(IBrokerInfo broker)
        {
            MCertificate    cert    = GetClientCert(broker);
            SecurityOptions options = new SecurityOptions(
                SecureProtocol.Tls1, cert, ConnectionEnd.Client
                );

            if (broker.SslOptions != null &&
                broker.SslOptions.IgnoreValidationErrors)
            {
                _logger.Warn("Ignoring any certificate validation errors during SSL handshake...");
                options.VerificationType = CredentialVerification.None;
            }

            _tcpClient = new MyTcpClient(broker.Host, broker.Port, options);
            return(_tcpClient.GetStream());
        }
Exemple #13
0
        /// <summary>
        /// Connect to the specified broker
        /// </summary>
        /// <param name="broker">The broker to connect to</param>
        /// <param name="connection">The AMQ connection</param>
        public void Connect(IBrokerInfo broker, AMQConnection connection)
        {
            _stopEvent        = new ManualResetEvent(false);
            _protocolListener = connection.ProtocolListener;

            _ioHandler = MakeBrokerConnection(broker, connection);
            // todo: get default read size from config!

            IProtocolDecoderOutput decoderOutput =
                new ProtocolDecoderOutput(_protocolListener);

            _amqpChannel =
                new AmqpChannel(new ByteChannel(_ioHandler), decoderOutput);

            // post an initial async read
            _amqpChannel.BeginRead(new AsyncCallback(OnAsyncReadDone), this);
        }
Exemple #14
0
        public async Task ShouldReceiveResponseAsExpected()
        {
            // given
            TopologyResponse expectedResponse = new TopologyResponse();

            expectedResponse.Brokers.Add(CreateBrokerInfo(0, "host", 26501, 0, true));
            expectedResponse.Brokers.Add(CreateBrokerInfo(1, "host", 26501, 0, false));
            expectedResponse.Brokers.Add(CreateBrokerInfo(2, "host", 26501, 0, false));
            TestService.AddRequestHandler(typeof(TopologyRequest), (request) => expectedResponse);

            // when
            ITopology response = await ZeebeClient.TopologyRequest().Send();

            // then
            IBrokerInfo firstBroker = response.Brokers[0];

            Assert.AreEqual("host0:26501", firstBroker.Address);
            Assert.AreEqual(0, firstBroker.NodeId);

            IPartitionInfo firstPartition = firstBroker.Partitions[0];

            Assert.AreEqual(0, firstPartition.PartitionId);
            Assert.AreEqual(PartitionBrokerRole.LEADER, firstPartition.Role);


            IBrokerInfo secondBroker = response.Brokers[1];

            Assert.AreEqual("host1:26501", secondBroker.Address);
            Assert.AreEqual(1, secondBroker.NodeId);

            firstPartition = secondBroker.Partitions[0];
            Assert.AreEqual(0, firstPartition.PartitionId);
            Assert.AreEqual(PartitionBrokerRole.FOLLOWER, firstPartition.Role);


            IBrokerInfo thirdBroker = response.Brokers[2];

            Assert.AreEqual("host2:26501", thirdBroker.Address);
            Assert.AreEqual(2, thirdBroker.NodeId);

            firstPartition = thirdBroker.Partitions[0];
            Assert.AreEqual(0, firstPartition.PartitionId);
            Assert.AreEqual(PartitionBrokerRole.FOLLOWER, firstPartition.Role);
        }
        public void SinglevmURL()
        {
            String url = "amqp://*****:*****@default/messages?brokerlist='vm://default:2'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("guest"));
            Assert.IsTrue(connectionurl.Password.Equals("guest"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/messages"));

            Assert.IsTrue(connectionurl.BrokerCount == 1);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("vm"));
            Assert.AreEqual("localhost", service.Host);
            Assert.AreEqual(2, service.Port);
        }
        public void SingleTransportUsernameBlankPasswordURL()
        {
            String url = "amqp://ritchiem:@default/temp?brokerlist='tcp://localhost:5672'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("ritchiem"));
            Assert.IsTrue(connectionurl.Password.Equals(""));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));

            Assert.IsTrue(connectionurl.BrokerCount == 1);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);
        }
        private void MakeBrokerConnection(IBrokerInfo brokerDetail)
        {
            try
            {
                _stateManager     = new AMQStateManager();
                _protocolListener = new AMQProtocolListener(this, _stateManager);
                _protocolListener.AddFrameListener(_stateManager);

                /*
                 * // Currently there is only one transport option - BlockingSocket.
                 * String assemblyName = "Apache.Qpid.Client.Transport.Socket.Blocking.dll";
                 * String transportType = "Apache.Qpid.Client.Transport.Socket.Blocking.BlockingSocketTransport";
                 *
                 * // Load the transport assembly dynamically.
                 * _transport = LoadTransportFromAssembly(brokerDetail.getHost(), brokerDetail.getPort(), assemblyName, transportType);
                 */

                _transport = new BlockingSocketTransport();

                // Connect.
                _transport.Connect(brokerDetail, this);
                _protocolWriter  = new ProtocolWriter(_transport.ProtocolWriter, _protocolListener);
                _protocolSession = new AMQProtocolSession(_transport.ProtocolWriter, _transport, this);
                _protocolListener.ProtocolSession = _protocolSession;

                // Now start the connection "handshake".
                _transport.ProtocolWriter.Write(new ProtocolInitiation());

                // Blocks until the connection has been opened.
                _stateManager.AttainState(AMQState.CONNECTION_OPEN);

                _failoverPolicy.attainedConnection();

                // XXX: Again this should be changed to a suitable notify.
                _connected = true;
            }
            catch (AMQException e)
            {
                _lastAMQException = e;
                throw; // rethrow
            }
        }
        public void SingleTransport1OptionURL()
        {
            String url = "amqp://*****:*****@default/temp?brokerlist='tcp://localhost:5672',routingkey='jim'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("guest"));
            Assert.IsTrue(connectionurl.Password.Equals("guest"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));


            Assert.IsTrue(connectionurl.BrokerCount == 1);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));

            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);
            Assert.IsTrue(connectionurl.GetOption("routingkey").Equals("jim"));
        }
        public void SingleTransportWithClientURLURL()
        {
            String url = "amqp://*****:*****@clientname/temp?brokerlist='tcp://localhost:5672'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);


            Assert.IsTrue(connectionurl.FailoverMethod == null);
            Assert.IsTrue(connectionurl.Username.Equals("guest"));
            Assert.IsTrue(connectionurl.Password.Equals("guest"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));
            Assert.IsTrue(connectionurl.ClientName.Equals("clientname"));


            Assert.IsTrue(connectionurl.BrokerCount == 1);


            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("tcp"));
            Assert.IsTrue(service.Host.Equals("localhost"));
            Assert.IsTrue(service.Port == 5672);
        }
        public void SetBroker(IBrokerInfo broker)
        {
            _connectionDetails.AddBrokerInfo(broker);

            int index = _connectionDetails.GetAllBrokerInfos().IndexOf(broker);

            String serverRetries = broker.GetOption(BrokerInfoConstants.OPTIONS_RETRY);

            if (serverRetries != null)
            {
                try
                {
                    _serverRetries = int.Parse(serverRetries);
                }
                catch (FormatException)
                {
                    _serverRetries = DEFAULT_SERVER_RETRIES;
                }
            }

            _currentServerRetry = -1;
            _currentBrokerIndex = index;
        }
        public void FailoverVMURL()
        {
            String url = "amqp://*****:*****@default/temp?brokerlist='vm://default:2;vm://default:3',failover='roundrobin'";

            IConnectionInfo connectionurl = QpidConnectionInfo.FromUrl(url);

            Assert.IsTrue(connectionurl.FailoverMethod.Equals("roundrobin"));
            Assert.IsTrue(connectionurl.Username.Equals("ritchiem"));
            Assert.IsTrue(connectionurl.Password.Equals("bob"));
            Assert.IsTrue(connectionurl.VirtualHost.Equals("/temp"));

            Assert.AreEqual(2, connectionurl.BrokerCount);

            IBrokerInfo service = connectionurl.GetBrokerInfo(0);

            Assert.IsTrue(service.Transport.Equals("vm"));
            Assert.AreEqual("localhost", service.Host);
            Assert.IsTrue(service.Port == 2);

            service = connectionurl.GetBrokerInfo(1);
            Assert.IsTrue(service.Transport.Equals("vm"));
            Assert.AreEqual("localhost", service.Host);
            Assert.IsTrue(service.Port == 3);
        }
        public void SetBroker(IBrokerInfo broker)
        {
            if (broker == null)
            {
                throw new ArgumentException("BrokerInfo details cannot be null");
            }
            _brokerDetail = broker;

            String retries = broker.GetOption(BrokerInfoConstants.OPTIONS_RETRY);
            if (retries != null)
            {
                try
                {
                    _retries = int.Parse(retries);
                }
                catch (FormatException)
                {
                    _retries = DEFAULT_SERVER_RETRIES;
                }
            }
            else
            {
                _retries = DEFAULT_SERVER_RETRIES;
            }

            Reset();
        }
 public FailoverSingleServer(IBrokerInfo brokerDetail)
 {
     SetBroker(brokerDetail);
 }
 public void setBroker(IBrokerInfo broker)
 {
     _methods[_currentMethod].SetBroker(broker);
 }
Exemple #25
0
        private void MakeBrokerConnection(IBrokerInfo brokerDetail)
        {
            try
            {
                _stateManager = new AMQStateManager();
                _protocolListener = new AMQProtocolListener(this, _stateManager);
                _protocolListener.AddFrameListener(_stateManager);

                /*
                // Currently there is only one transport option - BlockingSocket.
                String assemblyName = "Apache.Qpid.Client.Transport.Socket.Blocking.dll";
                String transportType = "Apache.Qpid.Client.Transport.Socket.Blocking.BlockingSocketTransport";

                // Load the transport assembly dynamically.
                _transport = LoadTransportFromAssembly(brokerDetail.getHost(), brokerDetail.getPort(), assemblyName, transportType);
                */

                _transport = new BlockingSocketTransport();
                
                // Connect.
                _transport.Connect(brokerDetail, this);                
                _protocolWriter = new ProtocolWriter(_transport.ProtocolWriter, _protocolListener);
                _protocolSession = new AMQProtocolSession(_transport.ProtocolWriter, _transport, this);
                _protocolListener.ProtocolSession = _protocolSession;

                // Now start the connection "handshake".
                _transport.ProtocolWriter.Write(new ProtocolInitiation());

                // Blocks until the connection has been opened.
                _stateManager.AttainState(AMQState.CONNECTION_OPEN);

                _failoverPolicy.attainedConnection();

                // XXX: Again this should be changed to a suitable notify.
                _connected = true;
            }
            catch (AMQException e)
            {
                _lastAMQException = e;
                throw; // rethrow
            }
        }
        public void SetBroker(IBrokerInfo broker)
        {
            _connectionDetails.AddBrokerInfo(broker);

            int index = _connectionDetails.GetAllBrokerInfos().IndexOf(broker);

            String serverRetries = broker.GetOption(BrokerInfoConstants.OPTIONS_RETRY);

            if (serverRetries != null)
            {
                try
                {
                    _serverRetries = int.Parse(serverRetries);
                }
                catch (FormatException)
                {
                    _serverRetries = DEFAULT_SERVER_RETRIES;
                }
            }

            _currentServerRetry = -1;
            _currentBrokerIndex = index;
        }
 public void setBroker(IBrokerInfo broker)
 {
     _methods[_currentMethod].SetBroker(broker);
 }
 public Stream Connect(IBrokerInfo broker)
 {
    _tcpClient = new MyTcpClient(broker.Host, broker.Port);
    return _tcpClient.GetStream();
 }
      private IoHandler MakeBrokerConnection(IBrokerInfo broker, AMQConnection connection)
      {
         if ( broker.UseSSL )
         {
            _connector = new SslSocketConnector();
         } else
         {
            _connector = new SocketConnector();
         }

         Stream stream = _connector.Connect(broker);
         return new IoHandler(stream, connection.ProtocolListener);
      }
Exemple #30
0
 public Stream Connect(IBrokerInfo broker)
 {
     _tcpClient = new MyTcpClient(broker.Host, broker.Port);
     return(_tcpClient.GetStream());
 }
 public FailoverSingleServer(IBrokerInfo brokerDetail)
 {
     SetBroker(brokerDetail);
 }