public class KinesisFirehoseRecorder extends AbstractKinesisRecorder
KinesisFirehoseRecorder is a high level client for Amazon Kinesis
Firehose. It can cache data on users' Android device and send them in a batch
later.
Note: AbstractKinesisRecorder.submitAllRecords() is a synchronous
method that sends cached data to Amazon Kinesis over the network. Therefore
you should not call KinesisRecorder methods on the main thread.
Warning: You should not create multiple KinesisFirehoseRecorder given
the same directory. Doing so is an error and behavior is undefined.
Note: KinesisFirehoseRecorder stores the requests in plain-text, and
does not perform additional security measures outside of what the Android OS
offers by default. Therefore it is recommended you pass a directory that is
only visible to your application, and additionally do not store highly
sensitive information using KinesisFirehoseRecorder.
// working directory for the recorder
File directory = context.getCachedDir();
// AWS Firehose region
Regions region = Regions.US_WEST_2;
// initialize a credentials provider
AWSCredentialsProvider provider = new CognitoCachingCredentialsProvider(
context,
"identityPoolId",
Regions.US_EAST_1);
KinesisFirehoseRecorder firehoseRecorder = new KinesisFirehoseRecorder(
directory, region, provider);
// save some strings
String streamName = "my_stream"; // Firehose delivery stream name
firehoseRecorder.saveRecord("Hello world!\n", streamName);
firehoseRecorder.saveRecord("Streaming data to S3 via Firehose is easy.\n", streamName);
// send previously save data to Amazon Firehose
// Note: submitAllRecords() makes network calls, so wrap it in an AsyncTask.
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... v) {
try {
firehoseRecorder.submitAllRecords();
} catch (AmazonClientException ace) {
// error occurs.
}
}
}.execute();
KinesisFirehoseRecorder requires an IAM policy that allows
PutRecordBatch action on the target delivery stream. Here is an example:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [ "firehose:PutRecordBatch" ],
"Resource": [
"arn:aws:firehose:us-east-1:123456789012:deliverystream/my_stream"
]
}]
}
| Constructor and Description |
|---|
KinesisFirehoseRecorder(java.io.File directory,
Regions region,
AWSCredentialsProvider credentialsProvider)
Constructs a new Kinesis Firehose Recorder specifying a directory that
the recorder has exclusive access to for storing requests.
|
KinesisFirehoseRecorder(java.io.File directory,
Regions region,
AWSCredentialsProvider credentialsProvider,
KinesisRecorderConfig config)
Constructs a new Kinesis Firehose Recorder specifying a directory that
the recorder has exclusive access to for storing requests.
|
| Modifier and Type | Method and Description |
|---|---|
void |
saveRecord(byte[] data,
java.lang.String streamName)
Saves a record to local storage to be sent later.
|
deleteAllRecords, getDiskByteLimit, getDiskBytesUsed, getKinesisRecorderConfig, saveRecord, submitAllRecordspublic KinesisFirehoseRecorder(java.io.File directory,
Regions region,
AWSCredentialsProvider credentialsProvider)
Note: Kinesis Firehose Recorder is synchronous, and it's methods should not be called on the main thread.
Note: Kinesis Firehose Recorder stores requests in plain-text, we recommend using a directory that is only readable by your application and not storing highly sensitive information in requests stored by Kinesis Firehose Recorder.
directory - A directory KinesisFirehoseRecorder can use for
storing requests.region - The region of Amazon Kinesis Firehose this Recorder should
save and send requests to.credentialsProvider - The credentials provider to use when making
requests to AWSpublic KinesisFirehoseRecorder(java.io.File directory,
Regions region,
AWSCredentialsProvider credentialsProvider,
KinesisRecorderConfig config)
Note: Kinesis Firehose Recorder is synchronous, and it's methods should not be called on the main thread.
Note: Kinesis Firehose Recorder stores requests in plain-text, we recommend using a directory that is only readable by your application and not storing highly sensitive information in requests stored by Kinesis Firehose Recorder.
directory - A directory KinesisFirehoseRecorder can use for
storing requests.region - The region of Amazon Kinesis Firehose this Recorder should
save and send requests to.credentialsProvider - The credentials provider to use when making
requests to AWSconfig - Allows configuring various parameters of the recorderpublic void saveRecord(byte[] data,
java.lang.String streamName)
AbstractKinesisRecordersaveRecord in class AbstractKinesisRecorderdata - The data to submit to the streamstreamName - The stream to submit the data to.Copyright © 2018 Amazon Web Services, Inc. All Rights Reserved.