@Override
public void onMessage(Message message, Channel channel) throws Exception {
RabbitMQMsg rabbitMQMsg = SerializationUtils.deserialize(message.getBody());
if (rabbitMQMsg != null) {
Boolean isSuc = false;
try {
if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_P2P
|| rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_INVITE) {
isSuc = yiXinAPIService.sendP2PMsg(rabbitMQMsg.getFromId(), rabbitMQMsg.getToId(),
rabbitMQMsg.getYiXinMsg());
} else if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_CIRCLE) {
String gameId = rabbitMQMsg.getYiXinMsg().getAppid();
String fromId = rabbitMQMsg.getFromId();
YiXinMsg msg = rabbitMQMsg.getYiXinMsg();
if (!gameWhiteListService.isWhiteListEnabled(gameId)) { // 未开启隔离模式
isSuc = yiXinAPIService.sendCircleMsg(fromId, msg);
} else { // 开启隔离模式,须测试一下我的好友都不在白名单中的情况
isSuc = yiXinAPIService.sendCircleMsgWithTouids(
fromId,
gameWhiteListService.getFriendsWithinWhiteList(gameId, fromId).toJSONString(),
msg);
}
}
} catch (Exception e) {
LOGGER.error("initNormalMessageMQConsumeTask exception error", e);
AppMonitorLogger.info("incNormalMessageMQConsumeTaskExceptionCount");
}
if (isSuc) {
// 更新监控状态
if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_P2P) {
AppMonitorLogger.info("incSuccGameSendP2PMsgAsyncCount");
} else if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_CIRCLE) {
AppMonitorLogger.info("incSuccGameSendCircleMsgAsyncCount");
} else if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_INVITE) {
AppMonitorLogger.info("incSuccGameFriendInviteAsyncCount");
}
} else {
// 一共失败了3次了 就算失败了
// 发送失败 加入失败队列等待再次发送
if (rabbitMQMsg.getQuota() > 0) {
rabbitMQMsg.setQuota(rabbitMQMsg.getQuota() - 1);
messageMQComponent.sendFailMessage(SerializationUtils.serialize(rabbitMQMsg));
} else {
// 更新监控状态
if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_P2P) {
AppMonitorLogger.info("incFailGameSendP2PMsgAsyncCount");
} else if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_CIRCLE) {
AppMonitorLogger.info("incFailGameSendCircleMsgAsyncCount");
} else if (rabbitMQMsg.getType() == RabbitMQMsg.MQ_MSG_TYPE_INVITE) {
AppMonitorLogger.info("incFailGameFriendInviteAsyncCount");
}
}
}
}
}
我们的message中quota默认是3,我们每发送失败一次就会减一,直到减到0,我们会记录失败日志。