Reputation:
I could not get the RabitMq to work and got this error. I am posting this so others with the same problem can eventually find the solution faster than me - I used several hours to find the solution to the problem.
Upvotes: 1
Views: 3220
Reputation:
Thanks @evgenirusev - https://github.com/devmentors/DNC-DShop/issues/8
RabitMQ - Docker - https://hub.docker.com/_/rabbitmq
I was trying to get the RabitMq "Hello World" tutorial to work and could not figure out why is it not working.
This is what worked for me: - hope it helps someone
1. In Docker Terminal "Client" to make RabitMq Image - new Image - docker run -d --hostname my-rabit --name ecomm-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:management
2. Than I copied the IP which is "192.168.99.100:15672
" with the port :15672
and used that in the RabitMq as hostname
- "Copied from the docker kitematic
app
"
3. In RabitMQ Console App Send And Receive - factory.HostName = "192.168.99.100";
4. In RabitMQ Console App Send And Receive - factory.Port = AmqpTcpEndpoint.UseDefaultPort;
5. Dont forget - Nuget- "RabbitMQ.Client" <PackageReference Include="RabbitMQ.Client" Version="6.2.1" />
Receive:
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();
Send:
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();
Upvotes: 1