List<MessageExt> wrappers =
MessageDecoder.decodes(
ByteBuffer.wrap(response.getBody()), true);
QueryResult qr =
new QueryResult(responseHeader
.getIndexLastUpdateTimestamp(), wrappers);
queryResultList.add(qr);
break;
}
default:
log.warn("getResponseCommand failed, {} {}",
response.getCode(), response.getRemark());
break;
}
}
else {
log.warn("getResponseCommand return null");
}
}
finally {
countDownLatch.countDown();
}
}
});
}
catch (Exception e) {
log.warn("queryMessage exception", e);
}// end of try
} // end of for
boolean ok = countDownLatch.await(1000 * 20, TimeUnit.MILLISECONDS);
if (!ok) {
log.warn("queryMessage, maybe some broker failed");
}
long indexLastUpdateTimestamp = 0;
List<MessageExt> messageList = new LinkedList<MessageExt>();
for (QueryResult qr : queryResultList) {
if (qr.getIndexLastUpdateTimestamp() > indexLastUpdateTimestamp) {
indexLastUpdateTimestamp = qr.getIndexLastUpdateTimestamp();
}
for (MessageExt msgExt : qr.getMessageList()) {
String keys = msgExt.getKeys();
if (keys != null) {
boolean matched = false;
String[] keyArray = keys.split(MessageConst.KEY_SEPARATOR);
if (keyArray != null) {
for (String k : keyArray) {
if (key.equals(k)) {
matched = true;
break;
}
}
}
if (matched) {
messageList.add(msgExt);
}
else {
log.warn(
"queryMessage, find message key not matched, maybe hash duplicate {}",
msgExt.toString());
}
}
}
}
if (!messageList.isEmpty()) {
return new QueryResult(indexLastUpdateTimestamp, messageList);
}
else {
throw new MQClientException("query operation over, but no message.", null);
}
}