EasyNetQRabbitMQ 的 .NET 开发包
EasyNetQ 是 RabbitMQ 的 .NET 开发包。
示例代码:
var bus = RabbitHutch.CreateRabbitBus("localhost"); var message = new MyMessage {Text = "Hello!"}; bus.Publish(message);
目标:
- 尽可能简化在.NET上使用RabbitMQ的工作。
要连接到RabbitMQ代理...
var bus = RabbitHutch.CreateBus("host=localhost");
要发布消息...
bus.Publish(message);
订阅消息...
bus.Subscribe<MyMessage>("my_subscription_id", msg => Console.WriteLine(msg.Text));
远程过程调用...
var request = new TestRequestMessage {Text = "Hello from the client! "};
bus.Request<TestRequestMessage, TestResponseMessage>(request, response =>
Console.WriteLine("Got response: '{0}'", response.Text));
RPC服务器...
bus.Respond<TestRequestMessage, TestResponseMessage>(request =>
new TestResponseMessage{ Text = request.Text + " all done!" });
评论