Created
March 11, 2013 06:20
-
-
Save zhuqling/5132196 to your computer and use it in GitHub Desktop.
RabbitMQ使用QueueingBasicConsumer循环方式,Dequeue取得队列
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 使用QueueingBasicConsumer循环方式,取得队列 | |
*/ | |
var consumer = new QueueingBasicConsumer(_chan); | |
string consumerTag = _chan.BasicConsume("hello-queue", | |
false, consumer); | |
while (true) | |
{ | |
BasicDeliverEventArgs evtArgs = (BasicDeliverEventArgs) consumer.Queue.Dequeue(); | |
IBasicProperties msgProps = evtArgs.BasicProperties; | |
string msgBody = Encoding.ASCII.GetString(evtArgs.Body); | |
_chan.BasicAck(evtArgs.DeliveryTag, false); | |
txtMsgBody.AppendText("\n"+ msgBody); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment