Java 类com.amazonaws.services.kinesis.model.PutRecordsRequestEntry 实例源码

项目:apex-malhar    文件:KinesisTestProducer.java   
private void generateRecords()
{
  // Create dummy message
  int recordNo = 1;
  while (recordNo <= sendCount) {
    String dataStr = "Record_" + recordNo;
    PutRecordsRequestEntry putRecordsEntry = new PutRecordsRequestEntry();
    putRecordsEntry.setData(ByteBuffer.wrap(dataStr.getBytes()));
    putRecordsEntry.setPartitionKey(dataStr);
    putRecordsRequestEntryList.add(putRecordsEntry);
    if ( (putRecordsRequestEntryList.size() == batchSize) || (recordNo == sendCount )) {
      PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
      putRecordsRequest.setStreamName(streamName);
      putRecordsRequest.setRecords(putRecordsRequestEntryList);
      client.putRecords(putRecordsRequest);
      putRecordsRequestEntryList.clear();
    }
    recordNo++;
  }
}
项目:presto-kinesis    文件:TestRecordAccess.java   
private void createDummyMessages(String streamName, int count)
        throws Exception
{
    PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
    putRecordsRequest.setStreamName(streamName);
    List<PutRecordsRequestEntry> putRecordsRequestEntryList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        PutRecordsRequestEntry putRecordsRequestEntry = new PutRecordsRequestEntry();
        putRecordsRequestEntry.setData(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes()));
        putRecordsRequestEntry.setPartitionKey(Long.toString(i));
        putRecordsRequestEntryList.add(putRecordsRequestEntry);
    }

    putRecordsRequest.setRecords(putRecordsRequestEntryList);
    mockClient.putRecords(putRecordsRequest);
}
项目:presto-kinesis    文件:TestRecordAccess.java   
private void createJsonMessages(String streamName, int count, int idStart)
        throws Exception
{
    String jsonFormat = "{\"id\" : %d, \"name\" : \"%s\"}";
    PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
    putRecordsRequest.setStreamName(streamName);
    List<PutRecordsRequestEntry> putRecordsRequestEntryList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        PutRecordsRequestEntry putRecordsRequestEntry = new PutRecordsRequestEntry();
        long id = idStart + i;
        String name = UUID.randomUUID().toString();
        String jsonVal = String.format(jsonFormat, id, name);

        // ? with StandardCharsets.UTF_8
        putRecordsRequestEntry.setData(ByteBuffer.wrap(jsonVal.getBytes()));
        putRecordsRequestEntry.setPartitionKey(Long.toString(id));
        putRecordsRequestEntryList.add(putRecordsRequestEntry);
    }

    putRecordsRequest.setRecords(putRecordsRequestEntryList);
    mockClient.putRecords(putRecordsRequest);
}
项目:presto-kinesis    文件:MockKinesisClient.java   
@Override
public PutRecordsResult putRecords(PutRecordsRequest putRecordsRequest) throws AmazonServiceException, AmazonClientException
{
    // Setup method to add a batch of new records:
    InternalStream theStream = this.getStream(putRecordsRequest.getStreamName());
    if (theStream != null) {
        PutRecordsResult result = new PutRecordsResult();
        ArrayList<PutRecordsResultEntry> resultList = new ArrayList<PutRecordsResultEntry>();
        for (PutRecordsRequestEntry entry : putRecordsRequest.getRecords()) {
            PutRecordResult putResult = theStream.putRecord(entry.getData(), entry.getPartitionKey());
            resultList.add((new PutRecordsResultEntry()).withShardId(putResult.getShardId()).withSequenceNumber(putResult.getSequenceNumber()));
        }

        result.setRecords(resultList);
        return result;
    }
    else {
        throw new AmazonClientException("This stream does not exist!");
    }
}
项目:presto-kinesis    文件:TestMinimalFunctionality.java   
private void createMessages(String streamName, int count)
        throws Exception
{
    PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
    putRecordsRequest.setStreamName(streamName);
    List<PutRecordsRequestEntry> putRecordsRequestEntryList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        PutRecordsRequestEntry putRecordsRequestEntry = new PutRecordsRequestEntry();
        putRecordsRequestEntry.setData(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes()));
        putRecordsRequestEntry.setPartitionKey(Long.toString(i));
        putRecordsRequestEntryList.add(putRecordsRequestEntry);
    }

    putRecordsRequest.setRecords(putRecordsRequestEntryList);
    embeddedKinesisStream.getKinesisClient().putRecords(putRecordsRequest);
}
项目:miru    文件:HttpKinesisLogAppenderTest.java   
@Test(enabled = false)
public void testKinesisPutRecords() throws Exception {
    List<LogEvent> logEventList = Collections.singletonList(
        Log4jLogEvent.createEvent("foobar", null, "foo.bar", Level.ERROR, null, null, null, null, null, "tname", null, 12345));

    Collection<PutRecordsRequestEntry> records = new ArrayList<>();
    for (LogEvent logEvent : logEventList) {
        String toJson = objectMapper.writeValueAsString(logEvent);
        PutRecordsRequestEntry putRecordsRequestEntry = new PutRecordsRequestEntry()
            .withData(ByteBuffer.wrap(toJson.getBytes()))
            .withPartitionKey("testKinesisPutRecords");
        records.add(putRecordsRequestEntry);
    }

    PutRecordsRequest putRecordsRequest = new PutRecordsRequest();
    putRecordsRequest.setRecords(records);
    putRecordsRequest.setStreamName(awsStreamName);
    PutRecordsResult putRecordsResult = client.putRecords(putRecordsRequest);
    System.out.println(putRecordsResult.toString());
}
项目:lumber-mill    文件:SimpleRetryableKinesisClient.java   
/**
 * Converts event to actual kinesis entry type
 */
