Search in sources :

Example 1 with GetRecordsResult

use of com.amazonaws.services.dynamodbv2.model.GetRecordsResult in project camel by apache.

the class DdbStreamConsumer method poll.

@Override
protected int poll() throws Exception {
    GetRecordsResult result;
    try {
        GetRecordsRequest req = new GetRecordsRequest().withShardIterator(shardIteratorHandler.getShardIterator(null)).withLimit(getEndpoint().getMaxResultsPerRequest());
        result = getClient().getRecords(req);
    } catch (ExpiredIteratorException e) {
        LOG.warn("Expired Shard Iterator, attempting to resume from " + lastSeenSequenceNumber, e);
        GetRecordsRequest req = new GetRecordsRequest().withShardIterator(shardIteratorHandler.getShardIterator(lastSeenSequenceNumber)).withLimit(getEndpoint().getMaxResultsPerRequest());
        result = getClient().getRecords(req);
    }
    List<Record> records = result.getRecords();
    Queue<Exchange> exchanges = createExchanges(records, lastSeenSequenceNumber);
    int processedExchangeCount = processBatch(CastUtils.cast(exchanges));
    shardIteratorHandler.updateShardIterator(result.getNextShardIterator());
    if (!records.isEmpty()) {
        lastSeenSequenceNumber = records.get(records.size() - 1).getDynamodb().getSequenceNumber();
    }
    return processedExchangeCount;
}
Also used : Exchange(org.apache.camel.Exchange) GetRecordsResult(com.amazonaws.services.dynamodbv2.model.GetRecordsResult) Record(com.amazonaws.services.dynamodbv2.model.Record) ExpiredIteratorException(com.amazonaws.services.dynamodbv2.model.ExpiredIteratorException) GetRecordsRequest(com.amazonaws.services.dynamodbv2.model.GetRecordsRequest)

Aggregations

ExpiredIteratorException (com.amazonaws.services.dynamodbv2.model.ExpiredIteratorException)1 GetRecordsRequest (com.amazonaws.services.dynamodbv2.model.GetRecordsRequest)1 GetRecordsResult (com.amazonaws.services.dynamodbv2.model.GetRecordsResult)1 Record (com.amazonaws.services.dynamodbv2.model.Record)1 Exchange (org.apache.camel.Exchange)1