Search in sources :

Example 1 with SubscribeToShardEvent

use of software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent in project aws-doc-sdk-examples by awsdocs.

the class KinesisStreamEx method responseHandlerBuilderVisitor.

// snippet-end:[kinesis.java2.stream_example.visitor]
/**
 * Subscribes to the stream of events by implementing the SubscribeToShardResponseHandler.Visitor interface.
 */
private static CompletableFuture<Void> responseHandlerBuilderVisitor(KinesisAsyncClient client, SubscribeToShardRequest request) {
    SubscribeToShardResponseHandler.Visitor visitor = new SubscribeToShardResponseHandler.Visitor() {

        @Override
        public void visit(SubscribeToShardEvent event) {
            System.out.println("Received subscribe to shard event " + event);
        }
    };
    SubscribeToShardResponseHandler responseHandler = SubscribeToShardResponseHandler.builder().onError(t -> System.err.println("Error during stream - " + t.getMessage())).subscriber(visitor).build();
    return client.subscribeToShard(request, responseHandler);
}
Also used : SubscribeToShardResponseHandler(software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponseHandler) SubscribeToShardEvent(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent)

Example 2 with SubscribeToShardEvent

use of software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent 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

SubscribeToShardEvent (software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent)2 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 RecordBatch (org.apache.flink.streaming.connectors.kinesis.internals.publisher.RecordBatch)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 SequenceNumber (org.apache.flink.streaming.connectors.kinesis.model.SequenceNumber)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