当前位置: 首页>>代码示例>>Java>>正文


Java Record类代码示例

本文整理汇总了Java中com.amazonaws.services.kinesis.model.Record的典型用法代码示例。如果您正苦于以下问题:Java Record类的具体用法?Java Record怎么用?Java Record使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Record类属于com.amazonaws.services.kinesis.model包,在下文中一共展示了Record类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processRecords

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
@Override
public void processRecords(List<Record> records,
		IRecordProcessorCheckpointer checkpointer) {
	LOG.info(String.format("Received %s Records", records.size()));
	
	// add a call to your business logic here!
	//
	// myLinkedClasses.doSomething(records)
	//
	//
	try {
		checkpointer.checkpoint();
	} catch (KinesisClientLibDependencyException | InvalidStateException
			| ThrottlingException | ShutdownException e) {
		e.printStackTrace();
		super.shutdown(checkpointer, ShutdownReason.ZOMBIE);
	}
}
 
开发者ID:awslabs,项目名称:aws-kinesis-beanstalk-workers,代码行数:19,代码来源:MyRecordProcessor.java

示例2: KinesisWrapper

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
private KinesisWrapper(final InternalEvent internal) {
  KinesisEventRecord eventRecord = ((KinesisInternalEvent) internal).getRecord();
  Record record = eventRecord.getKinesis();

  this.partitionKey = record.getPartitionKey();
  this.sequenceNumber = record.getSequenceNumber();
  this.eventSource = eventRecord.getEventSource();
  this.sourceArn = eventRecord.getEventSourceARN();
  this.functionName = internal.getCtx().getFunctionName();
  this.functionVersion = internal.getCtx().getFunctionVersion();
  this.processingTime = System.currentTimeMillis();
  this.arrivalTime = record.getApproximateArrivalTimestamp().getTime();
  this.timestamp = internal.getEventTime();
  this.processingDelay = processingTime - timestamp;

  if (internal.getEventObj() != null) {
    this.payload = internal.getEventObj().getPayload();
  } else {
    this.payload = null;
  }
}
 
开发者ID:Nextdoor,项目名称:bender,代码行数:22,代码来源:KinesisWrapper.java

示例3: processRecords

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
@SneakyThrows
@Override
public void processRecords(ProcessRecordsInput processRecordsInput) {
    List<Record> records = processRecordsInput.getRecords();
    // Used to update the last processed record
    IRecordProcessorCheckpointer checkpointer = processRecordsInput.getCheckpointer();
    log.info("Recovering records from kinesis.");
    for (Record r : records) {
        try {
            int len = r.getData().remaining();
            byte[] buffer = new byte[len];
            r.getData().get(buffer);
            String json = new String(buffer, "UTF-8");
            ZombieLecture lecture = mapper.readValue(json, ZombieLecture.class);
            this.processZombieLecture(lecture);
            log.debug(processedRecords++ + ": " + json);
            if (processedRecords % 1000 == 999) {
                // Uncomment next line to keep track of the processed lectures. 
                checkpointer.checkpoint();
            }
        } catch (UnsupportedEncodingException | MessagingException ex) {
            log.warn(ex.getMessage());
        }
    }
}
 
开发者ID:capside,项目名称:aws-kinesis-zombies,代码行数:26,代码来源:ZombieRecordProcessor.java

示例4: getKinesisClient

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
@Override
public AmazonKinesis getKinesisClient() {
  return new AmazonKinesisMock(transform(shardedData,
      new Function<List<TestData>, List<Record>>() {

        @Override
        public List<Record> apply(@Nullable List<TestData> testDatas) {
          return transform(testDatas, new Function<TestData, Record>() {

            @Override
            public Record apply(@Nullable TestData testData) {
              return testData.convertToRecord();
            }
          });
        }
      }), numberOfRecordsPerGet);

}
 
开发者ID:apache,项目名称:beam,代码行数:19,代码来源:AmazonKinesisMock.java

