的两种消费者模式basicConsume和basicGet
public class Recv1 {
public static void main(String[] args) throws IOException {
Connection connection = MqUtil.getConnection();
final Channel channel = connection.createChannel();
channel.queueDeclare("work",true,false,false,null);
// 设置通道的预取数量为1,官方推荐100到300,数据会影响其吞吐量
channel.basicQos(10);
// 关闭消息的自动确认机制
/*
* 参数1: 队列名称
* 参数2: 是否自动确认
* */
GetResponse work = channel.basicGet("work", true);
System.out.println(new String(work.getBody()));
// ("work", false, new DefaultConsumer(channel) {
// @Override
// public void handleDelivery(String consumerTag, Envelope envelope, properties, byte[] body) throws IOException {
// try {
// (new String(body) + "----" + ());
// // 在处理完消息后手动进行确认
// /*
// * 参数1: 消息标签
// * 参数2: 是否批量进行确认
// * */
// ((), true);
// } catch (Exception e) {
// ((), false,true);
// }
// }
// });
}
}