@Override public BatchResponse onNextBatch(BatchSource source, Collection<JetstreamEvent> events) throws EventException { // check if it's time to send the batch, check the delay time of the // lastEvent, if it's no time to send the batch, tell the IKC to wait // and resend this batch long start = System.currentTimeMillis(); if (getReplayConfig().getTimestampKey() != null && getReplayConfig().getDelayInMs() > 0) { JetstreamEvent[] eventArr = events .toArray(new JetstreamEvent[events.size()]); JetstreamEvent lastEvent = eventArr[eventArr.length - 1]; Long ts = (Long) lastEvent.get(getReplayConfig().getTimestampKey()); if (ts != null) { long v = ts + getReplayConfig().getDelayInMs() - start; if (v > 0) { incrementEventRecievedCounter(events.size()); incrementEventDelayedCounter(events.size()); return BatchResponse.getNextBatch() .setOffset(source.getHeadOffset()) .setWaitTimeInMs(v); } } } return super.onNextBatch(source, events); }
@Override public BatchResponse onNextBatch(BatchSource source, Collection<JetstreamEvent> events) throws EventException { initAutoAdvanceTime(source); incrementEventRecievedCounter(events.size()); if (m_config.isNoDuplication()) { cacheBatch(source, events); } else { BatchResponse ret = sendBatch(source, events); if (ret != null) return ret; } BatchResponse ret = autoAdvanceResponse(source); // check if the read rate exceeds the max, if exceeds, make the next // batch wait for a while String key = getKey(source); Long waitMs = waitForLastBatch.get(key); if (waitMs != null && waitMs > 0) { ret.setWaitTimeInMs(waitMs); } return ret; }