我已经安装了this rabbitmq图像(标签:rabbitmq:3-management)
以下命令用于在我的机器上设置容器
docker run --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3-management
我可以使用docker ps
命令看到容器已启动并正在运行
RabbitMQ管理门户也已启动并在端口8080上运行
。Net Core 2.2代码
下面是一段用于建立连接的.Net核心代码
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var factory = new ConnectionFactory() { HostName = "localhost" };
factory.Port = 8080;
factory.UserName = "guest";
factory.Password = "guest";
//Getting exception while creating connection
//RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
using (var conn = factory.CreateConnection())
{
}
//I am having simillar issue with MassTransit
//var bus = Bus.Factory.CreateUsingRabbitMq(cfg =>
//{
// cfg.Host(new Uri(@"rabbitmq://localhost:8080/my-rabbit"), host =>
// {
// host.Username("guest");
// host.Password("guest");
// });
//});
//bus.Start();
Console.ReadKey();
}
}
我无法建立连接并出现以下异常:
RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
创建容器时,我是否需要使用任何其他命令配置容器或传递任何其他环境变量?
也公开队列端口:
-p 5672:5672
连接到该端口,而不是像以前那样连接到8080。