JMS 消息选择器是否通过单个 consumer.receive() 调用或它看到的第一条消息拉下多条消息?

Does a JMS message selector pull multiple messages down with a single consumer.receive() call or the first message it sees?

我目前正在使用 IBM MQ JMS 库并编写一个 Java class 来处理使用如下选择器从消费队列中拉取消息:

consumer = session.createConsumer(queue, "JMSCorrelationID = '" + request.getCorrelationID() + "'");
message = consumer.receive(30000);

我的问题是,如果消费队列中有两条消息与消息选择器匹配,调用 consumer.receive 会拉下这两条消息还是只会拉下它看到的第一条消息?

我发现了另一个 SO 问题: How to remove multiple messages using message selector in JMS 这似乎暗示了这样一个事实,即使消费队列中的两条消息与选择器匹配,调用 receive 也会拉下一条消息。

MessageConsumer 的文档说明如下:

Receives the next message that arrives within the specified timeout interval.

https://docs.oracle.com/javaee/7/api/javax/jms/MessageConsumer.html

所以调用 receive 应该一次拉取 1 条消息。它实际上不能 return 更多消息,因为 return 类型是 Message 而不是任何类型的集合。

未指定实际的 JMS 提供程序客户端在内部如何工作:这取决于提供程序;但它只能 return 一条消息给呼叫者。