RabbitMQ C# API Event based Message Consumption

纵然是瞬间 提交于 2019-11-29 02:02:55

use the RabbitMQ.Client.Events.EventingBasicConsumer for a eventing consumer instead of a blocking one.

You're currently blocking on the Consumer.Queue.Dequeue(). If I understand your question correctly, you want to asynchronously consume messages.

The standard way of doing this would be to write your own IBasicConsumer (probably by subclassing DefaultBasicConsumer) and set it as the consumer for the channel.

The trouble with this is that you have to be very careful about what you do in IBasicConsumer.HandleBasicDelivery. If you use any synchronous AMQP methods, such as basic.publish, you'll get a dead-lock. If you do anything that takes a long time, you'll run into some other problems.

If you do need synchronous methods or long-running actions, what you're doing is about the right way to do it. Have a look at Subscription; it's an IBasicConsumer that consumes messages and puts them on a queue for you.

If you need any more help, a great place to ask is the rabbitmq-discuss mailing list.

I had this problem and could not find an answer so created a demonstration project to have the RabbitMQ subscription raise .Net events when a message is received. The subscription runs on its own thread leaving the UI (in mycase) free to do it thing.

I amusing call my project RabbitEar as it listens out for messages from the mighty RabbitMQ I intend to share this with the RabbitMQ site so if they think its of value they can include a link / code in there examples.

Check it out at http://rabbitears.codeplex.com/

Thanks Simon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!