RabbitMQ在创建连接时抛出异常。

huangapple go评论97阅读模式
英文:

RabbitMQ throws exception when creating connection

问题

我目前正在尝试实现RabbitMQ,但在尝试创建连接时遇到了以下错误:

> 执行了 'GS1Fetcher' (失败,
> Id=4c77f28d-12e0-4a71-a9d3-69e38d41564d,持续时间=137毫秒)
> [2023-06-21T17:15:39.447Z] System.Private.CoreLib: 在执行函数时发生异常:GS1Fetcher. RabbitMQ.Client: 未能到达指定的任何端点。RabbitMQ.Client: 无法加载文件或程序集 'System.Threading.Channels, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'。系统找不到指定的文件。

RabbitMQ 在本地以 Docker 容器方式运行。我检查了所需端口(5672)是否打开,根据我的发现,只有 5674 端口是打开的,但这应该没问题,对吧?我通过在 Windows 命令提示符中运行 docker ps 来进行检查,结果如下:

| CONTAINER ID | IMAGE                        | COMMAND                 | PORTS                                                                                     | NAMES            |
|--------------|------------------------------|-------------------------|-------------------------------------------------------------------------------------------|-----------------|
| 38fc3c343af4 | rabbitmq:management-alpine    | "docker-entrypoint.s…"   | 4369/tcp, 5671/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, 0.0.0.0:5674->5672/tcp   | trusting_keldysh |

下面的代码示例展示了我的代码实现。这是一个使用 .NET 6 的 Azure 函数:

_factory = new ConnectionFactory() { HostName = "localhost" };
_factory.UserName = "****";
_factory.Password = "****";
_factory.Port = 5674;
_conn = _factory.CreateConnection();

我对如何解决这个异常感到困惑。我的发现端口打开的情况是否不正确?我是否错过了 Docker 的某些其他设置/配置?或者我是否在 RabbitMQ 配置中漏掉了一些内容?

英文:

I am currently trying to implement rabbitMQ, but when trying to create a connection I get the following error:

> Executed 'GS1Fetcher' (Failed,
> Id=4c77f28d-12e0-4a71-a9d3-69e38d41564d, Duration=137ms)
> [2023-06-21T17:15:39.447Z] System.Private.CoreLib: Exception while
> executing function: GS1Fetcher. RabbitMQ.Client: None of the specified
> endpoints were reachable. RabbitMQ.Client: Could not load file or
> assembly 'System.Threading.Channels, Version=7.0.0.0, Culture=neutral,
> PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file
> specified.

RabbitMQ is running locally in a docker container. I checked if the required port (5672) is open, which according to my findings is open only under 5674, but that must be no problem right? The way I checked this is by running docker ps in my windows command prompt. Which resulted in the following;

CONTAINER ID IMAGE COMMAND PORTS NAMES
38fc3c343af4 rabbitmq:management-alpine "docker-entrypoint.s…" 4369/tcp, 5671/tcp, 15671/tcp, 15691-15692/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp, 0.0.0.0:5674->5672/tcp trusting_keldysh

The code sammple below shows my code implementation. This is an Azure function using .NET 6

_factory = new ConnectionFactory() { HostName = "localhost" };
_factory.UserName = "****";
_factory.Password = "****";
_factory.Port = 5674;
_conn = _factory.CreateConnection();

I am left dumbfound what I can still do to fix this exception. Are my findings that the port are open incorrect? is there some other setting/configuration for docker that I missed? Or did I miss some configuration on the rabbitMQ side

答案1

得分: 1

我已找到为什么会发生这个错误的答案。 看起来 rabbitMQ nugetpackage 的版本 6.5.0 没有向后兼容性(这就是我使用的版本)。

所以如果你在使用 .NET 6 或更低版本,请使用低于 6.5.0 的 rabbitMQ Nugetpackage 版本。 对于 .NET 7,你可以使用版本 6.5.0 的包。

他们在版本 6.5.0 中更新了一个依赖项 'System.Threading.Channels',从 4.7.1 更新到了 7.0.0。 由于前者在 .NET 6 中不可用,因此我遇到了错误。

感谢这篇帖子,它把我和我的同事引向了正确的方向 连接到 Azure Function 的 RabbitMQ 出现问题

英文:

I have found the answer to why this error occured.
It seems that the rabbitMQ nugetpackage with version 6.5.0 has no backwards compatability (which was the version I was using).

So if you are using .NET 6 or below. Make use a rabbitMQ Nugetpackage version lower then 6.5.0. For .NET 7 you can use package version 6.5.0.

They have updated one of their dependencies in version 6.5.0 'System.Threading.Channels' to 7.0.0 from 4.7.1. The former is not available in .NET 6 hence I get the error that occured

Thanks to this post for nudging my collegue and I in the right direction Issues connecting to RabbitMQ from an Azure Function

huangapple
  • 本文由 发表于 2023年6月22日 01:43:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525906.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定