我正在尝试将一些数据放到我的AWS Firehose Stream中,但遇到了一些困难。我也收到一个错误,我的流名称无法找到,即使它肯定存在于该名称下。我也尝试了另一个活动流,我遇到了同样的问题。我不确定这个错误是否与我不赞成使用构造函数的错误有关。
在帐户xxxxxxxxxxx下找不到Firehose项目流。 (服务:AmazonKinesisFirehose;状态代码:400;错误代码: ResourceNotFoundException;请求ID:xxxxxxxxxxxxxxxxxxxxxx
当我尝试创建" firehoseClient,"时出现以下错误在我第一次试试之后:
构造函数AmazonKinesisFirehoseClient(AWSCredentials)是 弃用
我试图透过AWS' API,但找不到有效的构造函数。
package com.amazonaws.samples;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.Collection;
import com.amazonaws.*;
import com.amazonaws.AmazonClientException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.services.kinesisfirehose.model.PutRecordRequest;
import com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehoseClient;
import com.amazonaws.services.kinesisfirehose.model.Record;
import com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehoseClient;
import com.amazonaws.services.kinesisfirehose.*;
public class FirehoseExample {
public static void main(String[] args) {
AWSCredentials credentials = null;
try {
credentials = new ProfileCredentialsProvider().getCredentials();
}
catch (Exception e) {
throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
+ "Please make sure that your credentials file is at the correct "
+ "location (/Users/elybenari/.aws/credentials), and is in valid format.", e);
}
AmazonKinesisFirehoseClient firehoseClient = new AmazonKinesisFirehoseClient(credentials);
PutRecordRequest request = new PutRecordRequest();
request.setDeliveryStreamName("project-stream");
Record record = new Record();
for (int i = 0; i < 10*60; i++){
try {
URL url = new URL("https://www.google.com/finance/info?q=NASDAQ:AMZN");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
System.out.println(response.toString().replace("\n", "").replaceAll(" ", ""));
System.out.println("****\n");
ByteBuffer buff = ByteBuffer.wrap(response.toString().replace("\n", "").replaceAll(" ", "").getBytes());
record.setData(buff);
request.setRecord(record);
firehoseClient.putRecord(request);
Thread.sleep(2000);
}
catch(Exception e){
e.printStackTrace();
}
}
}
}
答案 0 :(得分:1)
使用static builder()方法代替不推荐使用的构造函数。
javadoc文档提出了这种方法,而不是使用弃用的构造函数:
AmazonKinesisFirehoseClient client = AmazonKinesisFirehoseClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build();
// You can now use the client as you normally would...
client.putRecord(xyz);