我使用以下命令启动了kinesis本地流
kinesalite --port 4567
但是我无法从流中读取或写入流中。
这是我的编写代码:
public static void writeToLocalStream(String message)
{
String streamName="testStream";
AWSCredentials credentials = new BasicAWSCredentials("TestAccessKey","TestSecretKey");
AmazonKinesis kinesisClient = new AmazonKinesisClient(credentials);
kinesisClient.setEndpoint("http://localhost:4567");
System.out.println(kinesisClient.listStreams());
byte[] bytes = message.getBytes();
PutRecordRequest putRecord = new PutRecordRequest();
putRecord.setStreamName(streamName);
putRecord.setPartitionKey("needToBeUpdated");
putRecord.setData(ByteBuffer.wrap(bytes));
try {
PutRecordResult putRecordsResult = kinesisClient.putRecord(putRecord);
System.out.println("Put Result: " + putRecordsResult);
} catch (AmazonClientException ex) {
System.out.println("Error sending record to Amazon Kinesis. " + ex);
}
}
相似的方式,我也在写作以便阅读。