com.amazonaws.services.kinesis.model.Record.withData()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(133)

本文整理了Java中com.amazonaws.services.kinesis.model.Record.withData方法的一些代码示例,展示了Record.withData的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Record.withData方法的具体详情如下:
包路径:com.amazonaws.services.kinesis.model.Record
类名称:Record
方法名:withData

Record.withData介绍

[英]The data blob. The data in the blob is both opaque and immutable to Kinesis Data Streams, which does not inspect, interpret, or change the data in the blob in any way. When the data blob (the payload before base64-encoding) is added to the partition key size, the total size must not exceed the maximum record size (1 MB).

The AWS SDK for Java performs a Base64 encoding on this field before sending this request to the AWS service. Users of the SDK should not perform Base64 encoding on this field.

Warning: ByteBuffers returned by the SDK are mutable. Changes to the content or position of the byte buffer will be seen by all objects that have a reference to this object. It is recommended to call ByteBuffer.duplicate() or ByteBuffer.asReadOnlyBuffer() before using or reading from the buffer. This behavior will be changed in a future major version of the SDK.
[中]数据块。blob中的数据对Kinesis数据流来说既不透明又不可变,Kinesis数据流不会以任何方式检查、解释或更改blob中的数据。将数据blob(base64编码之前的有效负载)添加到分区密钥大小时,总大小不得超过最大记录大小(1MB)。
AWS SDK for Java在将此请求发送到AWS服务之前对该字段执行Base64编码。SDK用户不应在此字段上执行Base64编码。
警告:SDK返回的字节缓冲区是可变的。字节缓冲区的内容或位置的更改将被所有引用该对象的对象看到。建议致电ByteBuffer。复制()或字节缓冲。asReadOnlyBuffer()在使用或读取缓冲区之前。这种行为将在SDK的未来主要版本中更改。

代码示例

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-kinesis

private List<Record> generateRecords(int num) {
  List<Record> records = new ArrayList<>();
  for (int i = 0; i < num; i++) {
   byte[] value = new byte[1024];
   Arrays.fill(value, (byte) i);
   records.add(
     new Record()
       .withSequenceNumber(String.valueOf(i))
       .withPartitionKey("key")
       .withData(ByteBuffer.wrap(value)));
  }
  return records;
 }
}

代码示例来源:origin: Nextdoor/bender

Record rec = new Record();
rec.withPartitionKey("1").withSequenceNumber(r + "")
  .withData(ByteBuffer.wrap(line.getBytes()))
  .withApproximateArrivalTimestamp(approximateArrivalTimestamp);

代码示例来源:origin: apache/samza

private static List<Record> createRecords(int numRecords) {
  List<Record> records = new ArrayList<>(numRecords);
  Random rand = new Random();

  for (int i = 0; i < numRecords; i++) {
   String dataStr = "testData-" + System.currentTimeMillis();
   ByteBuffer data = ByteBuffer.wrap(dataStr.getBytes(StandardCharsets.UTF_8));
   String key = String.format("partitionKey-%d", rand.nextLong());
   String seqNum = String.format("%04d", 5 * i + 1);
   Record record = new Record()
     .withData(data)
     .withPartitionKey(key)
     .withSequenceNumber(seqNum)
     .withApproximateArrivalTimestamp(new Date());
   records.add(record);
  }
  return records;
 }
}

代码示例来源:origin: com.amazonaws/amazon-kinesis-client

.withData(ByteBuffer.wrap(mr.getData().toByteArray()))
.withPartitionKey(partitionKey)
.withSequenceNumber(r.getSequenceNumber())

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-kinesis

public Record convertToRecord() {
 return new Record()
   .withApproximateArrivalTimestamp(arrivalTimestamp.toDate())
   .withData(ByteBuffer.wrap(data.getBytes(StandardCharsets.UTF_8)))
   .withSequenceNumber(sequenceNumber)
   .withPartitionKey("");
}

代码示例来源:origin: Nextdoor/bender

public static KinesisEvent createEvent(Class clazz, String resource)
  throws UnsupportedEncodingException, IOException {
 /*
  * Create a kinesis record from a sample JSON file
  */
 String json =
   IOUtils.toString(new InputStreamReader(clazz.getResourceAsStream(resource), "UTF-8"));
 Date approximateArrivalTimestamp = new Date();
 approximateArrivalTimestamp.setTime(1478737790000l);
 Record rec = new Record();
 rec.withPartitionKey("1").withSequenceNumber("2").withData(ByteBuffer.wrap(json.getBytes()))
   .withApproximateArrivalTimestamp(approximateArrivalTimestamp);
 /*
  * Create a KinesisEventRecord and add single Record
  */
 KinesisEventRecord krecord = new KinesisEventRecord();
 krecord.setKinesis(rec);
 krecord.setEventSourceARN("arn:aws:kinesis:us-east-1:1234:stream/test-events-stream");
 krecord.setEventID("shardId-000000000000:1234");
 /*
  * Add single KinesisEventRecord to a KinesisEvent
  */
 KinesisEvent kevent = new KinesisEvent();
 List<KinesisEventRecord> events = new ArrayList<KinesisEventRecord>(1);
 events.add(krecord);
 kevent.setRecords(events);
 return kevent;
}

代码示例来源:origin: spring-projects/spring-integration-aws

.withPartitionKey("partition1")
.withSequenceNumber("1")
.withData(ByteBuffer.wrap("foo".getBytes()))));

代码示例来源:origin: spring-projects/spring-integration-aws

.withPartitionKey("partition1")
    .withSequenceNumber("1")
    .withData(ByteBuffer.wrap(serializingConverter.convert("foo"))),
new Record()
    .withPartitionKey("partition1")
    .withSequenceNumber("2")
    .withData(ByteBuffer.wrap(serializingConverter.convert("bar")))));
.withPartitionKey("partition1")
.withSequenceNumber("2")
.withData(ByteBuffer.wrap(serializingConverter.convert("bar")))));

相关文章