Create kafka connector with the name which is not already in use

Viewed 956

When I am trying to create a kafka connector with the name which is already in use through rest call, I got a error saying,

{"error_code":409,"message":"Connector Test already exists"}

I want to bypass this error , for example while creating kafka Topic we have something like below,

./kafka-topics **--if-not-exists**  --create --zookeeper localhost:2181 --replication-factor  1 --partitions 1  --topic test

Do we have something like --if-not-exists while creating kafka connectors?

2 Answers

The way I like to do it us to use the PUT method to the config endpoint, like this:

curl -i -X PUT -H "Accept:application/json" -H  "Content-Type:application/json" \
http://localhost:8083/connectors/my-connector-name/config -d "@my-connector-config.json"

The behavior is to create in case it doesn't exist and update otherwise, more in the documentation here: https://docs.confluent.io/current/connect/references/restapi.html#put--connectors-(string-name)-config

Note that your json payload doesn't need to contain name and config, but only the config contents as in the docs example.

There is no direct way but you can always use the custom scripts to accomodate validation. You can use the REST API to query the active connectors like below.

 curl localhost:8083/connectors  // will return the active connectors on worker
 ["local-file-sink1", "db-sink1"]

Once you get the name of active connector, you can validate against your connector properties to see if the name is already is use or not.

Related