Live2D

JAVA AWS Kinesis的PutRecord

AWS Kinesis的PutRecord

package com.example.firehose;

import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehose;
import com.amazonaws.services.kinesisfirehose.AmazonKinesisFirehoseClient;
import com.amazonaws.services.kinesisfirehose.model.PutRecordRequest;
import com.amazonaws.services.kinesisfirehose.model.PutRecordResult;
import com.amazonaws.services.kinesisfirehose.model.Record;

import java.nio.ByteBuffer;

public class FireHoseController {
    private static String access_key_id = "";
    private static String secret_key_id = "";
    private static AmazonKinesisFirehose build;
    static {        
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(access_key_id, secret_key_id);
        // withRegion("us-east-1") 表示你的节点
        build = AmazonKinesisFirehoseClient.builder().withRegion("us-east-1")
            .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
            .build();

    }
 
    public static PutRecordResult fireHose() {
 
        PutRecordRequest putRecordRequest = new PutRecordRequest();
        // 流的名称
        putRecordRequest.setDeliveryStreamName("callback");
        // 要投递的数据
        String data = "11111111111111" + "\n";
 
        Record record = new Record().withData(ByteBuffer.wrap(data.getBytes()));
        putRecordRequest.setRecord(record);
 
        // Put record into the DeliveryStream
        PutRecordResult putRecord = build.putRecord(putRecordRequest);
        return putRecord;
    }
    public static void main(String[] args) {
        System.out.println( fireHose());
    }
}
posted @ 2022-01-12 10:11  没有梦想的java菜鸟  阅读(124)  评论(0编辑  收藏  举报