List转Map(同源策略)、以及Map的优化
Map<String, List<QueueMessage>> queueMessageMap = new HashMap<>();
for (QueueMessage queueMessage: messages){
queueMessageMap.computeIfAbsent(new JsonObject(queueMessage.getBody()).getString("tenantId"),
k -> new LinkedList<>()).add(queueMessage);
}
for (Map.Entry<String, List<QueueMessage>> tenant: queueMessageMap.entrySet()){
// key = tenant.getKey()
// value = tenant.getValue()
}