use of org.apache.flink.connector.pulsar.source.enumerator.cursor.StartCursor in project flink by apache.
the class PulsarPartitionSplitReaderTestBase method seekStartPositionAndHandleSplit.
private void seekStartPositionAndHandleSplit(PulsarPartitionSplitReaderBase<String> reader, String topicName, int partitionId, MessageId startPosition) {
TopicPartition partition = new TopicPartition(topicName, partitionId, createFullRange());
PulsarPartitionSplit split = new PulsarPartitionSplit(partition, StopCursor.never(), null, null);
SplitsAddition<PulsarPartitionSplit> addition = new SplitsAddition<>(singletonList(split));
// create consumer and seek before split changes
try (Consumer<byte[]> consumer = reader.createPulsarConsumer(partition)) {
// inclusive messageId
StartCursor startCursor = StartCursor.fromMessageId(startPosition);
startCursor.seekPosition(partition.getTopic(), partition.getPartitionId(), consumer);
} catch (PulsarClientException e) {
sneakyThrow(e);
}
reader.handleSplitsChanges(addition);
}
use of org.apache.flink.connector.pulsar.source.enumerator.cursor.StartCursor in project flink by apache.
the class PulsarOrderedPartitionSplitReader method startConsumer.
@Override
protected void startConsumer(PulsarPartitionSplit split, Consumer<byte[]> consumer) {
MessageId latestConsumedId = split.getLatestConsumedId();
// Reset the start position for ordered pulsar consumer.
if (latestConsumedId != null) {
StartCursor startCursor = StartCursor.fromMessageId(latestConsumedId, false);
TopicPartition partition = split.getPartition();
try {
startCursor.seekPosition(partition.getTopic(), partition.getPartitionId(), consumer);
} catch (PulsarClientException e) {
if (sourceConfiguration.getVerifyInitialOffsets() == FAIL_ON_MISMATCH) {
throw new IllegalArgumentException(e);
} else {
// WARN_ON_MISMATCH would just print this warning message.
// No need to print the stacktrace.
LOG.warn("Failed to reset cursor to {} on partition {}", latestConsumedId, partition, e);
}
}
}
}
Aggregations