我试图测试RabbitMQ ConnectionFactory的AutomaticRecoveryEnabled
属性。我连接到本地VM上的RabbitMQ实例,并且在客户端上我在循环中发布消息。问题是如果我故意断开连接,客户端就会永远等待并且不会超时。如何设置超时值? RequestedConnectionTimeout
似乎没有任何效果。
我正在使用RabbitMQ客户端3.5.4
基本发布循环:
// 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);
}
包装器中的Publish方法:
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;
}
连接和连接工厂:
_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 :(得分:0)
这似乎是版本3.5.4中的错误。版本3.6.3不会无限期等待。