Search in sources :

Example 1 with GetRecordsRequest

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

the class KinesisConsumer method poll.

@Override
protected int poll() throws Exception {
    GetRecordsRequest req = new GetRecordsRequest().withShardIterator(getShardItertor()).withLimit(getEndpoint().getMaxResultsPerRequest());
    GetRecordsResult result = getClient().getRecords(req);
    Queue<Exchange> exchanges = createExchanges(result.getRecords());
    int processedExchangeCount = processBatch(CastUtils.cast(exchanges));
    // May cache the last successful sequence number, and pass it to the
    // getRecords request. That way, on the next poll, we start from where
    // we left off, however, I don't know what happens to subsequent
    // exchanges when an earlier echangee fails.
    currentShardIterator = result.getNextShardIterator();
    return processedExchangeCount;
}
Also used : Exchange(org.apache.camel.Exchange) GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Example 2 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project kafka-connect-kinesis by jcustenborder.

the class KinesisSourceTask method start.

@Override
public void start(Map<String, String> settings) {
    this.config = new KinesisSourceConnectorConfig(settings);
    this.kinesisClient = this.kinesisClientFactory.create(this.config);
    this.sourcePartition = ImmutableMap.of(RecordConverter.FIELD_SHARD_ID, this.config.kinesisShardId);
    Map<String, Object> lastOffset = this.context.offsetStorageReader().offset(this.sourcePartition);
    GetShardIteratorRequest shardIteratorRequest = new GetShardIteratorRequest().withShardId(this.config.kinesisShardId).withStreamName(this.config.kinesisStreamName);
    if (null != lastOffset && !lastOffset.isEmpty()) {
        String startingSequenceNumber = (String) lastOffset.get(RecordConverter.FIELD_SEQUENCE_NUMBER);
        log.info("start() - Starting iterator after last processed sequence number of '{}'", startingSequenceNumber);
        shardIteratorRequest.setShardIteratorType(ShardIteratorType.AFTER_SEQUENCE_NUMBER);
        shardIteratorRequest.setStartingSequenceNumber(startingSequenceNumber);
    } else {
        log.info("start() - Setting Shard Iterator Type to {} for {}", this.config.kinesisPosition, this.config.kinesisShardId);
        shardIteratorRequest.setShardIteratorType(this.config.kinesisPosition);
    }
    GetShardIteratorResult shardIteratorResult = this.kinesisClient.getShardIterator(shardIteratorRequest);
    log.info("start() - Using Shard Iterator {}", shardIteratorResult.getShardIterator());
    this.recordsRequest = new GetRecordsRequest().withLimit(this.config.kinesisRecordLimit).withShardIterator(shardIteratorResult.getShardIterator());
    this.recordConverter = new RecordConverter(this.config);
}
Also used : GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Example 3 with GetRecordsRequest

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

the class KinesisProxy method getRecords.

@Override
public GetRecordsResult getRecords(String shardIterator, int maxRecordsToGet) throws InterruptedException {
    final GetRecordsRequest getRecordsRequest = new GetRecordsRequest();
    getRecordsRequest.setShardIterator(shardIterator);
    getRecordsRequest.setLimit(maxRecordsToGet);
    GetRecordsResult getRecordsResult = null;
    int retryCount = 0;
    while (retryCount <= getRecordsMaxRetries && getRecordsResult == null) {
        try {
            getRecordsResult = kinesisClient.getRecords(getRecordsRequest);
        } catch (SdkClientException ex) {
            if (isRecoverableSdkClientException(ex)) {
                long backoffMillis = BACKOFF.calculateFullJitterBackoff(getRecordsBaseBackoffMillis, getRecordsMaxBackoffMillis, getRecordsExpConstant, retryCount++);
                LOG.warn("Got recoverable SdkClientException. Backing off for " + backoffMillis + " millis (" + ex.getClass().getName() + ": " + ex.getMessage() + ")");
                BACKOFF.sleep(backoffMillis);
            } else {
                throw ex;
            }
        }
    }
    if (getRecordsResult == null) {
        throw new RuntimeException("Retries exceeded for getRecords operation - all " + getRecordsMaxRetries + " retry attempts failed.");
    }
    return getRecordsResult;
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) SdkClientException(com.amazonaws.SdkClientException) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Example 4 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project druid by druid-io.

the class KinesisRecordSupplier method isClosedShardEmpty.

/**
 * Fetches records from the specified shard to determine if it is empty.
 * @param stream to which shard belongs
 * @param shardId of the closed shard
 * @return true if the closed shard is empty, false otherwise.
 */
public boolean isClosedShardEmpty(String stream, String shardId) {
    String shardIterator = kinesis.getShardIterator(stream, shardId, ShardIteratorType.TRIM_HORIZON.toString()).getShardIterator();
    GetRecordsRequest request = new GetRecordsRequest().withShardIterator(shardIterator).withLimit(1);
    GetRecordsResult shardData = kinesis.getRecords(request);
    return shardData.getRecords().isEmpty() && shardData.getNextShardIterator() == null;
}
Also used : GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest)

Example 5 with GetRecordsRequest

use of com.amazonaws.services.kinesis.model.GetRecordsRequest in project druid by druid-io.

the class KinesisRecordSupplier method getRecordsForLag.

private GetRecordsResult getRecordsForLag(String iteratorType, String offsetToUse, StreamPartition<String> partition) {
    String shardIterator = kinesis.getShardIterator(partition.getStream(), partition.getPartitionId(), iteratorType, offsetToUse).getShardIterator();
    GetRecordsResult recordsResult = kinesis.getRecords(new GetRecordsRequest().withShardIterator(shardIterator).withLimit(1));
    return recordsResult;
}
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