Search in sources :

Example 41 with OffsetAndMetadata

use of org.apache.kafka.clients.consumer.OffsetAndMetadata in project apex-malhar by apache.

the class KafkaConsumerWrapper method commitOffsets.

/**
 * Only put the offset needs to be committed in the ConsumerThread.offsetToCommit map
 * The consumer thread will commit the offset(s)
 *
 * @param offsetsInWindow
 */
public void commitOffsets(Map<AbstractKafkaPartitioner.PartitionMeta, Long> offsetsInWindow) {
    if (offsetsInWindow == null) {
        return;
    }
    // group offsets by cluster and topic partition
    for (Map.Entry<AbstractKafkaPartitioner.PartitionMeta, Long> e : offsetsInWindow.entrySet()) {
        String cluster = e.getKey().getCluster();
        Map<TopicPartition, OffsetAndMetadata> topicPartitionOffsetMap = offsetsToCommit.get(cluster);
        if (topicPartitionOffsetMap == null) {
            logger.warn("committed offset map should be initialized by consumer thread!");
            continue;
        }
        topicPartitionOffsetMap.put(e.getKey().getTopicPartition(), new OffsetAndMetadata(e.getValue()));
    }
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)41 TopicPartition (org.apache.kafka.common.TopicPartition)29 HashMap (java.util.HashMap)22 Test (org.junit.Test)22 Map (java.util.Map)12 OffsetCommitCallback (org.apache.kafka.clients.consumer.OffsetCommitCallback)7 SinkRecord (org.apache.kafka.connect.sink.SinkRecord)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ArrayList (java.util.ArrayList)4 PartitionInfo (org.apache.kafka.common.PartitionInfo)4 WakeupException (org.apache.kafka.common.errors.WakeupException)4 Properties (java.util.Properties)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 KafkaTopicPartition (org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition)3 CommitFailedException (org.apache.kafka.clients.consumer.CommitFailedException)3 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)3 ConsumerRecords (org.apache.kafka.clients.consumer.ConsumerRecords)3 StreamsConfig (org.apache.kafka.streams.StreamsConfig)3 File (java.io.File)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2