如何在Java中连接Kinesis本地流?

时间:2018-11-29 11:00:30

标签: java aws-sdk amazon-kinesis amazon-kinesis-kpl

我使用以下命令启动了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);
    }
}

相似的方式,我也在写作以便阅读。

0 个答案:

没有答案