c# - RabbitMQ.Client.Exceptions.BrokerUnreachableException:'指定的端点都不可到达'
解决方案
谢谢@evgenirusev - https://github.com/devmentors/DNC-DShop/issues/8
RabitMQ - Docker - https://hub.docker.com/_/rabbitmq
我试图让 RabitMq“Hello World”教程工作,但不知道为什么它不工作。
这对我有用: -希望它对某人有所帮助
1. 在 Docker 终端“客户端”中制作 RabitMq Image - new Image - docker run -d --hostname my-rabit --name ecomm-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:management
2.比我192.168.99.100:15672
用端口复制“ ”的IP:15672
并在RabitMq中使用它作为hostname
-“从docker复制kitematic
app
”
3. 在 RabitMQ 控制台 App 发送和接收 - factory.HostName = "192.168.99.100";
4. 在 RabitMQ 控制台应用程序发送和接收 - factory.Port = AmqpTcpEndpoint.UseDefaultPort;
5. 别忘了——Nuget——“RabbitMQ.Client” <PackageReference Include="RabbitMQ.Client" Version="6.2.1" />
收到:
ConnectionFactory factory = new ConnectionFactory();
//factory.UserName = "user";
//factory.Password = "password";
//factory.VirtualHost = "/";
factory.HostName = "192.168.99.100";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
IConnection connection = factory.CreateConnection();
//using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);
Console.WriteLine(" [*] Waiting for messages.");
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Console.WriteLine(" [x] Received {0}", message);
};
channel.BasicConsume(queue: "hello", autoAck: true, consumer: consumer);
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
发送:
ConnectionFactory factory = new ConnectionFactory();
//factory.UserName = "user";
//factory.Password = "password";
//factory.VirtualHost = "/";
factory.HostName = "192.168.99.100";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
IConnection connection = factory.CreateConnection();
//using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null);
string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body);
Console.WriteLine(" [x] Sent {0}", message);
}
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
推荐阅读
- r - 将双引号添加到每行的第一个单词
- sql - 使用“IN”运算符时计算重复项
- firebase - Firebase 托管的 Flutter Web/Dart CORS 错误
- docker - 构建另一个镜像时如何使用现有 docker 镜像的层?
- validation - 输入文本字段的 Primefaces Wizard 验证问题
- javascript - Google 跟踪代码管理器事件未显示在 Universal Analytics 控制台中?
- python - Pyodbc 无法在 SQL Server 2008 中执行 proc
- webpack - Webpack 不提供 css 文件
- sql - 来自具有可变数据库名称的多个数据库的 SQL“LEFT JOIN”
- java - 如何从 java 7 中的 .txt 文件中提取主机名和主机请求的出现?