use of software.amazon.awssdk.services.firehose.model.FirehoseException in project aws-doc-sdk-examples by awsdocs.
the class CreateDeliveryStream method createStream.
// snippet-start:[firehose.java2.create_stream.main]
public static void createStream(FirehoseClient firehoseClient, String bucketARN, String roleARN, String streamName) {
try {
ExtendedS3DestinationConfiguration destinationConfiguration = ExtendedS3DestinationConfiguration.builder().bucketARN(bucketARN).roleARN(roleARN).build();
CreateDeliveryStreamRequest deliveryStreamRequest = CreateDeliveryStreamRequest.builder().deliveryStreamName(streamName).extendedS3DestinationConfiguration(destinationConfiguration).deliveryStreamType("DirectPut").build();
CreateDeliveryStreamResponse streamResponse = firehoseClient.createDeliveryStream(deliveryStreamRequest);
System.out.println("Delivery Stream ARN is " + streamResponse.deliveryStreamARN());
} catch (FirehoseException e) {
System.out.println(e.getLocalizedMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.firehose.model.FirehoseException in project aws-doc-sdk-examples by awsdocs.
the class PutRecord method putSingleRecord.
// snippet-start:[firehose.java2.put_record.main]
public static void putSingleRecord(FirehoseClient firehoseClient, String textValue, String streamName) {
try {
SdkBytes sdkBytes = SdkBytes.fromByteArray(textValue.getBytes());
Record record = Record.builder().data(sdkBytes).build();
PutRecordRequest recordRequest = PutRecordRequest.builder().deliveryStreamName(streamName).record(record).build();
PutRecordResponse recordResponse = firehoseClient.putRecord(recordRequest);
System.out.println("The record ID is " + recordResponse.recordId());
} catch (FirehoseException e) {
System.out.println(e.getLocalizedMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.firehose.model.FirehoseException in project aws-doc-sdk-examples by awsdocs.
the class ListDeliveryStreams method listStreams.
// snippet-start:[firehose.java2.list_streams.main]
public static void listStreams(FirehoseClient firehoseClient) {
try {
ListDeliveryStreamsResponse streamsResponse = firehoseClient.listDeliveryStreams();
List<String> items = streamsResponse.deliveryStreamNames();
for (String item : items) {
System.out.println("The delivery stream name is: " + item);
}
} catch (FirehoseException e) {
System.out.println(e.getLocalizedMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.firehose.model.FirehoseException in project aws-doc-sdk-examples by awsdocs.
the class DeleteStream method delStream.
// snippet-start:[firehose.java2.delete_stream.main]
public static void delStream(FirehoseClient firehoseClient, String streamName) {
try {
DeleteDeliveryStreamRequest deleteDeliveryStreamRequest = DeleteDeliveryStreamRequest.builder().deliveryStreamName(streamName).build();
firehoseClient.deleteDeliveryStream(deleteDeliveryStreamRequest);
System.out.println("Delivery Stream " + streamName + " is deleted");
} catch (FirehoseException e) {
System.out.println(e.getLocalizedMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.firehose.model.FirehoseException in project aws-doc-sdk-examples by awsdocs.
the class PutBatchRecords method addStockTradeData.
// snippet-start:[firehose.java2.put_batch_records.main]
public static void addStockTradeData(FirehoseClient firehoseClient, String streamName) {
List<Record> recordList = new ArrayList<>();
try {
// Repeatedly send stock trades with a 100 milliseconds wait in between
StockTradeGenerator stockTradeGenerator = new StockTradeGenerator();
int index = 100;
// Populate the list with StockTrade data
for (int x = 0; x < index; x++) {
StockTrade trade = stockTradeGenerator.getRandomTrade();
byte[] bytes = trade.toJsonAsBytes();
Record myRecord = Record.builder().data(SdkBytes.fromByteArray(bytes)).build();
System.out.println("Adding trade: " + trade.toString());
recordList.add(myRecord);
Thread.sleep(100);
}
PutRecordBatchRequest recordBatchRequest = PutRecordBatchRequest.builder().deliveryStreamName(streamName).records(recordList).build();
PutRecordBatchResponse recordResponse = firehoseClient.putRecordBatch(recordBatchRequest);
System.out.println("The number of records added is: " + recordResponse.requestResponses().size());
// Check the details of all records in this batch operation.
String errorMsg = "";
String errorCode = "";
List<PutRecordBatchResponseEntry> results = recordResponse.requestResponses();
for (PutRecordBatchResponseEntry result : results) {
// Returns null if there is no error.
errorCode = result.errorCode();
if (errorCode == null) {
System.out.println("Record " + result.recordId() + " was successfully added!");
} else {
errorMsg = result.errorMessage();
System.out.println("Error code for record ID : " + result.recordId() + " is " + errorMsg);
}
}
} catch (FirehoseException | InterruptedException e) {
System.out.println(e.getLocalizedMessage());
System.exit(1);
}
}
Aggregations