solujic
solujic

Reputation: 1004

Kafka connector "Unable to connect to the server" - dockerized kafka-connect worker that connects to confluent cloud

I'm following similar example as in this blog post:

https://rmoff.net/2019/11/12/running-dockerised-kafka-connect-worker-on-gcp/

Except that I'm not running kafka connect worker on GCP but locally.

Everything is fine I run the docker-compose up and kafka connect starts but when I try to create instance of source connector via CURL I get the following ambiguous message (Note: there is literally no log being outputed in the kafka connect logs):

{"error_code":400,"message":"Connector configuration is invalid and contains the following 1 error(s):\nUnable to connect to the server.\nYou can also find the above list of errors at the endpoint `/{connectorType}/config/validate`"}

I know I can connect to confluent cloud because I see that there are topics being created:

docker-connect-configs  
docker-connect-offsets  
docker-connect-status  

My docker-compose.yml looks like this:

---
  version: '2'
  services:
      
        kafka-connect-01:
          image: confluentinc/cp-kafka-connect:5.4.0
          container_name: kafka-connect-01
          restart: always
          depends_on:
            # - zookeeper
            # - kafka
            - schema-registry
          ports:
            - 8083:8083
          environment:
            CONNECT_LOG4J_APPENDER_STDOUT_LAYOUT_CONVERSIONPATTERN: "[%d] %p %X{connector.context}%m (%c:%L)%n"
            CONNECT_BOOTSTRAP_SERVERS: "my-server-name.confluent.cloud:9092"
            CONNECT_REST_PORT: 8083
            CONNECT_REST_ADVERTISED_HOST_NAME: "kafka-connect-01"
            CONNECT_GROUP_ID: compose-connect-group
            CONNECT_CONFIG_STORAGE_TOPIC: docker-connect-configs
            CONNECT_OFFSET_STORAGE_TOPIC: docker-connect-offsets
            CONNECT_STATUS_STORAGE_TOPIC: docker-connect-status
            #CONNECT_KEY_CONVERTER: io.confluent.connect.avro.AvroConverter
            CONNECT_KEY_CONVERTER_SCHEMA_REGISTRY_URL: 'http://my-server-name.confluent.cloud:8081'
            #CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
            CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: 'http://my-server-name.confluent.cloud:8081'
            CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
            CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
            CONNECT_LOG4J_ROOT_LOGLEVEL: "INFO"
            CONNECT_LOG4J_LOGGERS: "org.apache.kafka.connect.runtime.rest=WARN,org.reflections=ERROR"
            CONNECT_REPLICATION_FACTOR: "3"
            CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: "3"
            CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: "3"
            CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: "3"
            CONNECT_PLUGIN_PATH: '/usr/share/java'
            CONNECT_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
            CONNECT_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
            #ENV VARS FOR CCLOUD CONNECTION
            CONNECT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: "https"
            CONNECT_SASL_MECHANISM: PLAIN
            CONNECT_SECURITY_PROTOCOL: SASL_SSL
            CONNECT_SASL_JAAS_CONFIG: "${SASL_JAAS_CONFIG}"
            CONNECT_CONSUMER_SECURITY_PROTOCOL: SASL_SSL
            CONNECT_CONSUMER_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: https
            CONNECT_CONSUMER_SASL_MECHANISM: PLAIN
            CONNECT_CONSUMER_SASL_JAAS_CONFIG: "${SASL_JAAS_CONFIG}"
            CONNECT_PRODUCER_SECURITY_PROTOCOL: SASL_SSL
            CONNECT_PRODUCER_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM: https
            CONNECT_PRODUCER_SASL_MECHANISM: PLAIN
            CONNECT_PRODUCER_SASL_JAAS_CONFIG: "${SASL_JAAS_CONFIG}"
    
          volumes:
            - db-leach:/db-leach/
            - $PWD/connectors:/usr/share/java/kafka-connect-jdbc/jars/
          command: 
            - /bin/bash
            - -c 

I have dockerized mongo instances running and I want to create mongo source connector, this is my CURL request:

    curl -X PUT http://localhost:8083/connectors/my-mongo-source-connector/config -H "Content-Type: application/json" -d '{
    "tasks.max":"1",
    "connector.class":"com.mongodb.kafka.connect.MongoSourceConnector",
    "connection.uri":"mongodb://mongo1:27017,mongo2:27017,mongo3:27017",
    "topic.prefix":"topic.prefix",
    "topic.suffix":"mySuffix",
    "database":"myMongoDB",
    "collection":"myMongoCollection",
    "copy.existing": "true",
    "output.format.key": "json",
    "output.format.value": "json",
    "change.stream.full.document": "updateLookup",
    "publish.full.document.only": "false",
    "confluent.topic.bootstrap.servers" : "'${CCLOUD_BROKER_HOST}':9092", 
    "confluent.topic.sasl.jaas.config" : "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"'${CCLOUD_API_KEY}'\" password=\"'${CCLOUD_API_SECRET}'\";", 
    "confluent.topic.security.protocol": "SASL_SSL", 
    "confluent.topic.ssl.endpoint.identification.algorithm": "https", 
    "confluent.topic.sasl.mechanism": "PLAIN" 
    }';

What am I missing?

Upvotes: 2

Views: 4131

Answers (1)

solujic
solujic

Reputation: 1004

I managed to get it to work, this is a correct configuration...

The message "Unable to connect to the server" was because I had wrongly deployed mongo instance so it's not related to kafka-connect or confluent cloud.

I'm going to leave this question as an example if somebody struggles with this in the future. It took me a while to figure out how to configure docker-compose for kafka-connect that connects to confluent cloud.

Upvotes: 1

Related Questions