Esempio n. 1
0
        private void HandleConnectionException(Exception ex)
        {
            _watcher.ErrorFormat("连接主机失败:{0},Host:{1},尝试 {2} 秒后重试.ExceptionMessage:{3}",
                                 ConnectionFactory.HostName,
                                 ConnectionFactory.VirtualHost,
                                 _retryPolicy.DelayTime,
                                 ex.Message);

            _retryPolicy.WaitForNextRetry(Connect);
        }
Esempio n. 2
0
        private void HandleConnectionException(Exception ex)
        {
            _watcher.ErrorFormat("Failed to connect to Broker: '{0}', VHost: '{1}'. Retrying in {2} ms\n" +
                                 "Check HostName, VirtualHost, Username and Password.\n" +
                                 "ExceptionMessage: {3}",
                                 ConnectionFactory.HostName,
                                 ConnectionFactory.VirtualHost,
                                 _retryPolicy.DelayTime,
                                 ex.Message);

            _retryPolicy.WaitForNextRetry(Connect);
        }
Esempio n. 3
0
        private void HandleConnectionException(Exception ex)
        {
            var oldFactory  = ConnectionFactory;
            var nextFactory = _connectionFactories.GetNext();

            if (++_nodeTried < _connectionFactories.All.Count())
            {
                _watcher.ErrorFormat("Failed to connect to Broker: '{0}:{1}', VHost: '{2}'. Failing over to '{3}:{4}'\nExceptionMessage: {5}",
                                     oldFactory.HostName,
                                     oldFactory.Port,
                                     oldFactory.VirtualHost,
                                     nextFactory.HostName,
                                     nextFactory.Port,
                                     ex.Message);
                Connect();
            }
            else
            {
                _watcher.ErrorFormat("Failed to connect to Broker: '{0}:{1}', VHost: '{2}'. Failing over to '{3}{4}' after {5}ms\nExceptionMessage: {6}",
                                     oldFactory.HostName,
                                     oldFactory.Port,
                                     oldFactory.VirtualHost,
                                     nextFactory.HostName,
                                     nextFactory.Port,
                                     _retryPolicy.DelayTime,
                                     ex.Message);
                _retryPolicy.WaitForNextRetry(Connect);
            }
        }
Esempio n. 4
0
        public void Connect()
        {
            try
            {
                lock (_syncConnection)
                {
                    if (IsConnected || _retryPolicy.IsWaiting)
                    {
                        return;
                    }

                    _watcher.DebugFormat("Trying to connect to endpoint: {0}", ConnectionFactory.Endpoint);
                    var newConnection = ConnectionFactory.CreateConnection();
                    newConnection.ConnectionShutdown += SharedConnectionShutdown;
                    //Console.WriteLine(ConnectionFactory.Endpoint + ConnectionFactory.VirtualHost);
                    SharedConnections.Add(ConnectionFactory.Endpoint + ConnectionFactory.VirtualHost, newConnection);
                    if (Connected != null)
                    {
                        Connected();
                    }

                    _retryPolicy.Reset();
                    _watcher.InfoFormat("Connected to RabbitMQ. Broker: '{0}', VHost: '{1}'", ConnectionFactory.Endpoint, ConnectionFactory.VirtualHost);
                }
            }
            catch (BrokerUnreachableException brokerUnreachableException)
            {
                _watcher.ErrorFormat("Failed to connect to Broker: '{0}', VHost: '{1}'. Retrying in {2} ms\n" +
                                     "Check HostName, VirtualHost, Username and Password.\n" +
                                     "ExceptionMessage: {3}",
                                     ConnectionFactory.HostName,
                                     ConnectionFactory.VirtualHost,
                                     _retryPolicy.DelayTime,
                                     brokerUnreachableException.Message);

                _retryPolicy.WaitForNextRetry(Connect);
            }
        }