我正在使用AWS SDK從將數據發佈到Kinesis流的Java應用程序寫入數據。使用下面的代碼一次批量完成10條記錄;將Kinesis中的數據寫入S3
// Convert to JSON object, and then to bytes...
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
String json = ow.writeValueAsString(transaction);
// Add byte array to PutRecordsRequestEntry
PutRecordsRequestEntry record = new PutRecordsRequestEntry();
record.setPartitionKey(String.valueOf(java.util.UUID.randomUUID()));
record.setData(ByteBuffer.wrap(json.getBytes()));
// Add to list...
batch.add(record);
// Check and send batches
if(counter>=batchLimit){
logger.info("Sending batch of " + batchLimit + " rows.");
putRecordsRequest.setRecords(batch);
PutRecordsResult result = amazonKinesisClient.putRecords(putRecordsRequest);
batch = new ArrayList<>();
counter=0;
}else{
counter++;
}
然後我有室壁運動收到了被觸發。每筆交易的NodeJS lambda函數,這種想法是爲它寫從室壁運動來進行交易,並把它們轉化爲他們的數據來流水流保存到S3。
var AWS = require('aws-sdk');
var firehose = new AWS.Firehose();
exports.handler = function(event, context) {
console.log(event);
var params = {
DeliveryStreamName: "transaction-postings",
Record: {
Data: decodeURIComponent(event)
}
};
firehose.putRecord(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
console.log(data); // successful response
}
context.done();
});
};
然而,在S3上的數據看時,我看到的是下面的,並沒有像我期待的對象的JSON列表...
[object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object][object Object]
可有人請點我什麼我錯過了將Kinesis中的數據作爲JSON對象流向s3嗎?
剛做了改變,仍然得到「[object object]」「[object object]」「[object object]」「[object Object]」「[object Object]」「[object Object]」 「[對象對象]」「[對象對象]」「[對象對象]」「[對象對象]」「[對象對象]」「[對象對象]結果是 – Mez
實際上,當我將這行代碼更改爲「Data:event」時,我在S3中得到了例子:{「Records」:[{「kinesis」:{「kinesisSchemaVersion」:「1.0」,「partitionKey 「:」2a4bb9d9-a023-4c03-8616-ef3e7c567459「,」sequenceNumber「:」49571132156681255058105982946244422009241197082071531522「,」data「:」ewogICJyb3dJZCIgOiA3MjEzMTU0NSwKICAi ......爲什麼我沒有得到上面發送的實際JSON對象? – Mez
我認爲這是因爲當設置數據record.setData(ByteBuffer.wrap(json.getBytes()))...我需要轉換回utf8。 – Mez