Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RabbitMQ连接在本地主机上工作,但不是通过网络_C#_Networking_Rabbitmq - Fatal编程技术网

C# RabbitMQ连接在本地主机上工作,但不是通过网络

C# RabbitMQ连接在本地主机上工作,但不是通过网络,c#,networking,rabbitmq,C#,Networking,Rabbitmq,我正在尝试让RabbitMQ服务器工作。本地主机连接在本教程中没有问题。但是,每当我试图通过网络执行同样的操作时,我都无法让应用程序连接到代理 发送: RabbitMQ实例在IP地址为192.168.1.52的其他PC上运行。 RabbitMQ使用的默认端口是5672,我还没有更改用户名或密码,所以它们仍然是guest和guest 收到: var factory = new ConnectionFactory() { }; factory.HostName = "192.168.1.52"; f

我正在尝试让RabbitMQ服务器工作。本地主机连接在本教程中没有问题。但是,每当我试图通过网络执行同样的操作时,我都无法让应用程序连接到代理

发送:

RabbitMQ实例在IP地址为192.168.1.52的其他PC上运行。 RabbitMQ使用的默认端口是5672,我还没有更改用户名或密码,所以它们仍然是guest和guest

收到:

var factory = new ConnectionFactory() { };
factory.HostName = "192.168.1.52";
factory.Port = 5672;
factory.UserName = "guest";
factory.Password = "guest";
factory.VirtualHost = "/";
using (var connection = factory.CreateConnection())
    using (var channel = connection.CreateModel())
    {
        channel.QueueDeclare(queue: "hello",
                             durable: false,
                             exclusive: false,
                             autoDelete: false,
                             arguments: null);

        var consumer = new EventingBasicConsumer(channel);
        consumer.Received += (model, ea) =>
        {
            var body = ea.Body;
            var message = Encoding.UTF8.GetString(body);
            Console.WriteLine(" [x] Received {0}", message);
        };
        channel.BasicConsume(queue: "hello",
                             autoAck: true,
                             consumer: consumer);

        Console.WriteLine(" Press [enter] to exit.");
        Console.ReadLine();
    }
两个程序都会引发异常:

运行程序时引发异常:RabbitMQ.Client.dll中的“RabbitMQ.Client.Exceptions.ConnectFailureException”

但它并没有打破这条线。一段时间后,威胁退出,并出现以下错误:

ExtendedSocketException:连接尝试失败,因为连接方在某一时间后没有正确响应,或者连接失败,因为连接的主机没有响应。192.168.1.52:5672


问题可能是你的防火墙。[RabbitMQ提供了一些关于如何正确配置防火墙的文档,以便您不必完全关闭它]()

以下是链路损坏情况下的概述:

Port Access

RabbitMQ nodes bind to ports (open server TCP sockets) in order to accept client and CLI tool connections. Other processes and tools such as SELinux may prevent RabbitMQ from binding to a port. When that happens, the node will fail to start.

