[英]Can I have Kafka consumers/sink connects to skip specific partitions within a topic?
Any option in Kafka Connect to specify from which partition specifically to read the messages. Kafka Connect中的任何选项可指定专门从哪个分区读取消息。 Basically, I am looking for an option in Kafka Connects to manually assign a list of partitions to read. 基本上,我正在Kafka Connects中寻找一个选项来手动分配要读取的分区列表。
Similar to assign() method in KafkaConsumer API 类似于KafkaConsumer API中的Assign()方法
https://kafka.apache.org/0100/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#assign(java.util.Collection) https://kafka.apache.org/0100/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#assign(java.util.Collection)
You can't listen to only specific partition in Kafka Connect. 您不能只收听Kafka Connect中的特定分区。
But you can achieve functionality of inserting messages from only specific partitions. 但是您可以实现仅从特定分区插入消息的功能。
To have such feature you need to implement your custom Transformation
. 要拥有这样的功能,您需要实现自定义的Transformation
。 If Transformation
returns null
message is skipped, so your custom Transformation
must return null
for unwanted partitions. 如果“ Transformation
返回null
消息被跳过,那么您的自定义Transformation
必须为不需要的分区返回“ null
”。
Sample code will be as follow: 示例代码如下:
public class PartitionFilter <R extends ConnectRecord<R>> implements Transformation<R> {
public static final ConfigDef CONFIG_DEF = new ConfigDef();
@Override
public void configure(Map<String, ?> props) {
final SimpleConfig config = new SimpleConfig(CONFIG_DEF, props);
}
@Override
public R apply(R record) {
int neededPartition = 1; // some parititon
if (record.kafkaPartition() != neededPartition)
return null;
return record;
}
@Override
public void close() {
}
@Override
public ConfigDef config() {
return CONFIG_DEF;
}
}
More information about transformations can be found: https://kafka.apache.org/documentation/#connect_transforms 可以找到有关转换的更多信息: https : //kafka.apache.org/documentation/#connect_transforms
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.