gpt4 book ai didi

c# - Rabbitmq C# 客户端超时错误

转载 作者:行者123 更新时间:2023-12-05 04:13:29 27 4
gpt4 key购买 nike

以下是在 visual studio 2013 中构建为 Windows 窗体的 Rabbitmq 消费者应用程序的一部分。此窗体连接到在另一个程序中设置的交换并监听通过三个路由键之一发送的消息:“信息”、“错误”和“警告”。用户通过在 Windows 窗体上选中它们然后单击监听按钮来选择他们想要监听的路由键中的哪一个。

private void listenButton_Click(object sender, EventArgs e)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.ExchangeDeclare("direct_logs", "direct");

var queueName = channel.QueueDeclare().QueueName;

if (infoCheckBox.Checked)
{
channel.QueueBind(queueName, "direct_logs", "info");
}
if (errorCheckBox.Checked)
{
channel.QueueBind(queueName, "direct_logs", "error");
}
if (warningCheckBox.Checked)
{
channel.QueueBind(queueName, "direct_logs", "warning");
}

var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
messageTextBox.Text += "\n" + message;
};
channel.BasicConsume(queueName, true, consumer);
}
}

但是,为了能够执行 QueueBind 方法,我需要 queueName。但是程序总是在 var queueName = channel.QueueDeclare().QueueName; 行失败。它总是卡住大约 10 秒,然后出现超时异常。我在控制台应用程序中使用了几乎完全相同的代码。使用 Windows 窗体时,我需要考虑一些不同的地方吗?预先感谢您的帮助。

最佳答案

如果您总是让 RabbitMQ 在 QueueDeclare 上超时,您可能只是遇到了长时间运行的作业的内存问题。正如本 google groups discussion 中所建议的,尝试运行:

rabbitmqctl eval 'rabbit_diagnostics:maybe_stuck().'

此工具仅检查是否有任何作业在特定时间窗口内没有任何堆栈跟踪更改,但可用于查找挂起的作业。如果出现问题,您将得到如下输出:

2017-03-27 13:59:27 There are 269 processes.
2017-03-27 13:59:27 Investigated 9 processes this round, 5000ms to go.
2017-03-27 13:59:28 Investigated 9 processes this round, 4500ms to go.
2017-03-27 13:59:29 Investigated 9 processes this round, 4000ms to go.
2017-03-27 13:59:29 Investigated 9 processes this round, 3500ms to go.
2017-03-27 13:59:30 Investigated 9 processes this round, 3000ms to go.
2017-03-27 13:59:30 Investigated 9 processes this round, 2500ms to go.
2017-03-27 13:59:31 Investigated 9 processes this round, 2000ms to go.
2017-03-27 13:59:31 Investigated 9 processes this round, 1500ms to go.
2017-03-27 13:59:32 Investigated 9 processes this round, 1000ms to go.
2017-03-27 13:59:32 Investigated 9 processes this round, 500ms to go.
2017-03-27 13:59:33 Found 9 suspicious processes.
2017-03-27 13:59:33 [{pid,<10469.54.0>},
{registered_name,user},
{current_stacktrace,
[{user,get_chars,8,[{file,"user.erl"},{line,613}]},
{user,do_io_request,5,
[{file,"user.erl"},{line,183}]},
{user,server_loop,2,[{file,"user.erl"},
etc

我通常只使用 rabbitmqctl stop_apprabbitmqctl start_app 就可以成功清除可疑作业,但您也可以使用

终止特定作业
rabbitmqctl eval 'erlang:exit(c:pid(0,54,0),kill).'

关于c# - Rabbitmq C# 客户端超时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37598214/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com