asp.net - RabbitMQ 连接被拒绝 127.0.0.1:5672
问题描述
我正在准备一个简单的 ASP.NET Core MVC Web 应用程序。
我已经在我的笔记本电脑上安装了 RabbitMQ 服务器。RabbitMQ 管理 UI 在localhost:15672
.
Rabbit MQ 集群名称如下:rabbit@CR00001.ABC.COM.LOCAL
我正在尝试向控制器中的 rabbitmq 发送消息。但我得到None of the specified endpoints are reachable错误。
如果我使用 'localhost' 作为主机名,我会在内部异常中得到Connection denied 127.0.0.1:5672 。
如果我rabbit
用作主机名,我会得到Name or service not known
我试图根据其他 StackOverflow 问题来解决问题,但是,没有一个可以解决我的问题。
家庭控制器:
[HttpPost]
public void SendMessage([FromBody]Message message)
{
try
{
var factory = new ConnectionFactory()
{
UserName = _username,
Password = _password,
HostName = _hostname,
VirtualHost = "/",
Port = _port,
};
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: _queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
var body = Encoding.UTF8.GetBytes(message.Text);
channel.BasicPublish(exchange: "",
routingKey: _queueName,
basicProperties: null,
body: body);
}
}
catch (Exception ex)
{
}
}
应用设置.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"RabbitMq": {
"Hostname": "localhost",
"QueueName": "WordQueue",
"UserName": "test",
"Password": "test",
"Port": 5672
}
}
解决方案
推荐阅读
- c# - 重构所有代码文件以删除类型限定符
- node.js - 公共模块在路由内的代码之前执行?
- python - 如何使用 python 在日期之间访问 azure Dev Ops 数据,例如 Changeset?
- ruby-on-rails - 在 Rails 6 中 Webpacker 在 image_pack_tag 的帮助下使用(添加)图像到 html
- rust - 一个 Rust 函数,用于在压缩文件的行上返回一个迭代器
- android - android:textSize 在 MotionLayout 中的变化
- php - 如何在 php 中的 Google adwords api Traffic Estimator Service 中设置估计的最大每日费用
- azure-devops - Azure DevOps 将 Nuget 发布到托管源
- php - 如何确认http post请求是否已在flutter中发布?
- version-control - AzureDevops 中项目结构的建议