自定义Kafka连接器:连接器错误,但任务仍在运行

时间:2020-04-16 23:33:30

标签: apache-kafka task apache-kafka-connect connector

我正在构建自定义Kafka Source连接器。此连接器已启动并正在运行。我使用剩余的API更新连接器配置设置(例如,源端点和连接密钥)。我使用下面的Rest API

PUT /connectors/{name}/config

由于某些问题,例如(错误的密钥)API不成功且连接器失败

API输出如下。请注意,连接器处于失败状态,但是任务仍在运行。实际上,它们仍然“连接”到旧的端点和连接密钥,而不是优雅地终止任务。

{
    "name": "CustomSrcConnector_V1",
    "connector": {
        "state": "FAILED",
        "worker_id": "XXX.XX.XX.XX:8083",
        "trace": "org.apache.kafka.connect.errors.ConnectException: Exception happened at Create : Exception in getPartitions()\n\tat com.xxx.yyy.kafka.connect.eventhub.CustomSourceConnector.start(CustomSourceConnector.java:102)\n\tat org.apache.kafka.connect.runtime.WorkerConnector.doStart(WorkerConnector.java:111)\n\tat org.apache.kafka.connect.runtime.WorkerConnector.start(WorkerConnector.java:136)\n\tat org.apache.kafka.connect.runtime.WorkerConnector.transitionTo(WorkerConnector.java:196)\n\tat org.apache.kafka.connect.runtime.Worker.startConnector(Worker.java:242)\n\tat org.apache.kafka.connect.runtime.distributed.DistributedHerder.startConnector(DistributedHerder.java:908)\n\tat org.apache.kafka.connect.runtime.distributed.DistributedHerder.processConnectorConfigUpdates(DistributedHerder.java:345)\n\tat org.apache.kafka.connect.runtime.distributed.DistributedHerder.tick(DistributedHerder.java:317)\n\tat org.apache.kafka.connect.runtime.distributed.DistributedHerder.run(DistributedHerder.java:219)\n\tat java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\n\tat java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:834)\n"
    },
    "tasks": [
        {
            "id": 0,
            "state": "RUNNING",
            "worker_id": "XXX.XX.XX.XX:8083"
        },
        {
            "id": 1,
            "state": "RUNNING",
            "worker_id": "XXX.XX.XX.XX:8083"
        }
    ],
    "type": "source"
}

我知道任务和连接器通常是分离的。但是,我想知道如果连接器在Conenctor配置更新期间出现错误,是否可以正常关闭任务。

1 个答案:

答案 0 :(得分:0)

到目前为止,当连接器发生故障时,无法强制执行失败任务。

到目前为止,我找到的解决方案是捕获源连接器中的任何异常,然后允许在taskConfigs方法运行并重新初始化任务,而不是在源连接器中引发异常。我们将需要允许任务失败,因此,我们可以使连接器处于RUNNING状态,但任务为FAILED。 这将与上述Iskuskov Alexander共享的示例一致

https://issues.apache.org/jira/browse/KAFKA-9639