示例5: recordsAreSentToTheProcessor

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
@Test
public void recordsAreSentToTheProcessor() throws Exception {
    when(kinesisClient.getRecords(any(GetRecordsRequest.class)))
        .thenReturn(new GetRecordsResult()
            .withNextShardIterator("nextShardIterator")
            .withRecords(new Record().withSequenceNumber("1"), new Record().withSequenceNumber("2"))
        );

    int messageCount = undertest.poll();

    assertThat(messageCount, is(2));
    final ArgumentCaptor<Exchange> exchangeCaptor = ArgumentCaptor.forClass(Exchange.class);

    verify(processor, times(2)).process(exchangeCaptor.capture(), any(AsyncCallback.class));
    assertThat(exchangeCaptor.getAllValues().get(0).getIn().getBody(Record.class).getSequenceNumber(), is("1"));
    assertThat(exchangeCaptor.getAllValues().get(1).getIn().getBody(Record.class).getSequenceNumber(), is("2"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:KinesisConsumerTest.java

示例6: exchangePropertiesAreSet

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
@Test
public void exchangePropertiesAreSet() throws Exception {
    String partitionKey = "partitionKey";
    String sequenceNumber = "1";
    when(kinesisClient.getRecords(any(GetRecordsRequest.class)))
        .thenReturn(new GetRecordsResult()
            .withNextShardIterator("nextShardIterator")
            .withRecords(new Record()
                .withSequenceNumber(sequenceNumber)
                .withApproximateArrivalTimestamp(new Date(42))
                .withPartitionKey(partitionKey)
            )
        );

    undertest.poll();

    final ArgumentCaptor<Exchange> exchangeCaptor = ArgumentCaptor.forClass(Exchange.class);

    verify(processor).process(exchangeCaptor.capture(), any(AsyncCallback.class));
    assertThat(exchangeCaptor.getValue().getIn().getHeader(KinesisConstants.APPROX_ARRIVAL_TIME, long.class), is(42L));
    assertThat(exchangeCaptor.getValue().getIn().getHeader(KinesisConstants.PARTITION_KEY, String.class), is(partitionKey));
    assertThat(exchangeCaptor.getValue().getIn().getHeader(KinesisConstants.SEQUENCE_NUMBER, String.class), is(sequenceNumber));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:KinesisConsumerTest.java

示例7: emitTuples

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
/**
 * Implement InputOperator Interface.
 */
@Override
public void emitTuples()
{
  if (currentWindowId <= windowDataManager.getLargestCompletedWindow()) {
    return;
  }
  int count = consumer.getQueueSize();
  if (maxTuplesPerWindow > 0) {
    count = Math.min(count, maxTuplesPerWindow - emitCount);
  }
  for (int i = 0; i < count; i++) {
    Pair<String, Record> data = consumer.pollRecord();
    String shardId = data.getFirst();
    String recordId = data.getSecond().getSequenceNumber();
    emitTuple(data);
    MutablePair<String, Integer> shardOffsetAndCount = currentWindowRecoveryState.get(shardId);
    if (shardOffsetAndCount == null) {
      currentWindowRecoveryState.put(shardId, new MutablePair<String, Integer>(recordId, 1));
    } else {
      shardOffsetAndCount.setRight(shardOffsetAndCount.right + 1);
    }
    shardPosition.put(shardId, recordId);
  }
  emitCount += count;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:29,代码来源:AbstractKinesisInputOperator.java

示例8: processNextIterator

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
public String processNextIterator(String iterator)
{
  GetRecordsRequest getRequest = new GetRecordsRequest();
  getRequest.setLimit(1000);

  getRequest.setShardIterator(iterator);
  // call "get" operation and get everything in this shard range
  GetRecordsResult getResponse = client.getRecords(getRequest);

  iterator = getResponse.getNextShardIterator();

  List<Record> records = getResponse.getRecords();
  processResponseRecords(records);

  return iterator;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:17,代码来源:KinesisTestConsumer.java

示例9: processResponseRecords

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
protected void processResponseRecords( List<Record> records )
{
  if ( records == null || records.isEmpty() ) {
    return;
  }
  receiveCount += records.size();
  logger.debug("ReceiveCount= {}", receiveCount);

  for ( Record record : records ) {
    holdingBuffer.add(record);
    if ( shouldProcessRecord ) {
      processRecord( record );
    }

    if ( doneLatch != null ) {
      doneLatch.countDown();
    }
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:20,代码来源:KinesisTestConsumer.java

示例10: processRecord

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
@Override
protected void processRecord(Record record)
{
  String partitionKey = record.getPartitionKey();
  ByteBuffer data = record.getData();
  logger.info("partitionKey={} ", partitionKey);
  byte[] dataBytes = new byte[data.remaining()];
  data.get(dataBytes, 0, dataBytes.length);

  long key = Long.valueOf(partitionKey);
  TestPOJO expected = new TestPOJO(key);

  TestPOJO read = (TestPOJO)fieldValueGenerator.deserializeObject(dataBytes);

  if (!read.outputFieldsEquals(expected)) {
    logger.error("read is not same as expected. read={}, expected={}", read, expected);
    Assert.assertTrue(false);
  } else {
    logger.info("read is same as expected. read={}, expected={}", read, expected);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:22,代码来源:KinesisByteArrayOutputOperatorTest.java

示例11: processSingleRecord

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
/**
 * Process a single record.
 *
 * @param record The record to be processed.
 */
private void processSingleRecord(Record record) {

    if (producer == null) {
        producer = createProducer();
    }

    String kafkaServers = System.getenv().get("KAFKA_SERVERS");
    if (null == kafkaServers) {
        kafkaServers = Constants.KAFKA_SERVERS;
    }

    ByteBuffer data = record.getData();


    retryCounter = 0;
    // sending event to Queue
    ProducerRecord<String, byte[]> keyedMessage = new ProducerRecord<>(
            TestConstants.topic,
            TestConstants.partition, data.array());
    this.sendMessage(keyedMessage);
}
 
开发者ID:SaschaMoellering,项目名称:ingestion-service,代码行数:27,代码来源:RecordProcessor.java

示例12: verifyRecords

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
private void verifyRecords(List<IncomingMessageEnvelope> outputRecords, List<Record> inputRecords, String shardId) {
  Iterator outputRecordsIter = outputRecords.iterator();
  inputRecords.forEach(record -> {
      IncomingMessageEnvelope envelope = (IncomingMessageEnvelope) outputRecordsIter.next();
      String outputKey = (String) envelope.getKey();
      KinesisIncomingMessageEnvelope kinesisMessageEnvelope = (KinesisIncomingMessageEnvelope) envelope;
      Assert.assertEquals(outputKey, record.getPartitionKey());
      Assert.assertEquals(kinesisMessageEnvelope.getSequenceNumber(), record.getSequenceNumber());
      Assert.assertEquals(kinesisMessageEnvelope.getApproximateArrivalTimestamp(),
          record.getApproximateArrivalTimestamp());
      Assert.assertEquals(kinesisMessageEnvelope.getShardId(), shardId);
      ByteBuffer outputData = ByteBuffer.wrap((byte[]) kinesisMessageEnvelope.getMessage());
      record.getData().rewind();
      Assert.assertTrue(outputData.equals(record.getData()));
      verifyOffset(envelope.getOffset(), record, shardId);
    });
}
 
开发者ID:apache,项目名称:samza,代码行数:18,代码来源:TestKinesisSystemConsumer.java

示例13: generateRecords

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
static Map<KinesisRecordProcessor, List<Record>> generateRecords(int numRecordsPerShard,
    List<KinesisRecordProcessor> processors) throws ShutdownException, InvalidStateException {
  Map<KinesisRecordProcessor, List<Record>> processorRecordMap = new HashMap<>();
  processors.forEach(processor -> {
      try {
        // Create records and call process records
        IRecordProcessorCheckpointer checkpointer = Mockito.mock(IRecordProcessorCheckpointer.class);
        doNothing().when(checkpointer).checkpoint(anyString());
        doNothing().when(checkpointer).checkpoint();
        ProcessRecordsInput processRecordsInput = Mockito.mock(ProcessRecordsInput.class);
        when(processRecordsInput.getCheckpointer()).thenReturn(checkpointer);
        when(processRecordsInput.getMillisBehindLatest()).thenReturn(1000L);
        List<Record> inputRecords = createRecords(numRecordsPerShard);
        processorRecordMap.put(processor, inputRecords);
        when(processRecordsInput.getRecords()).thenReturn(inputRecords);
        processor.processRecords(processRecordsInput);
      } catch (ShutdownException | InvalidStateException ex) {
        throw new RuntimeException(ex);
      }
    });
  return processorRecordMap;
}
 
开发者ID:apache,项目名称:samza,代码行数:23,代码来源:TestKinesisRecordProcessor.java

示例14: createRecords

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:samza,代码行数:19,代码来源:TestKinesisRecordProcessor.java

示例15: theTransformerShouldFailGracefullyWhenUnableToCompress

import com.amazonaws.services.kinesis.model.Record; //导入依赖的package包/类
@Test
public void theTransformerShouldFailGracefullyWhenUnableToCompress () {
  CloudWatchMessageModelSumologicTransformer transfomer = new CloudWatchMessageModelSumologicTransformer();
  
  String randomData = "Some random string without GZIP compression";
  ByteBuffer bufferedData = null;
  try {
    bufferedData = encoder.encode(CharBuffer.wrap(randomData));
  } catch (Exception e) {
    Assert.fail("Getting error: "+e.getMessage());
  }
  
  Record mockedRecord = new Record();
  mockedRecord.setData(bufferedData);
  
  CloudWatchLogsMessageModel messageModel = transfomer.toClass(mockedRecord);
  
  
  Assert.assertNull(messageModel);
}
 
开发者ID:SumoLogic,项目名称:sumologic-kinesis-connector,代码行数:21,代码来源:CloudWatchMessageModelSumologicTransformerTest.java


注:本文中的com.amazonaws.services.kinesis.model.Record类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。