12345678910111213141516171819202122 |
- package com.sf.message.pull;
- import com.rabbitmq.client.Channel;
- import com.rabbitmq.client.GetResponse;
- import com.sf.util.RabbitMqUtils;
- public class Consumer {
- private static String queueName = "hello1";
- public static void main(String[] args) throws Exception{
- Channel channel = RabbitMqUtils.getChannel();
- // 消息的处理有两种模式 推和拉
- // basicAck 推送,是由mq主动推送的方式
- // basicGet 拉取,消费者主动获取消息
- GetResponse response = channel.basicGet(queueName, true);
- byte[] body = response.getBody();
- String message = new String(body, "UTF-8");
- System.out.println(message);
- channel.close();
- }
- }
|