private PutRecordsRequestEntry toRecordEntries(T event) {
    //Optional<String> partitionKey = partitionKeyTemplate.format(event);
    return new PutRecordsRequestEntry().withData (
            event.raw().asByteBuffer())
            // FIXME: If partitionkey does not return a value, what approach is best?
            .withPartitionKey(partitionKeySupplier.isPresent()
                    ? partitionKeySupplier.get().get().format(event).get()
                    : UUID.randomUUID().toString());
}
项目:lumber-mill    文件:SimpleRetryableKinesisClient.java   
/**
 * Based on the request and the result, returns a new request
 * containing the records that failed.
 * @param result is the last PutRecordsResult
 * @return a new PutRecordsRequest with failing records
 */
private PutRecordsRequest failedRecords(PutRecordsResult result) {
    List<PutRecordsRequestEntry> newRecords = new ArrayList<>();
    List<PutRecordsResultEntry> records = result.getRecords();
    for (int i = 0; i < records.size(); i++) {
        if (records.get(i).getErrorCode() != null) {
            newRecords.add(putRecordsRequest.getRecords().get(i));
        }
    }
    return new PutRecordsRequest()
            .withRecords(newRecords)
            .withStreamName(putRecordsRequest.getStreamName());
}
项目:apex-malhar    文件:AbstractKinesisOutputOperator.java   
private void addRecord(T tuple)
{
  try {
    Pair<String, V> keyValue = tupleToKeyValue(tuple);
    PutRecordsRequestEntry putRecordsEntry = new PutRecordsRequestEntry();
    putRecordsEntry.setData(ByteBuffer.wrap(getRecord(keyValue.second)));
    putRecordsEntry.setPartitionKey(keyValue.first);
    putRecordsRequestEntryList.add(putRecordsEntry);
  } catch (AmazonClientException e) {
    throw new RuntimeException(e);
  }
}
项目:datacollector    文件:KinesisSourceIT.java   
private static Collection<PutRecordsRequestEntry> getRecords(int numRecords) {
  return IntStream.range(0, numRecords).mapToObj(i -> {
    PutRecordsRequestEntry record = new PutRecordsRequestEntry();
    record.setData(ByteBuffer.wrap("{\"a\":1,\"b\":2,\"c\":2}".getBytes(Charsets.UTF_8)));
    record.setPartitionKey(String.valueOf(i));
    return record;
  }).collect(Collectors.toList());
}
项目:aws-big-data-blog    文件:RecordBatcher.java   
public Optional<PutRecordsRequest> put(PutRecordsRequestEntry entry) {
    int newRequestSize = requestSize + entry.getData().remaining()
            + entry.getPartitionKey().length();
    if (entries.size() < maxCount && newRequestSize <= maxSize) {
        requestSize = newRequestSize;
        entries.add(entry);
        return Optional.empty();
    } else {
        Optional<PutRecordsRequest> ret = flush();
        put(entry);
        return ret;
    }
}
项目:aws-big-data-blog    文件:BatchedClickEventsToKinesis.java   
@Override
protected void runOnce() throws Exception {
    ClickEvent event = inputQueue.take();
    String partitionKey = event.getSessionId();
    ByteBuffer data = ByteBuffer.wrap(
            event.getPayload().getBytes("UTF-8"));
    recordsPut.getAndIncrement();

    addEntry(new PutRecordsRequestEntry()
            .withPartitionKey(partitionKey)
            .withData(data));
}
项目:aws-big-data-blog    文件:BatchedClickEventsToKinesis.java   
protected void addEntry(PutRecordsRequestEntry entry) {
    int newDataSize = dataSize + entry.getData().remaining() +
            entry.getPartitionKey().length();
    if (newDataSize <= 5 * 1024 * 1024 && entries.size() < 500) {
        dataSize = newDataSize;
        entries.add(entry);
    } else {
        flush();
        dataSize = 0;
        addEntry(entry);
    }
}
项目:datacollector    文件:KinesisSourceIT.java   
private static PutRecordsRequestEntry getBadRecord() {
  PutRecordsRequestEntry badRecord = new PutRecordsRequestEntry();
  badRecord.setData(ByteBuffer.wrap("{\"a\":1,\"b\":2,\"c\":2,".getBytes(Charsets.UTF_8)));
  badRecord.setPartitionKey(String.valueOf(0));
  return badRecord;
}