2016-07-14 28 views
0

私はRabbitMQ ConnectionFactoryのAutomaticRecoveryEnabledプロパティをテストしようとしています。私は、ローカルVM上のRabbitMQインスタンスに接続しています。クライアント上では、ループでメッセージを公開しています。問題は、私が意図的に接続を切断した場合、クライアントは永遠に待ってタイムアウトしないことです。タイムアウト値を設定するにはどうすればよいですか? RequestedConnectionTimeoutは効果がないようです。RabbitMQ .NETクライアントと接続タイムアウト

public bool Publish(string routingKey, byte[] body) 
{ 
    try 
    { 
     using (var channel = _connection.CreateModel()) 
     { 
      var basicProps = new BasicProperties 
      { 
       Persistent = true, 
      }; 

      channel.ExchangeDeclare(_exchange, _exchangeType); 
      channel.BasicPublish(_exchange, routingKey, basicProps, body); 

      return true; 
     } 
    } 
    catch (Exception e) 
    { 
     _logger.Log(e); 
    } 

    return false; 
} 

接続し、接続ファクトリー:

// Client is a wrapper around the RabbitMQ client 
for (var i = 0; i < 1000; ++i) 
{ 
    // Publish sequentially numbered messages 
    client.Publish("routingkey", GetContent(i))); 
    Thread.Sleep(100); 
} 

ラッパー内のメソッドを公開:

私はRabbitMQのクライアントを使用しています3.5.4

初歩的なループが公開

_connectionFactory = new ConnectionFactory 
{ 
    UserName = _userName, 
    Password = _password, 
    HostName = _hostName, 
    Port = _port, 
    Protocol = Protocols.DefaultProtocol, 
    VirtualHost = _virtualHost, 

    // Doesn't seem to have any effect on broken connections 
    RequestedConnectionTimeout = 2000, 

    // The behaviour appears to be the same with or without these included 
    // AutomaticRecoveryEnabled = true, 
    // NetworkRecoveryInterval = TimeSpan.FromSeconds(10), 
}; 

_connection = _connectionFactory.CreateConnection(); 

答えて

0

これはバージョン3.5.4のバグです。バージョン3.6.3は無期限に待機しません。

関連する問題