Skip to content

Instantly share code, notes, and snippets.

@zhuqling
Created March 11, 2013 06:20
Show Gist options
  • Save zhuqling/5132196 to your computer and use it in GitHub Desktop.
Save zhuqling/5132196 to your computer and use it in GitHub Desktop.
RabbitMQ使用QueueingBasicConsumer循环方式,Dequeue取得队列
/*
* 使用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