List of usage examples for com.amazonaws.services.kinesis.model GetRecordsResult toString
@Override
public String toString()
From source file:dbtucker.connect.kinesis.KinesisSourceTask.java
License:Apache License
@Override public List<SourceRecord> poll() throws InterruptedException { if (assignedShards.isEmpty()) { throw new ConnectException("No source shards remaining for this task"); }/*from w w w . java 2s. c om*/ // Kinesis best practice is to sleep 1 second between calls to getRecords // We'll do that only after we've cycled through all the shards we're polling if (currentShardIdx == 0) { try { Thread.sleep(1000); } catch (InterruptedException exception) { throw exception; } } final String shardUid = assignedShards.get(currentShardIdx); final GetRecordsRequest req = new GetRecordsRequest(); req.setShardIterator(toShardIterator(shardUid)); req.setLimit(config.getRecPerReq()); final GetRecordsResult rsp = client.getRecords(req); log.info("client.getRecords retrieve {} records", rsp.getRecords().size()); log.debug("client.getRecords returns {}", rsp.toString()); if (rsp.getNextShardIterator() == null) { log.info("Shard ID `{}` for stream `{}` has been closed, it will no longer be polled", shardUid.split("/")[1], shardUid.split("/")[0]); shardIterators.remove(shardUid); assignedShards.remove(shardUid); } else { shardIterators.put(shardUid, rsp.getNextShardIterator()); } currentShardIdx = (currentShardIdx + 1) % assignedShards.size(); final String streamName = shardUid.split("/")[0]; final String topic = config.getTopicFormat().replace("${stream}", streamName); final Map<String, String> sourcePartition = toSourcePartition(shardUid); return rsp.getRecords().stream().map(kinesisRecord -> toSourceRecord(sourcePartition, topic, kinesisRecord)) .collect(Collectors.toList()); }