protected void response(PullMessageTask pullTask, List<TppConsumerMessageBatch> batches) {
    PullMessageResultCommand cmd = new PullMessageResultCommand();
    if (batches != null) {
      cmd.addBatches(batches);
    }
    cmd.getHeader().setCorrelationId(pullTask.getCorrelationId());

    pullTask.getChannel().writeAndFlush(cmd);
  }
예제 #2
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;
    }
  }
  protected void response(
      PullMessageTask pullTask, List<TppConsumerMessageBatch> batches, Offset offset) {
    Command cmd = null;
    switch (pullTask.getPullMessageCommandVersion()) {
      case 1:
        cmd = new PullMessageResultCommand();
        if (batches != null) {
          ((PullMessageResultCommand) cmd).addBatches(batches);
        }
        break;
      case 2:
      default:
        cmd = new PullMessageResultCommandV2();
        if (batches != null) {
          ((PullMessageResultCommandV2) cmd).addBatches(batches);
        }
        ((PullMessageResultCommandV2) cmd).setOffset(offset);
        break;
    }
    cmd.getHeader().setCorrelationId(pullTask.getCorrelationId());

    pullTask.getChannel().writeAndFlush(cmd);
  }