예제 #1
0
  /** 基类实现消息监听接口,加上打印metaq监控日志的方法 */
  @Override
  public ConsumeConcurrentlyStatus consumeMessage(
      List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
    long startTime = System.currentTimeMillis();
    logger.info("receive_message:{}", msgs.toString());
    if (msgs == null || msgs.size() < 1) {
      logger.error("receive empty msg!");
      return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
    }

    List<Serializable> msgList = new ArrayList<>();
    for (MessageExt message : msgs) {
      msgList.add(decodeMsg(message));
    }

    final int reconsumeTimes = msgs.get(0).getReconsumeTimes();
    MsgObj msgObj = new MsgObj();
    msgObj.setReconsumeTimes(reconsumeTimes);
    msgObj.setMsgList(msgList);
    msgObj.setContext(context);
    context.setDelayLevelWhenNextConsume(getDelayLevelWhenNextConsume(reconsumeTimes));

    ConsumeConcurrentlyStatus status = doConsumeMessage(msgObj);
    logger.info(
        "ConsumeConcurrentlyStatus:{}|cost:{}", status, System.currentTimeMillis() - startTime);
    return status;
  }
예제 #2
0
 protected ConsumeConcurrentlyStatus exceptionConsumeConcurrentlyStatus(
     TransactionStatus status, Throwable e, MsgObj msgObj, int maxRetryCount) {
   logger.error("mq consume failed", e);
   status.setRollbackOnly();
   if (msgObj.getReconsumeTimes() >= maxRetryCount) {
     logger.error(
         "retryCount: {}, msgs: {}, context: {}", maxRetryCount, msgObj, msgObj.getContext());
     msgObj.setErrorMsg(e.getMessage());
     doLogErrorConsumeMessage(msgObj);
     return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
   } else {
     return ConsumeConcurrentlyStatus.RECONSUME_LATER;
   }
 }