I am learning to use RabbitMQ, I am creating a C# console project on Visual Studio for Mac.
I've created a RabbitMQ server on Amazon AWS however every time I try to connect I get the error "none of the endpoints were reachable"; here's my code:
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();
}
}
}
Any ideas on why I can't reach AWS?
it looks like you also need to enter the endpoint URI that is also provided by AWS and specify that SSL is Enabled. I've added the following code before opening the connection:
Uri uri = new Uri("amqps://mq.ap-southeast-1.amazonaws.com:5671");
factory.Ssl.Enabled = true;
factory.Uri = uri;