到目前为止,我的 RabbitMQ 消费者客户端使用的预取值为 1。我希望增加该值以提高性能。如果我将值设置为 2,RabbitMQ 服务器是否会一次向每个消费者发送 2 条消息,以便我需要解析这两条消息并将第二条消息存储在 List 中,直到第一个消息被处理和确认?还是 API 会在幕后处理这个问题?
我正在使用 Java AMQP 客户端库:
ConnectionFactory factory = new ConnectionFactory();
...
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.basicQos(2);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(CONSUME_QUEUE_NAME, false, consumer);
while (!Thread.currentThread().isInterrupted()) {
try {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String m = new String(delivery.getBody(), "UTF-8");
// Will m contain two messages? Will I have to each message and keep track of them within a List?
...
}