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);
}
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;
}
Aggregations