简体   繁体   中英

How to access RabbitMQ cluster configured on Azure AKS to send message on queue?

[HttpGet]
[Route("api/sender")]
public string Sender(string message, string hostName)
{
  try
    {
       Send("myQ1", message, hostName);
       return "successfully message sent to Queue";
    }
    catch (Exception ex)
    {
       return ex.Message;
    }                     
        
}

public static void Send(string queue, string data,string hostName)
{
   var factory = new ConnectionFactory() { HostName = hostName };
   using (IConnection connection = factory.CreateConnection())
   {
      using (IModel channel = connection.CreateModel())
      {
         channel.QueueDeclare(queue, false, false, false, null);
         channel.BasicPublish(string.Empty, queue, null, Encoding.UTF8.GetBytes(data));
       }
    }
} 

I have configured RabbitMQ cluster on Azure AKS( Hybrid cluster Win+Linux ) using helm and then deployed the above code by creating docker image using LoadBalancer Service to access the application.So, my API URL is like:

http://xxxx/api/sender?message=Hi&hostname=rabbit@my-release-rabbitmq-0.my-release-rabbitmq-headless.default.svc.cluster.local

Here I am passing hostname dynamically to this API as: rabbit@my-release-rabbitmq-0.my-release-rabbitmq-headless.default.svc.cluster.local

I have port forwarded from 15672 to 3000 to access RabbitMQ Dashboard from my native computer like below image.

在此处输入图像描述

But not able to send the message to Queue.

So, my question is what should I pass as host name in the API I have created(above code) to send message to RabbitMQ queue

Below is my AKS cluster deployment details: 在此处输入图像描述

I have modified the code like:

var factory = new ConnectionFactory() { HostName = hostName, UserName="RabbitMQ Username",Password="RabitMQ Password" };

Then I passed the hostname=" my-release-rabbitmq-headless "; This is the service name .

Now its working as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM