简体   繁体   English

如何判断Kinesis碎片的状态?

[英]How do I tell the status of a Kinesis shard?

Is there a way to tell what a shard's status is, whether it's OPEN, CLOSED, or EXPIRED? 有没有办法告诉碎片的状态是什么,无论是开放,关闭还是过期? The only way I've been able to determine this information seems to be attempting an operation on the shard. 我能够确定此信息的唯一方法似乎是尝试在分片上进行操作。

You can use Amazon Web Services Java SDK: https://github.com/aws/aws-sdk-java 您可以使用Amazon Web Services Java SDK: https//github.com/aws/aws-sdk-java

There are a lot of useful methods for accessing your resources. 有很多有用的方法来访问您的资源。

Edit: Sorry, I misunderstood the question. 编辑:对不起,我误解了这个问题。 You cannot access a shard's status directly (yet). 您无法直接访问分片的状态(尚未)。 But there is a trick: A Closed shard always has an "Ending Sequence Number" defined. 但有一个技巧:一个封闭的分片总是定义一个“结束序列号”。 You can hack this way. 你可以这样破解。

Excerpt from Javadoc; 摘自Javadoc;

public String getEndingSequenceNumber () public String getEndingSequenceNumber ()

The ending sequence number for the range. 范围的结束序列号。 Shards that are in the OPEN state have an ending sequence number of null. 处于OPEN状态的碎片的结束序列号为null。

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/kinesis/model/SequenceNumberRange.html#getEndingSequenceNumber() http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/kinesis/model/SequenceNumberRange.html#getEndingSequenceNumber()

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.kinesis.AmazonKinesis;
import com.amazonaws.services.kinesis.AmazonKinesisClient;
import com.amazonaws.services.kinesis.model.DescribeStreamRequest;
import com.amazonaws.services.kinesis.model.DescribeStreamResult;
import com.amazonaws.services.kinesis.model.ListStreamsResult;

public class KinesisSandbox {

    public static void main(String[] args) {
        try {
            String amazonKey = "x";
            String amazonSecret = "y";
            AmazonKinesis client = new AmazonKinesisClient(new BasicAWSCredentials(amazonKey, amazonSecret));

            ListStreamsResult listStreamsResult = client.listStreams();
            System.out.println("\nlistStreamsResult: " + listStreamsResult);

            String streamName = listStreamsResult.getStreamNames().get(0);

            DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest();
            describeStreamRequest.setStreamName(streamName);
            DescribeStreamResult describeStreamResult = client.describeStream(describeStreamRequest);
            System.out.println("\n describeStreamResult.getStreamDescription().getStreamStatus(): "
                    + describeStreamResult.getStreamDescription().getStreamStatus());
                // System.out.println("\ndescribeStreamResult: " + describeStreamResult);

            List<Shard> shards = describeStreamResult.getStreamDescription().getShards();
            for (int i = 0; i < shards.size(); i++) {
                Shard shard = shards.get(i);
                if (shard.getSequenceNumberRange().getEndingSequenceNumber() == null) {
                    System.out.println("shard(" + i + "): " + shard.getShardId() + " is OPEN.");
                } else {
                    System.out.println("shard(" + i + "): " + shard.getShardId() + " is CLOSED.");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

- -

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM