Map<RoundRobinTable.Table,Long> lastIdMap = Maps.newHashMap();
Map<RoundRobinTable.Table,Object> lastOrderIdMap = Maps.newHashMap();
while(running){
RoundTable.Table table.= roundRobinTable.nextTable();
List<Map<String,Object>> list = listOrderBuffers(table,lastIdMap.get(table));
list.foreach((map)->{
Long id = (Long)map.get("id");
Long orderId = (Long)map.get("order_id");
String orderJson = (String)map.get("order_json");
publishEvent(table,id,orderId,orderJson);
lastIdMap.put(table,id);
lastOrderIdMap.put(table,orderId);
tryRateLimit();
});
}
2.缓冲订单同步到订单中心
Long orderId = orderBufferEvent.getOrderId();
String orderJson = orderBufferEvent.getOrderJson();
RoundRobinTable.table = orderBufferEvent.getTable();
try{
OrderDTO order = JSONUtils.fromJson(orderJson,OrderDTO.class);
orderService.save(order);
deleteOrderBuffer(table,orderId);
}catch(OrderException e){
OrderDTO.order = orderJsfService.getOrderFromDB(orderId);
if(order != null){
deleteOrderBuffer(table,orderId);
}
}
|