【问题标题】:How to access RabbitMQ cluster configured on Azure AKS to send message on queue?如何访问在 Azure AKS 上配置的 RabbitMQ 集群以在队列上发送消息?
【发布时间】:2021-04-06 22:27:22
【问题描述】:
[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));
       }
    }
} 

我已经使用 helm 在 Azure AKS(混合集群 Win+Linux)上配置了 RabbitMQ 集群,然后通过使用 LoadBalancer 服务创建 docker 映像来部署上述代码以访问应用程序。所以,我的 API URL 是这样的:

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

在这里,我将主机名动态传递给此 API:rabbit@my-release-rabbitmq-0.my-release-rabbitmq-headless.default.svc.cluster.local

我已将端口从 15672 转发到 3000,以便从我的本地计算机访问 RabbitMQ Dashboard,如下图所示。

但无法将消息发送到队列。

所以,我的问题是我应该在我创建的 API(上面的代码)中将什么作为主机名传递给 RabbitMQ 队列

以下是我的 AKS 群集部署详细信息:

【问题讨论】:

  • 您是尝试从集群内部还是外部连接?
  • 我在 Azure ASK 上部署的 API 并使用 Loadbalancer IP 我正在调用该 API。现在该 API 负责将消息推送到队列。即从集群内部推送消息

标签: c# azure kubernetes rabbitmq azure-aks


【解决方案1】:

我修改了如下代码:

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

然后我通过了 hostname="my-release-rabbitmq-headless"; 这是服务名称

现在它按预期工作。

【讨论】:

    猜你喜欢
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 2011-10-18
    • 2021-01-27
    • 1970-01-01
    • 2020-08-31
    相关资源
    最近更新 更多