无法写入Kinesis流

时间:2019-05-14 11:28:53

标签: amazon-web-services amazon-kinesis

我正在尝试使用AWS KPL库将数据写入Data Firehouse交付流(对于Amazon Kinesis流而言,不是Amazon Kinesis流,因为我的理解是不同的)。但是,无论是在Lambda实例还是在我的本地计算机上,我似乎都无法正常运行。我尝试了几种不同的Amazon kinesis生产者版本,但当前使用的是0.12.11。

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>amazon-kinesis-producer</artifactId>
        <version>0.12.11</version>
    </dependency>

我已按照此处描述的说明进行操作:https://docs.aws.amazon.com/streams/latest/dev/kinesis-kpl-writing.html我的代码如下。该代码运行无误,除了关于不配置Log4J的警告外。完成后,我的s3存储桶上没有日志。

AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new
                 BasicAWSCredentials("accessKey",
                 "secretKey"));


         KinesisProducerConfiguration config = new KinesisProducerConfiguration()
                 .setRecordMaxBufferedTime(300)
                 .setMaxConnections(5)
                 .setRequestTimeout(6000)
                 .setCredentialsProvider(credentialsProvider)
                 .setVerifyCertificate(false)
                 .setRegion("eu-west-1");


        final KinesisProducer kinesis = new KinesisProducer(config);
        ByteBuffer data = ByteBuffer.wrap(("Test main java").getBytes());
        kinesis.addUserRecord("myStream", "myKey", data);

然后,我还尝试等待回调,结果导致如下错误。

AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new
                 BasicAWSCredentials("accessKey",
                 "secretKey"));


         KinesisProducerConfiguration config = new KinesisProducerConfiguration()
                 .setRecordMaxBufferedTime(300)
                 .setMaxConnections(5)
                 .setRequestTimeout(6000)
                 .setCredentialsProvider(credentialsProvider)
                 .setVerifyCertificate(false)
                 .setRegion("eu-west-1");


         KinesisProducer kinesis = new KinesisProducer(config);

         Thread.sleep(2000); //Was told it could help as the producers takes time to set up.
         FutureCallback<UserRecordResult> myCallback = new FutureCallback<UserRecordResult>() {
             @Override
             public void onFailure(Throwable t) {
                 System.out.println("Failed: " + t.toString());
                 System.out.println(t.getStackTrace().toString()); //This always prints exceptions as below
                 t.printStackTrace();
             }

             @Override
             public void onSuccess(UserRecordResult result) {
                 System.out.println("Success: " + result.toString());
             }
         };

         for (int i = 0; i < 10; ++i) {
             ByteBuffer data = ByteBuffer.wrap("myData".getBytes("UTF-8"));
             ListenableFuture<UserRecordResult> f = kinesis.addUserRecord("myStream", "myKey", data);
             // If the Future is complete by the time we call addCallback, the callback will be invoked immediately.
             Futures.addCallback(f, myCallback);
         }

         for (int i = 0; i < 5; i++) {
             try {
                 Thread.sleep(10000); //So I can wait and see the callbacks.
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }

         }

Failed: com.amazonaws.services.kinesis.producer.UserRecordFailedException
[Ljava.lang.StackTraceElement;@3b138ba8
com.amazonaws.services.kinesis.producer.UserRecordFailedException
    at com.amazonaws.services.kinesis.producer.KinesisProducer$MessageHandler.onPutRecordResult(KinesisProducer.java:197)
    at com.amazonaws.services.kinesis.producer.KinesisProducer$MessageHandler.access$000(KinesisProducer.java:131)
    at com.amazonaws.services.kinesis.producer.KinesisProducer$MessageHandler$1.run(KinesisProducer.java:138)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

这个小时,我在做什么错?许多其他人似乎也有相同的问题:https://github.com/awslabs/amazon-kinesis-producer/issues/39

0 个答案:

没有答案