如何在 Kafka-Connect API 中设置 max.poll.records

Ren*_*hya 0 apache-kafka apache-kafka-connect

我正在使用 confluent-3.0.1 平台并构建一个 Kafka-Elasticsearch 连接器。为此,我扩展了 SinkConnector 和 SinkTask(Kafka 连接 API)以从 Kafka 获取数据。

作为此代码的一部分,我正在扩展 SinkConnector 的 taskConfigs 方法以返回“max.poll.records”以一次仅获取 100 条记录。但它不起作用,我同时获取所有记录,但我没有在规定的时间内提交偏移量。请任何人帮我配置“max.poll.records”

 public List<Map<String, String>> taskConfigs(int maxTasks) {
    ArrayList<Map<String, String>> configs = new ArrayList<Map<String, String>>();
    for (int i = 0; i < maxTasks; i++) {
      Map<String, String> config = new HashMap<String, String>();
      config.put(ConfigurationConstants.CLUSTER_NAME, clusterName);
      config.put(ConfigurationConstants.HOSTS, hosts);
      config.put(ConfigurationConstants.BULK_SIZE, bulkSize);
      config.put(ConfigurationConstants.IDS, elasticSearchIds);
      config.put(ConfigurationConstants.TOPICS_SATELLITE_DATA, topics);
      config.put(ConfigurationConstants.PUBLISH_TOPIC, topicTopublish);
      config.put(ConfigurationConstants.TYPES, elasticSearchTypes);
      config.put("max.poll.records", "100");

      configs.add(config);
    }
    return configs;
  }
Run Code Online (Sandbox Code Playgroud)

shi*_*har 7

您不能像max.poll.records在连接器配置中那样覆盖大多数 Kafka 消费者配置。不过,您可以在 Connect 工作器配置中使用consumer.前缀进行此操作。