gobblin.kafka.client.GobblinKafkaConsumerClient Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package gobblin.kafka.client;
import java.io.Closeable;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import com.typesafe.config.Config;
import gobblin.source.extractor.extract.kafka.KafkaOffsetRetrievalFailureException;
import gobblin.source.extractor.extract.kafka.KafkaPartition;
import gobblin.source.extractor.extract.kafka.KafkaTopic;
import gobblin.util.DatasetFilterUtils;
/**
* A simplified, generic wrapper client to communicate with Kafka. This class is (AND MUST never) depend on classes
* defined in kafka-clients library. The request and response objects are defined in gobblin. This allows gobblin
* sources and extractors to work with different versions of kafka. Concrete classes implementing this interface use a
* specific version of kafka-client library.
*
*
* This simplified client interface supports consumer operations required by gobblin to pull from kafka. Most of the APIs
* are migrated from the legacy gobblin.source.extractor.extract.kafka.KafkaWrapper$KafkaAPI
*
*/
public interface GobblinKafkaConsumerClient extends Closeable {
/**
* Get a list of {@link KafkaTopic}s satisfy blacklist
and whitelist
patterns
* @param blacklist - List of regex patterns that need to be blacklisted
* @param whitelist - List of regex patterns that need to be whitelisted
*
* @see DatasetFilterUtils#survived(String, List, List)
*
*/
public List getFilteredTopics(List blacklist, List whitelist);
/**
* Get the earliest available offset for a partition
*
* @param partition for which earliest offset is retrieved
*
* @throws UnsupportedOperationException - If the underlying kafka-client does not support getting earliest offset
*/
public long getEarliestOffset(KafkaPartition partition) throws KafkaOffsetRetrievalFailureException;
/**
* Get the latest available offset for a partition
*
* @param partition for which latest offset is retrieved
*
* @throws UnsupportedOperationException - If the underlying kafka-client does not support getting latest offset
*/
public long getLatestOffset(KafkaPartition partition) throws KafkaOffsetRetrievalFailureException;
/**
* API to consume records from kakfa starting from nextOffset
till maxOffset
.
* If maxOffset
is greater than nextOffset
, returns a null.
* nextOffset
*
* NOTE: If the underlying kafka-client version does not support
* reading message till an end offset, all available messages are read, maxOffset
is ignored.
*
*
* @param partition whose messages are read
* @param nextOffset to being reading
* @param maxOffset to stop reading (Iff underlying client supports)
*
* @return An {@link Iterator} of {@link KafkaConsumerRecord}s
*/
public Iterator consume(KafkaPartition partition, long nextOffset, long maxOffset);
/**
* A factory to create {@link GobblinKafkaConsumerClient}s
*/
public interface GobblinKafkaConsumerClientFactory {
/**
* Creates a new {@link GobblinKafkaConsumerClient} for config
*
*/
public GobblinKafkaConsumerClient create(Config config);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy