rabbitmq接收数据
时间: 2023-10-05 13:08:39 浏览: 97
要在RabbitMQ中接收数据,首先需要创建一个消费者。可以使用以下方法创建消费者:
//新建一个事件驱动的消费者
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);
};
//通知RabbitMQ服务器,我要接收指定队列的消息
channel.BasicConsume(queue: "q.log.info", noAck: true, consumer: consumer);
这个方法创建了一个事件驱动的消费者,当消费者收到消息后,会执行相应的事件处理。在这个例子中,事件处理会将收到的消息进行打印输出。同时,通过调用channel.BasicConsume方法,并指定要接收消息的队列,来告诉RabbitMQ服务器,我要接收指定队列的消息。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [RabbitMQ 简单的消息发送与接收](https://blog.csdn.net/dietisi8980/article/details/101856657)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [python操作rabbitmq 实践笔记](https://blog.csdn.net/weixin_34195142/article/details/92870270)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文