Search in sources :

Example 6 with KinesisAsyncClient

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

the class KinesisStreamEx method main.

public static void main(String[] args) {
    // snippet-start:[kinesis.java2.stream_example.setup]
    Region region = Region.US_EAST_1;
    KinesisAsyncClient client = KinesisAsyncClient.builder().region(region).build();
    SubscribeToShardRequest request = SubscribeToShardRequest.builder().consumerARN(CONSUMER_ARN).shardId("arn:aws:kinesis:us-east-1:111122223333:stream/StockTradeStream").startingPosition(s -> s.type(ShardIteratorType.LATEST)).build();
    // snippet-end:[kinesis.java2.stream_example.setup]
    SubscribeToShardResponseHandler responseHandler = SubscribeToShardResponseHandler.builder().onError(t -> System.err.println("Error during stream - " + t.getMessage())).subscriber(MySubscriber::new).build();
    client.subscribeToShard(request, responseHandler);
    client.close();
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) ShardIteratorType(software.amazon.awssdk.services.kinesis.model.ShardIteratorType) SubscribeToShardResponseHandler(software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponseHandler) SubscribeToShardEventStream(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEventStream) CompletableFuture(java.util.concurrent.CompletableFuture) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) SubscribeToShardRequest(software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest) SubscribeToShardResponse(software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Region(software.amazon.awssdk.regions.Region) SubscribeToShardEvent(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent) Subscriber(org.reactivestreams.Subscriber) SubscribeToShardResponseHandler(software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponseHandler) KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SubscribeToShardRequest(software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest) Region(software.amazon.awssdk.regions.Region)

Example 7 with KinesisAsyncClient

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

the class KinesisStreamEx method responseHandlerBuilderVisitorBuilder.

// snippet-end:[kinesis.java2.stream_example.publish_transformer]
/**
 * Creates a SubscribeToShardResponseHandler.Visitor using the builder which lets you register an event handler for
 * all events you're interested in rather than implementing the interface.
 */
// snippet-start:[kinesis.java2.stream_example.visitor]
private static CompletableFuture<Void> responseHandlerBuilderVisitorBuilder(KinesisAsyncClient client, SubscribeToShardRequest request) {
    SubscribeToShardResponseHandler.Visitor visitor = SubscribeToShardResponseHandler.Visitor.builder().onSubscribeToShardEvent(e -> System.out.println("Received subscribe to shard event " + e)).build();
    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) KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) ShardIteratorType(software.amazon.awssdk.services.kinesis.model.ShardIteratorType) SubscribeToShardResponseHandler(software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponseHandler) SubscribeToShardEventStream(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEventStream) CompletableFuture(java.util.concurrent.CompletableFuture) SdkPublisher(software.amazon.awssdk.core.async.SdkPublisher) SubscribeToShardRequest(software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest) SubscribeToShardResponse(software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Subscription(org.reactivestreams.Subscription) Region(software.amazon.awssdk.regions.Region) SubscribeToShardEvent(software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent) Subscriber(org.reactivestreams.Subscriber)

Example 8 with KinesisAsyncClient

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

the class KinesisStreamRxJavaEx method main.

public static void main(String[] args) {
    KinesisAsyncClient client = KinesisAsyncClient.create();
    SubscribeToShardRequest request = SubscribeToShardRequest.builder().consumerARN(CONSUMER_ARN).shardId("shardId-000000000000").startingPosition(StartingPosition.builder().type(ShardIteratorType.LATEST).build()).build();
    responseHandlerBuilder_RxJava(client, request).join();
    client.close();
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SubscribeToShardRequest(software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest)

Example 9 with KinesisAsyncClient

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

the class ClientConfiguration method main.

public static void main(String[] args) {
    // If configured with an httpClientBuilder, the SDK will manage the lifecycle of the HTTP client
    // and it will be shutdown when the client is shut down.
    // snippet-start:[kinesis.java2.client_configuration.client]
    KinesisAsyncClient client = KinesisAsyncClient.builder().httpClientBuilder(NettyNioAsyncHttpClient.builder().maxConcurrency(100).maxPendingConnectionAcquires(10_000)).build();
    // snippet-end:[kinesis.java2.client_configuration.client]
    // When passing in the httpClient directly, the lifecycle must be managed by the caller and the HTTP client
    // will not be shut down when the client is shut down.
    // snippet-start:[kinesis.java2.client_configuration.httpclient]
    SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder().maxConcurrency(100).maxPendingConnectionAcquires(10_000).build();
    KinesisAsyncClient kinesisClient = KinesisAsyncClient.builder().httpClient(httpClient).build();
    httpClient.close();
// snippet-end:[kinesis.java2.client_configuration.httpclient]
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient)

Example 10 with KinesisAsyncClient

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

the class KinesisStreamReactorEx method main.

public static void main(String[] args) {
    KinesisAsyncClient client = KinesisAsyncClient.create();
    SubscribeToShardRequest request = SubscribeToShardRequest.builder().consumerARN(CONSUMER_ARN).shardId("shardId-000000000000").startingPosition(StartingPosition.builder().type(ShardIteratorType.LATEST).build()).build();
    responseHandlerBuilder_Reactor(client, request).join();
    client.close();
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SubscribeToShardRequest(software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest)

Aggregations

KinesisAsyncClient (software.amazon.awssdk.services.kinesis.KinesisAsyncClient)18 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)14 Test (org.junit.Test)12 SubscribeToShardRequest (software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 DescribeStreamConsumerRequest (software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerRequest)3 DescribeStreamConsumerResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse)3 DescribeStreamSummaryRequest (software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest)3 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FanOutRecordPublisherConfiguration (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutRecordPublisherConfiguration)2 Subscriber (org.reactivestreams.Subscriber)2 Subscription (org.reactivestreams.Subscription)2 SdkPublisher (software.amazon.awssdk.core.async.SdkPublisher)2 Region (software.amazon.awssdk.regions.Region)2 DescribeStreamSummaryResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryResponse)2 ShardIteratorType (software.amazon.awssdk.services.kinesis.model.ShardIteratorType)2 SubscribeToShardEvent (software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent)2 SubscribeToShardEventStream (software.amazon.awssdk.services.kinesis.model.SubscribeToShardEventStream)2 SubscribeToShardResponse (software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponse)2