【问题标题】:System.TimeoutException: 'The requested operation on PersistentChannel has timed out with EasyNetQSystem.TimeoutException: 'PersistentChannel 上请求的操作已通过 EasyNetQ 超时
【发布时间】:2020-07-06 00:07:05
【问题描述】:

我从 RabbitMq 开始,但在启动我的 API 时遇到问题。发生此错误:System.TimeoutException: 'PersistentChannel 上请求的操作已超时'。

我正在使用 EasyNetQ。

RabbitMq 在配置为设置的 Docker 容器中运行:http:15672 和 ampq:56712。单击此处访问 Rabbitmq,在浏览器中没有任何问题。

下面是设置的代码(现在是硬代码)。根据代码,也尝试传递用户名和密码,但没有成功。

protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
    _bus = RabbitHutch.CreateBus("host=localhost:5672;username=guest;password=guest");

    _bus.RespondAsync<UsuarioRegistradoIntegrationEvent, ResponseMessage>(async request =>
        new ResponseMessage(await RegistrarCliente(request)));

    return Task.CompletedTask;
}

ou

protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
    _bus = RabbitHutch.CreateBus("host=localhost:5672");

    _bus.RespondAsync<UsuarioRegistradoIntegrationEvent, ResponseMessage>(async request =>
        new ResponseMessage(await RegistrarCliente(request)));

    return Task.CompletedTask;
}

ou

protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
    _bus = RabbitHutch.CreateBus("host=localhost");

    _bus.RespondAsync<UsuarioRegistradoIntegrationEvent, ResponseMessage>(async request =>
        new ResponseMessage(await RegistrarCliente(request)));

    return Task.CompletedTask;
}

【问题讨论】:

    标签: asp.net-core rabbitmq easynetq


    【解决方案1】:
    • 您在描述中提到了 AMQP 的非默认端口,请在您的容器中将 56712 更改为 5672(如果适用)
    • 确保每个应用程序实例只调用一次RabbitHutch.CreateBus("host=localhost")(共享实例)。
    • 确保等待所有异步调用:
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _bus = RabbitHutch.CreateBus("host=localhost");
        
            await _bus.RespondAsync<UsuarioRegistradoIntegrationEvent, ResponseMessage>(async request =>
                new ResponseMessage(await RegistrarCliente(request)));
        }
    

    我们缺少 RegistrarCliente(request) 的实现,因此很难发现任何其他问题。

    【讨论】:

    • 您好,感谢您的回复!我将其更改为端口 5672 和相同的持续错误。经过多次测试,我决定将此端口添加到 Windows 防火墙,它最终可以正常工作。我觉得奇怪为什么我在 Stack 或其他地方的任何问题中都没有看到这个解决方案。无论如何,非常感谢兄弟的帮助!
    【解决方案2】:

    通过在防火墙上插入端口 5672 解决了问题。

    【讨论】:

      猜你喜欢
      • 2014-05-17
      • 2013-03-08
      • 2017-07-13
      • 2019-02-14
      • 1970-01-01
      • 2018-06-26
      • 2019-12-22
      • 2011-04-19
      • 2015-10-03
      相关资源
      最近更新 更多