Search in sources :

Example 6 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project apex-malhar by apache.

the class KinesisUtil method getRecords.

/**
 * Get the records from the particular shard
 * @param streamName Name of the stream from where the records to be accessed
 * @param recordsLimit Number of records to return from shard
 * @param shId Shard Id of the shard
 * @param iteratorType Shard iterator type
 * @param seqNo Record sequence number
 * @return the list of records from the given shard
 * @throws AmazonClientException
 */
public List<Record> getRecords(String streamName, Integer recordsLimit, String shId, ShardIteratorType iteratorType, String seqNo) throws AmazonClientException {
    assert client != null : "Illegal client";
    try {
        // Create the GetShardIteratorRequest instance and sets streamName, shardId and iteratorType to it
        GetShardIteratorRequest iteratorRequest = new GetShardIteratorRequest();
        iteratorRequest.setStreamName(streamName);
        iteratorRequest.setShardId(shId);
        iteratorRequest.setShardIteratorType(iteratorType);
        // If the iteratorType is AFTER_SEQUENCE_NUMBER, set the sequence No to the iteratorRequest
        if (ShardIteratorType.AFTER_SEQUENCE_NUMBER.equals(iteratorType) || ShardIteratorType.AT_SEQUENCE_NUMBER.equals(iteratorType)) {
            iteratorRequest.setStartingSequenceNumber(seqNo);
        }
        // Get the Response from the getShardIterator service method & get the shardIterator from that response
        GetShardIteratorResult iteratorResponse = client.getShardIterator(iteratorRequest);
        // getShardIterator() specifies the position in the shard
        String iterator = iteratorResponse.getShardIterator();
        // Create the GetRecordsRequest instance and set the recordsLimit and iterator
        GetRecordsRequest getRequest = new GetRecordsRequest();
        getRequest.setLimit(recordsLimit);
        getRequest.setShardIterator(iterator);
        // Get the Response from the getRecords service method and get the data records from that response.
        GetRecordsResult getResponse = client.getRecords(getRequest);
        return getResponse.getRecords();
    } catch (AmazonClientException e) {
        throw new RuntimeException(e);
    }
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) AmazonClientException(com.amazonaws.AmazonClientException) GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Example 7 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project apex-malhar by apache.

the class KinesisTestConsumer method processNextIterator.

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;
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) Record(com.amazonaws.services.kinesis.model.Record) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Example 8 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project beam by apache.

the class SimplifiedKinesisClientTest method shouldReturnLimitedNumberOfRecords.

@Test
public void shouldReturnLimitedNumberOfRecords() throws Exception {
    final Integer limit = 100;
    doAnswer((Answer<GetRecordsResult>) invocation -> {
        GetRecordsRequest request = (GetRecordsRequest) invocation.getArguments()[0];
        List<Record> records = generateRecords(request.getLimit());
        return new GetRecordsResult().withRecords(records).withMillisBehindLatest(1000L);
    }).when(kinesis).getRecords(any(GetRecordsRequest.class));
    GetKinesisRecordsResult result = underTest.getRecords(SHARD_ITERATOR, STREAM, SHARD_1, limit);
    assertThat(result.getRecords().size()).isEqualTo(limit);
}
Also used : Shard(com.amazonaws.services.kinesis.model.Shard) Minutes(org.joda.time.Minutes) DescribeStreamSummaryResult(com.amazonaws.services.kinesis.model.DescribeStreamSummaryResult) StreamDescriptionSummary(com.amazonaws.services.kinesis.model.StreamDescriptionSummary) Arrays(java.util.Arrays) Record(com.amazonaws.services.kinesis.model.Record) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException) Duration(org.joda.time.Duration) RunWith(org.junit.runner.RunWith) Supplier(java.util.function.Supplier) ShardFilterType(com.amazonaws.services.kinesis.model.ShardFilterType) ByteBuffer(java.nio.ByteBuffer) Mockito.verifyZeroInteractions(org.mockito.Mockito.verifyZeroInteractions) Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) ArrayList(java.util.ArrayList) InitialPositionInStream(com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream) GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) Answer(org.mockito.stubbing.Answer) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) InjectMocks(org.mockito.InjectMocks) GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) DescribeStreamSummaryRequest(com.amazonaws.services.kinesis.model.DescribeStreamSummaryRequest) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis) ShardIteratorType(com.amazonaws.services.kinesis.model.ShardIteratorType) ErrorType(com.amazonaws.AmazonServiceException.ErrorType) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Matchers.any(org.mockito.Matchers.any) GetMetricStatisticsRequest(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest) List(java.util.List) LimitExceededException(com.amazonaws.services.kinesis.model.LimitExceededException) Instant(org.joda.time.Instant) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest) GetMetricStatisticsResult(com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult) Mockito.reset(org.mockito.Mockito.reset) ExpiredIteratorException(com.amazonaws.services.kinesis.model.ExpiredIteratorException) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assertions.failBecauseExceptionWasNotThrown(org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter) GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) ArrayList(java.util.ArrayList) List(java.util.List) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest) Test(org.junit.Test)

Example 9 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project hazelcast by hazelcast.

the class ShardReader method getRecordsAsync.

private Future<GetRecordsResult> getRecordsAsync(String shardIterator) {
    GetRecordsRequest request = new GetRecordsRequest();
    request.setShardIterator(shardIterator);
    return kinesis.getRecordsAsync(request);
}
Also used : GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Example 10 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project storm by apache.

the class KinesisConnection method fetchRecords.

GetRecordsResult fetchRecords(String shardIterator) {
    GetRecordsRequest getRecordsRequest = new GetRecordsRequest();
    getRecordsRequest.setShardIterator(shardIterator);
    getRecordsRequest.setLimit(kinesisConnectionInfo.getRecordsLimit());
    GetRecordsResult getRecordsResult = kinesisClient.getRecords(getRecordsRequest);
    return getRecordsResult;
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Aggregations

GetRecordsRequest (com.amazonaws.services.kinesis.model.GetRecordsRequest)12 GetRecordsResult (com.amazonaws.services.kinesis.model.GetRecordsResult)10 GetShardIteratorResult (com.amazonaws.services.kinesis.model.GetShardIteratorResult)4 GetShardIteratorRequest (com.amazonaws.services.kinesis.model.GetShardIteratorRequest)3 Record (com.amazonaws.services.kinesis.model.Record)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AmazonKinesis (com.amazonaws.services.kinesis.AmazonKinesis)2 ExpiredIteratorException (com.amazonaws.services.kinesis.model.ExpiredIteratorException)2 ListShardsRequest (com.amazonaws.services.kinesis.model.ListShardsRequest)2 ListShardsResult (com.amazonaws.services.kinesis.model.ListShardsResult)2 ProvisionedThroughputExceededException (com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException)2 Shard (com.amazonaws.services.kinesis.model.Shard)2 ShardIteratorType (com.amazonaws.services.kinesis.model.ShardIteratorType)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ErrorType (com.amazonaws.AmazonServiceException.ErrorType)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 SdkClientException (com.amazonaws.SdkClientException)1