Search in sources :

Example 1 with RecordBatch

use of org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch in project flink by apache.

the class PollingRecordPublisher method run.

public RecordPublisherRunResult run(final RecordBatchConsumer consumer, int maxNumberOfRecords) throws InterruptedException {
    if (nextShardItr == null) {
        return COMPLETE;
    }
    metricsReporter.setMaxNumberOfRecordsPerFetch(maxNumberOfRecords);
    GetRecordsResult result = getRecords(nextShardItr, maxNumberOfRecords);
    RecordBatch recordBatch = new RecordBatch(result.getRecords(), subscribedShard, result.getMillisBehindLatest());
    SequenceNumber latestSequenceNumber = consumer.accept(recordBatch);
    nextStartingPosition = getNextStartingPosition(latestSequenceNumber);
    nextShardItr = result.getNextShardIterator();
    long adjustmentEndTimeNanos = adjustRunLoopFrequency(processingStartTimeNanos, System.nanoTime());
    long runLoopTimeNanos = adjustmentEndTimeNanos - processingStartTimeNanos;
    processingStartTimeNanos = adjustmentEndTimeNanos;
    metricsReporter.setRunLoopTimeNanos(runLoopTimeNanos);
    return nextShardItr == null ? COMPLETE : INCOMPLETE;
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) RecordBatch(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)

Example 2 with RecordBatch

use of org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch in project flink by apache.

the class FanOutRecordPublisher method run.

@Override
public RecordPublisherRunResult run(final RecordBatchConsumer recordConsumer) throws InterruptedException {
    LOG.info("Running fan out record publisher on {}::{} from {} - {}", subscribedShard.getStreamName(), subscribedShard.getShard().getShardId(), nextStartingPosition.getShardIteratorType(), nextStartingPosition.getStartingMarker());
    Consumer<SubscribeToShardEvent> eventConsumer = event -> {
        RecordBatch recordBatch = new RecordBatch(toSdkV1Records(event.records()), subscribedShard, event.millisBehindLatest());
        SequenceNumber sequenceNumber = recordConsumer.accept(recordBatch);
        nextStartingPosition = StartingPosition.continueFromSequenceNumber(sequenceNumber);
    };
    RecordPublisherRunResult result = runWithBackoff(eventConsumer);
    LOG.info("Subscription expired {}::{}, with status {}", subscribedShard.getStreamName(), subscribedShard.getShard().getShardId(), result);
    return result;
}
Also used : COMPLETE(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.COMPLETE) Date(java.util.Date) FullJitterBackoff(org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff) LoggerFactory(org.slf4j.LoggerFactory) RecordPublisher(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher) StartingPosition(org.apache.flink.streaming.connectors.kinesis.model.StartingPosition) FanOutSubscriberInterruptedException(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.FanOutSubscriberInterruptedException) ArrayList(java.util.ArrayList) FanOutSubscriberException(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.FanOutSubscriberException) SubscribeToShardEvent(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) Nonnull(javax.annotation.Nonnull) StartingPosition.builder(software.amazon.awssdk.services.kinesis.model.StartingPosition.builder) KinesisProxyV2Interface(org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface) INCOMPLETE(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.INCOMPLETE) ResourceNotFoundException(software.amazon.awssdk.services.kinesis.model.ResourceNotFoundException) Logger(org.slf4j.Logger) StreamShardHandle(org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle) RecoverableFanOutSubscriberException(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.RecoverableFanOutSubscriberException) Preconditions(org.apache.flink.util.Preconditions) Consumer(java.util.function.Consumer) RecordBatch(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch) List(java.util.List) EncryptionType(software.amazon.awssdk.services.kinesis.model.EncryptionType) Record(software.amazon.awssdk.services.kinesis.model.Record) CANCELLED(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.CANCELLED) Internal(org.apache.flink.annotation.Internal) RecordBatch(org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch) SequenceNumber(org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber) SubscribeToShardEvent(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent)

Aggregations

RecordBatch (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch)2 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)2 GetRecordsResult (com.amazonaws.services.kinesis.model.GetRecordsResult)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Nonnull (javax.annotation.Nonnull)1 Internal (org.apache.flink.annotation.Internal)1 RecordPublisher (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher)1 CANCELLED (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.CANCELLED)1 COMPLETE (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.COMPLETE)1 INCOMPLETE (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordPublisher.RecordPublisherRunResult.INCOMPLETE)1 FanOutSubscriberException (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.FanOutSubscriberException)1 FanOutSubscriberInterruptedException (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.FanOutSubscriberInterruptedException)1 RecoverableFanOutSubscriberException (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutShardSubscriber.RecoverableFanOutSubscriberException)1 StartingPosition (org.apache.flink.streaming.connectors.kinesis.model.StartingPosition)1 StreamShardHandle (org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle)1 FullJitterBackoff (org.apache.flink.streaming.connectors.kinesis.proxy.FullJitterBackoff)1 KinesisProxyV2Interface (org.apache.flink.streaming.connectors.kinesis.proxy.KinesisProxyV2Interface)1