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