.Net - AmazonMQ - how to fix problem connection?

Viewed 12

im trying to send messages to a queue but i had a connection exeception.

"RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable" "System.Net.Sockets.SocketException (11001): Unknow Host." "System.AggregateException: One or more errors occurred. (Connection failed)"

anyone knows the explanation for this?

using RabbitMQ.Client;

[Route("api/[controller]")]
[ApiController]
public class ProducerController : ControllerBase
{
   public void SendMessage(string payload)
   {
      ConnectionFactory factory = new ConnectionFactory()
            {
                HostName = "amqps://b-111111-b11a-11aa-b111-111f1111f1aa.mq.us-east- 
                1.amazonaws.com:5671",
                UserName = "admin",
                Password = "randompassword",
                Port = 5671
            };

            var connection = factory.CreateConnection();
            using (var channel = connection.CreateModel())
            {
                channel.QueueDeclare(queue: "hello",
                     durable: false,
                     exclusive: false,
                     autoDelete: false,
                     arguments: null);

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

                channel.BasicPublish(exchange: "",
                                 routingKey: "hello",
                                 basicProperties: null,
                                 body: body);
    }

    [HttpPost]
    public async Task<IActionResult> Post([FromBody] Message message)
    {
        SendMessage(message.text);
        return Ok();
    }
   }
}

0 Answers
Related