AWS RabbitMQ none 个端点可访问 C#

AWS RabbitMQ none of the endpoints were reachable C#

我正在学习使用 RabbitMQ,我正在 Visual Studio 上为 Mac 创建一个 C# 控制台项目。

我已经在 Amazon AWS 上创建了一个 RabbitMQ 服务器,但是每次我尝试连接时,我都会收到错误消息“none of the endpoints were reachable”;这是我的代码:

using System;
using System.Text;
using RabbitMQ.Client;

namespace Producer
{
    class Sender
    {
        public static void Main(string[] args)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "mq.ap-southeast-1.amazonaws.com",
                Port = 5671,
                UserName = "username",
                Password = "password"
            };

            

            using(var connection = factory.CreateConnection())

            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare("BasicTest", false, false, false, null);

                string message = "Getting Started with .net Core RabbitMQ";

                var body = Encoding.UTF8.GetBytes(message);

                channel.BasicPublish("", "BasicTest", null, body);
                Console.WriteLine("Message Sent: {0}", message);
            }

            Console.WriteLine("Press Enter to Exit");
            Console.ReadLine();
        }
    }
}

关于我无法访问 AWS 的原因有什么想法吗?

您似乎还需要输入同样由 AWS 提供的端点 URI,并指定启用 SSL。我在打开连接之前添加了以下代码:

Uri uri = new Uri("amqps://mq.ap-southeast-1.amazonaws.com:5671");
factory.Ssl.Enabled = true;
factory.Uri = uri;