Search in sources :

Example 1 with FirehoseException

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);
    }
}
Also used : FirehoseException(software.amazon.awssdk.services.firehose.model.FirehoseException) CreateDeliveryStreamResponse(software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamResponse) CreateDeliveryStreamRequest(software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamRequest) ExtendedS3DestinationConfiguration(software.amazon.awssdk.services.firehose.model.ExtendedS3DestinationConfiguration)

Example 2 with FirehoseException

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);
    }
}
Also used : SdkBytes(software.amazon.awssdk.core.SdkBytes) PutRecordResponse(software.amazon.awssdk.services.firehose.model.PutRecordResponse) PutRecordRequest(software.amazon.awssdk.services.firehose.model.PutRecordRequest) FirehoseException(software.amazon.awssdk.services.firehose.model.FirehoseException) Record(software.amazon.awssdk.services.firehose.model.Record)

Example 3 with FirehoseException

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);
    }
}
Also used : FirehoseException(software.amazon.awssdk.services.firehose.model.FirehoseException) ListDeliveryStreamsResponse(software.amazon.awssdk.services.firehose.model.ListDeliveryStreamsResponse)

Example 4 with FirehoseException

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);
    }
}
Also used : DeleteDeliveryStreamRequest(software.amazon.awssdk.services.firehose.model.DeleteDeliveryStreamRequest) FirehoseException(software.amazon.awssdk.services.firehose.model.FirehoseException)

Example 5 with FirehoseException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) PutRecordBatchResponse(software.amazon.awssdk.services.firehose.model.PutRecordBatchResponse) FirehoseException(software.amazon.awssdk.services.firehose.model.FirehoseException) Record(software.amazon.awssdk.services.firehose.model.Record) PutRecordBatchRequest(software.amazon.awssdk.services.firehose.model.PutRecordBatchRequest) PutRecordBatchResponseEntry(software.amazon.awssdk.services.firehose.model.PutRecordBatchResponseEntry)

Aggregations

FirehoseException (software.amazon.awssdk.services.firehose.model.FirehoseException)5 Record (software.amazon.awssdk.services.firehose.model.Record)2 ArrayList (java.util.ArrayList)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 CreateDeliveryStreamRequest (software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamRequest)1 CreateDeliveryStreamResponse (software.amazon.awssdk.services.firehose.model.CreateDeliveryStreamResponse)1 DeleteDeliveryStreamRequest (software.amazon.awssdk.services.firehose.model.DeleteDeliveryStreamRequest)1 ExtendedS3DestinationConfiguration (software.amazon.awssdk.services.firehose.model.ExtendedS3DestinationConfiguration)1 ListDeliveryStreamsResponse (software.amazon.awssdk.services.firehose.model.ListDeliveryStreamsResponse)1 PutRecordBatchRequest (software.amazon.awssdk.services.firehose.model.PutRecordBatchRequest)1 PutRecordBatchResponse (software.amazon.awssdk.services.firehose.model.PutRecordBatchResponse)1 PutRecordBatchResponseEntry (software.amazon.awssdk.services.firehose.model.PutRecordBatchResponseEntry)1 PutRecordRequest (software.amazon.awssdk.services.firehose.model.PutRecordRequest)1 PutRecordResponse (software.amazon.awssdk.services.firehose.model.PutRecordResponse)1