public Form1()
{
InitializeComponent();
用户名密码,服务器地址,端口号略...
using (var connection = factory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("bj_gaojiachang", true, false, false, null);//"hello", true, false, false, null
consumer = new EventingBasicConsumer(channel);
channel.BasicConsume("bj_gaojiachang", true, consumer);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
File.AppendAllText(pathUrl, message + "\r\n");
};
Console.ReadLine();
}
}
}