Search in sources :

Example 1 with ListShardsResponse

use of software.amazon.awssdk.services.kinesis.model.ListShardsResponse in project beam by apache.

the class SimplifiedKinesisClient method listShards.

private List<Shard> listShards(final String streamName, final ShardFilter shardFilter) throws TransientKinesisException {
    return wrapExceptions(() -> {
        ImmutableList.Builder<Shard> shardsBuilder = ImmutableList.builder();
        String currentNextToken = null;
        do {
            ListShardsRequest.Builder reqBuilder = ListShardsRequest.builder().maxResults(LIST_SHARDS_MAX_RESULTS).shardFilter(shardFilter);
            if (currentNextToken != null) {
                reqBuilder.nextToken(currentNextToken);
            } else {
                reqBuilder.streamName(streamName);
            }
            ListShardsResponse response = kinesis.listShards(reqBuilder.build());
            shardsBuilder.addAll(response.shards());
            currentNextToken = response.nextToken();
        } while (currentNextToken != null);
        return shardsBuilder.build();
    });
}
Also used : ListShardsRequest(software.amazon.awssdk.services.kinesis.model.ListShardsRequest) ListShardsResponse(software.amazon.awssdk.services.kinesis.model.ListShardsResponse) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Shard(software.amazon.awssdk.services.kinesis.model.Shard)

Example 2 with ListShardsResponse

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

the class ListShards method listKinShards.

// snippet-start:[kinesis.java2.ListShards.main]
public static void listKinShards(KinesisClient kinesisClient, String name) {
    try {
        ListShardsRequest request = ListShardsRequest.builder().streamName(name).build();
        ListShardsResponse response = kinesisClient.listShards(request);
        System.out.println(request.streamName() + " has " + response.shards());
    } catch (KinesisException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Done");
}
Also used : ListShardsRequest(software.amazon.awssdk.services.kinesis.model.ListShardsRequest) ListShardsResponse(software.amazon.awssdk.services.kinesis.model.ListShardsResponse) KinesisException(software.amazon.awssdk.services.kinesis.model.KinesisException)

Aggregations

ListShardsRequest (software.amazon.awssdk.services.kinesis.model.ListShardsRequest)2 ListShardsResponse (software.amazon.awssdk.services.kinesis.model.ListShardsResponse)2 ImmutableList (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList)1 KinesisException (software.amazon.awssdk.services.kinesis.model.KinesisException)1 Shard (software.amazon.awssdk.services.kinesis.model.Shard)1