仅当记录数超过x时才启动Kinesis使用者吗?

时间:2018-12-01 21:29:46

标签: amazon-kinesis

有没有办法创建具有缓冲区限制的Kinesis使用者?像here

#Flush when buffer exceeds 100000 Amazon Kinesis records, 64 MB size limit or when time since last buffer exceeds 1 hour
bufferByteSizeLimit = 67108864 
bufferRecordCountLimit = 100000
bufferMillisecondsLimit = 3600000

基本上,我只想在有大量数据时才开始IRecordProcessor。我无法使用上面的连接器代码,因为我需要amazon-kinesis-client的{​​{3}}版。

1 个答案:

答案 0 :(得分:0)

我最终实现了自己的解决方案。

  1. 具有ConcurrentHashMap来存储流数据
      private val recsMap = new ConcurrentHashMap[String, List[RecordStore]]
      private val currByteSize = new AtomicLong(0L)
      private val currRecordCount = new AtomicLong(0L)
      private val currSeconds = new AtomicLong(0L)
    
  2. 更新计数器(按大小/时间/记录数)
  3. 到达计数器时刷新数据
      recsMap.foreach(write2File())
      // clean up
      recsMap.remove(writtenRecs())
    
  4. 检查点和重置计数器
      // reset counters
      currByteSize.getAndSet(value)
      currRecordCount.getAndSet(value)
      currSeconds.getAndSet(value)