I'm trying to get the RabbitMQ server working. The localhost connection was not a problem with the tutorial. But whenever I try to do the same trough the network I can't get the application to connect to the broker.
Send:
var factory = new ConnectionFactory() { };
factory.HostName = "192.168.1.52";
factory.Port = 5672;
factory.UserName = "guest";
factory.Password = "guest";
factory.VirtualHost = "/";
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();
The RabbitMQ instance runs on a different PC with the IP address 192.168.1.52. The default port used by RabbitMQ is 5672, and I've not yet changed the username or password so those are still guest and guest.
Recieve:
var factory = new ConnectionFactory() { };
factory.HostName = "192.168.1.52";
factory.Port = 5672;
factory.UserName = "guest";
factory.Password = "guest";
factory.VirtualHost = "/";
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
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();
}
Both program's throw a exception:
Exception thrown: 'RabbitMQ.Client.Exceptions.ConnectFailureException' in RabbitMQ.Client.dll while running the program
but it doesn't break the thread. After a while the threat exitst with the following error:
ExtendedSocketException: A connection attempt failed because the connected party did not respond correctly after a certain time, or the connection made failed because the connected host did not respond. 192.168.1.52:5672