Search in sources :

Example 1 with KinesisException

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

Example 2 with KinesisException

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

the class StockTradesWriter method sendStockTrade.

private static void sendStockTrade(StockTrade trade, KinesisClient kinesisClient, String streamName) {
    byte[] bytes = trade.toJsonAsBytes();
    // The bytes could be null if there is an issue with the JSON serialization by the Jackson JSON library.
    if (bytes == null) {
        System.out.println("Could not get JSON bytes for stock trade");
        return;
    }
    System.out.println("Putting trade: " + trade.toString());
    PutRecordRequest request = PutRecordRequest.builder().partitionKey(// We use the ticker symbol as the partition key, explained in the Supplemental Information section below.
    trade.getTickerSymbol()).streamName(streamName).data(SdkBytes.fromByteArray(bytes)).build();
    try {
        kinesisClient.putRecord(request);
    } catch (KinesisException e) {
        e.getMessage();
    }
}
Also used : KinesisException(software.amazon.awssdk.services.kinesis.model.KinesisException) PutRecordRequest(software.amazon.awssdk.services.kinesis.model.PutRecordRequest)

Example 3 with KinesisException

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

the class StockTradesWriter method validateStream.

private static void validateStream(KinesisClient kinesisClient, String streamName) {
    try {
        DescribeStreamRequest describeStreamRequest = DescribeStreamRequest.builder().streamName(streamName).build();
        DescribeStreamResponse describeStreamResponse = kinesisClient.describeStream(describeStreamRequest);
        if (!describeStreamResponse.streamDescription().streamStatus().toString().equals("ACTIVE")) {
            System.err.println("Stream " + streamName + " is not active. Please wait a few moments and try again.");
            System.exit(1);
        }
    } catch (KinesisException e) {
        System.err.println("Error found while describing the stream " + streamName);
        System.err.println(e);
        System.exit(1);
    }
}
Also used : KinesisException(software.amazon.awssdk.services.kinesis.model.KinesisException) DescribeStreamResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamResponse) DescribeStreamRequest(software.amazon.awssdk.services.kinesis.model.DescribeStreamRequest)

Example 4 with KinesisException

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

the class DescribeLimits method describeKinLimits.

// snippet-start:[kinesis.java2.DescribeLimits.main]
public static void describeKinLimits(KinesisClient kinesisClient) {
    try {
        DescribeLimitsRequest request = DescribeLimitsRequest.builder().build();
        DescribeLimitsResponse response = kinesisClient.describeLimits(request);
        System.out.println("Number of open shards: " + response.openShardCount());
        System.out.println("Maximum shards allowed: " + response.shardLimit());
    } catch (KinesisException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    System.out.println("Done");
}
Also used : KinesisException(software.amazon.awssdk.services.kinesis.model.KinesisException) DescribeLimitsRequest(software.amazon.awssdk.services.kinesis.model.DescribeLimitsRequest) DescribeLimitsResponse(software.amazon.awssdk.services.kinesis.model.DescribeLimitsResponse)

Example 5 with KinesisException

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

the class RegisterStreamConsumer method regConsumer.

public static String regConsumer(KinesisClient kinesisClient, String streamARN) {
    try {
        RegisterStreamConsumerRequest regCon = RegisterStreamConsumerRequest.builder().consumerName("MyConsumer").streamARN(streamARN).build();
        RegisterStreamConsumerResponse resp = kinesisClient.registerStreamConsumer(regCon);
        return resp.consumer().consumerARN();
    } catch (KinesisException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return "";
}
Also used : RegisterStreamConsumerRequest(software.amazon.awssdk.services.kinesis.model.RegisterStreamConsumerRequest) KinesisException(software.amazon.awssdk.services.kinesis.model.KinesisException) RegisterStreamConsumerResponse(software.amazon.awssdk.services.kinesis.model.RegisterStreamConsumerResponse)

Aggregations

KinesisException (software.amazon.awssdk.services.kinesis.model.KinesisException)8 CreateStreamRequest (software.amazon.awssdk.services.kinesis.model.CreateStreamRequest)1 DeleteStreamRequest (software.amazon.awssdk.services.kinesis.model.DeleteStreamRequest)1 DescribeLimitsRequest (software.amazon.awssdk.services.kinesis.model.DescribeLimitsRequest)1 DescribeLimitsResponse (software.amazon.awssdk.services.kinesis.model.DescribeLimitsResponse)1 DescribeStreamRequest (software.amazon.awssdk.services.kinesis.model.DescribeStreamRequest)1 DescribeStreamResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamResponse)1 ListShardsRequest (software.amazon.awssdk.services.kinesis.model.ListShardsRequest)1 ListShardsResponse (software.amazon.awssdk.services.kinesis.model.ListShardsResponse)1 PutRecordRequest (software.amazon.awssdk.services.kinesis.model.PutRecordRequest)1 RegisterStreamConsumerRequest (software.amazon.awssdk.services.kinesis.model.RegisterStreamConsumerRequest)1 RegisterStreamConsumerResponse (software.amazon.awssdk.services.kinesis.model.RegisterStreamConsumerResponse)1 UpdateShardCountRequest (software.amazon.awssdk.services.kinesis.model.UpdateShardCountRequest)1 UpdateShardCountResponse (software.amazon.awssdk.services.kinesis.model.UpdateShardCountResponse)1