CLI tools, client libraries and RabbitMQ nodes also open connections (client TCP sockets). Firewalls can prevent nodes and CLI tools from communicating with each other. Make sure the following ports are accessible:

    4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
    5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
    25672: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). Unless external connections on these ports are really necessary (e.g. the cluster uses federation or CLI tools are used on machines outside the subnet), these ports should not be publicly exposed. See networking guide for details.
    35672-35682: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as server distribution port + 10000 through server distribution port + 10010). See networking guide for details.
    15672: HTTP API clients, management UI and rabbitmqadmin (only if the management plugin is enabled)
    61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled)
    1883, 8883: (MQTT clients without and with TLS, if the MQTT plugin is enabled
    15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
    15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
    15692: Prometheus metrics (only if the Prometheus plugin is enabled)

It is possible to configure RabbitMQ to use different ports and specific network interfaces.

问题可能是你的防火墙。[RabbitMQ提供了一些关于如何正确配置防火墙的文档,以便您不必完全关闭它]()

以下是链路损坏情况下的概述:

Port Access

RabbitMQ nodes bind to ports (open server TCP sockets) in order to accept client and CLI tool connections. Other processes and tools such as SELinux may prevent RabbitMQ from binding to a port. When that happens, the node will fail to start.

CLI tools, client libraries and RabbitMQ nodes also open connections (client TCP sockets). Firewalls can prevent nodes and CLI tools from communicating with each other. Make sure the following ports are accessible:

    4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
    5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
    25672: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). Unless external connections on these ports are really necessary (e.g. the cluster uses federation or CLI tools are used on machines outside the subnet), these ports should not be publicly exposed. See networking guide for details.
    35672-35682: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as server distribution port + 10000 through server distribution port + 10010). See networking guide for details.
    15672: HTTP API clients, management UI and rabbitmqadmin (only if the management plugin is enabled)
    61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled)
    1883, 8883: (MQTT clients without and with TLS, if the MQTT plugin is enabled
    15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
    15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
    15692: Prometheus metrics (only if the Prometheus plugin is enabled)

It is possible to configure RabbitMQ to use different ports and specific network interfaces.

您需要创建一个新的用户帐户,默认的来宾帐户仅限于localhost。

您需要创建一个新的用户帐户,默认的来宾帐户仅限于localhost。

我刚刚遇到了同样的问题

杜仁良是部分正确的。这是您需要做的:

  • 首先,您需要启用RabbitMq管理

    rabbitmq插件支持rabbitmq_管理

  • 其次,您需要为rabbitmq_管理创建一个帐户,Guest没有足够的权限

  • 第三,您需要将防火墙配置为通过5672端口或您设置的端口接收消息


所有最好的和快乐的编码。

我也有同样的问题

杜仁良是部分正确的。这是您需要做的:

  • 首先,您需要启用RabbitMq管理

    rabbitmq插件支持rabbitmq_管理

  • 其次,您需要为rabbitmq_管理创建一个帐户,Guest没有足够的权限

  • 第三,您需要将防火墙配置为通过5672端口或您设置的端口接收消息


所有最好和快乐的编码。

愚蠢的问题,但你检查过防火墙设置吗?我不认为这是一个愚蠢的问题,可能是罪魁祸首。干杯,伙计们,这似乎有帮助。几个后续问题。我试图在允许的应用程序列表中找到RabbitMQ之外的实例,但没有一个实例只是简单地称为RabbitMQ。然而,我确实找到了erl(我相信它是需要被允许的()),但我已经允许了它。但在临时关闭防火墙之后,它确实抛出了一个不同的错误,我将尝试解决这个问题next@Titulum这绝对是问题所在。在解决了下一个错误(这是使用guest登录引起的)之后,我能够创建一个连接并发送一条消息。你知道我需要什么应用程序来添加防火墙接受列表,以便在不关闭防火墙的情况下实现这一点吗?愚蠢的问题,但你检查过防火墙设置吗?我不认为这是一个愚蠢的问题,可能是罪魁祸首。干杯,伙计们,这似乎有帮助。几个后续问题。我试图在允许的应用程序列表中找到RabbitMQ之外的实例,但没有一个实例只是简单地称为RabbitMQ。然而,我确实找到了erl(我相信它是需要被允许的()),但我已经允许了它。但在临时关闭防火墙之后,它确实抛出了一个不同的错误,我将尝试解决这个问题next@Titulum这绝对是问题所在。在解决了下一个错误(这是使用guest登录引起的)之后,我能够创建一个连接并发送一条消息。你知道我需要什么应用程序来添加防火墙接受列表,以便在不关闭防火墙的情况下实现这一点吗?虽然你完全正确(我现在已经解决了这个问题),但我会将@Titulum的答案标记为正确答案,但也会在那里发表评论,指出你的答案。因为这也是我在解决问题中描述的问题后遇到的一个问题。谢谢你的回答!虽然你完全正确(我现在已经解决了这个问题),但我会将@Titulum的答案标注为正确答案,并在这里发表评论,指出你的答案。因为这也是我在解决问题中描述的问题后遇到的一个问题。谢谢你的回答!如果这个答案解决了这个问题,你能接受吗?另外,我犯的错误是使用了@Tu-Jen-Liang answer指出的预制来宾帐户。所以,如果其他人有类似的问题,我们也要检查一下!如果这个答案解决了这个问题,你能接受吗?另外,我犯的错误是使用了@Tu-Jen-Liang answer指出的预制来宾帐户。所以,如果其他人有类似的问题,我们也要检查一下!