【发布时间】:2021-05-23 09:09:48
【问题描述】:
【问题讨论】:
【问题讨论】:
感谢@evgenirusev - https://github.com/devmentors/DNC-DShop/issues/8
RabitMQ - Docker - https://hub.docker.com/_/rabbitmq
我试图让 RabitMq“Hello World”教程工作,但不知道为什么它不工作。
这对我有用: - 希望对某人有所帮助
1.在 Docker Terminal "Client" 中制作 RabitMq Image - new Image - docker run -d --hostname my-rabit --name ecomm-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:management
2。比我复制的 IP 是“192.168.99.100:15672”与端口:15672 并在RabitMq 中使用它作为hostname - “从码头复制kitematicapp”
3。在 RabitMQ 控制台应用程序中发送和接收 - 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();
【讨论】: