如何在Kafka Connect中动态更新SinkConnector的主题?

时间:2016-08-24 06:14:24

标签: apache-kafka apache-kafka-connect

我已经为消费者主题编写了Kafka Connect,但我的主题将在运行时更改,因此我需要重新配置主题。

我知道使用RESTful API可以更新主题还有另一种方法可以实现吗?

2 个答案:

答案 0 :(得分:2)

Kafka Connect旨在作为服务运行,它还支持用于管理连接器的REST API。 只能在运行时通过REST API更新它:

PUT / connectors / {name} / config - 在运行时更新连接器的配置参数。

Request Json Object - config(map)

{
    "connector.class": "io.confluent.connect.hdfs.HdfsSinkConnector",
    "tasks.max": "20",
    "topics": "kafkaConnectTopic",
    "hdfs.url": "hdfs://smoketest:9000",
    "hadoop.conf.dir": "/etc/hadoop/conf",
    "hadoop.home": "/etc/hadoop",
    "flush.size": "1000",
    "rotate.interval.ms": "100"
}

Response :

{
    "name": "hdfs-sink-connector",
    "config": {
        "connector.class": "io.confluent.connect.hdfs.HdfsSinkConnector",
        "tasks.max": "20",
        "topics": "kafkaConnectTopic",
        "hdfs.url": "hdfs://smoketest:9000",
        "hadoop.conf.dir": "/etc/hadoop/conf",
        "hadoop.home": "/etc/hadoop",
        "flush.size": "1000",
        "rotate.interval.ms": "100"
    },
    "tasks": [
        { "connector": "hdfs-sink-connector", "task": 1 },
        { "connector": "hdfs-sink-connector", "task": 2 },
        { "connector": "hdfs-sink-connector", "task": 3 }
   ]
}

如需进一步阅读,您可以浏览http://docs.confluent.io/3.0.0/connect/userguide.html#connect-administration

答案 1 :(得分:0)

如果您事先知道要切换到的主题集,则可以在连接器配置中指定要使用的主题列表。否则,the REST API是动态更新配置的唯一方法。