我正在尝试让 RabbitMQ 服务器正常工作。在本教程中,本地主机连接不是问题。但是每当我尝试通过网络执行相同的操作时,我都无法让应用程序连接到代理。
发送:
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();
Run Code Online (Sandbox Code Playgroud)
RabbitMQ 实例运行在另一台 PC 上,IP …