コード例 #1
0
  private boolean queryAndResponseData(PullMessageTask pullTask) {
    Tpg tpg = pullTask.getTpg();

    MessageQueueCursor cursor =
        m_queueManager.getCursor(tpg, pullTask.getBrokerLease(), pullTask.getStartOffset());

    if (cursor == null) {
      return false;
    }

    Pair<Offset, List<TppConsumerMessageBatch>> p = null;

    try {
      p = cursor.next(pullTask.getBatchSize());
    } finally {
      cursor.stop();
    }

    if (p != null) {
      Offset currentOffset = p.getKey();
      List<TppConsumerMessageBatch> batches = p.getValue();

      if (batches != null && !batches.isEmpty()) {

        String ip = NettyUtils.parseChannelRemoteAddr(pullTask.getChannel(), false);
        for (TppConsumerMessageBatch batch : batches) {
          // TODO remove legacy code
          boolean needServerSideAckHolder =
              pullTask.getPullMessageCommandVersion() < 3 ? true : false;
          m_queueManager.delivered(
              batch, tpg.getGroupId(), pullTask.isWithOffset(), needServerSideAckHolder);

          bizLogDelivered(ip, batch.getMessageMetas(), tpg);
        }

        response(pullTask, batches, currentOffset);
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  }
コード例 #2
0
  private void bizLog(
      CommandProcessorContext ctx,
      Map<Integer, MessageBatchWithRawData> rawBatches,
      int partition) {
    String ip = NettyUtils.parseChannelRemoteAddr(ctx.getChannel(), false);
    for (Entry<Integer, MessageBatchWithRawData> entry : rawBatches.entrySet()) {
      MessageBatchWithRawData batch = entry.getValue();
      List<PartialDecodedMessage> msgs = batch.getMessages();
      for (PartialDecodedMessage msg : msgs) {
        BizEvent event = new BizEvent("Message.Received");
        event.addData("topic", batch.getTopic());
        event.addData("partition", partition);
        event.addData("priority", entry.getKey());
        event.addData("producerIp", ip);
        event.addData("bornTime", msg.getBornTime());
        event.addData("refKey", msg.getKey());

        m_bizLogger.log(event);
      }
    }
  }