您的位置:首页 > 其它

RabbitMQ 原文译02--"Hello Word"

2016-03-24 12:57 267 查看
本系列文章均来自官网原文,属于个人翻译,如有雷同,权当个人归档,忽喷.

.NET/C# RabbitMQ 客户端下载地址:https://github.com/rabbitmq/rabbitmq-dotnet-client

关于RabbitMQ在windows 平台的安装和管理配置请参考:/article/5384469.html

确保安装成功:

class Receive
{
private static void Main(string[] args)
{
var factory = new ConnectionFactory() { HostName = "192.168.15.128" };
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",
noAck: true,
consumer: consumer);

Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();
}
}

}


View Code
运行代码Send:



成功发送。

运行代码Reveive:



消息成功接收.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: