apache-kafkajdbcapache-kafka-connect

Connection refused when creating JdbcSourceConnector to MySQL


I am using Confluent Platform (hosted in docker locally) and I am trying to add JdbcSourceConnector to fetch data from MySQL database.

But no matter what I do, I get exception:

java.net.ConnectException: Connection refused (Connection refused)

Here is configuration of the connector:

{
"name":"mysql-login-connector",
"config":
{
    "connector.class":"io.confluent.connect.jdbc.JdbcSourceConnector",
    "connection.url":"jdbc:mysql://localhost:3306/test",
    "connection.user": "root",
    "connection.password": "Admin",
    "topic.prefix": "mysql-01-",
    "mode":"bulk"
}

}

Here is docker-compose:

  connect:
image: cnfldemos/cp-server-connect-datagen:0.6.4-7.6.0
hostname: connect
container_name: connect
depends_on:
  - broker
  - schema-registry
ports:
  - "8083:8083"
environment:
  CONNECT_BOOTSTRAP_SERVERS: 'broker:29092'
  CONNECT_REST_ADVERTISED_HOST_NAME: connect
  CONNECT_GROUP_ID: compose-connect-group
  CONNECT_CONFIG_STORAGE_TOPIC: docker-connect-configs
  CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
  CONNECT_OFFSET_FLUSH_INTERVAL_MS: 10000
  CONNECT_OFFSET_STORAGE_TOPIC: docker-connect-offsets
  CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
  CONNECT_STATUS_STORAGE_TOPIC: docker-connect-status
  CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
  CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter
  CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
  CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081
  # CLASSPATH required due to CC-2422
  CLASSPATH: /usr/share/java/monitoring-interceptors/monitoring-interceptors-7.9.0.jar:/config/confluentinc-kafka-connect-jdbc-10.8.4/lib/mysql-connector-java-8.0.30.jar
  CONNECT_PRODUCER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor"
  CONNECT_CONSUMER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor"
  CONNECT_PLUGIN_PATH: "/usr/share/java,/usr/share/confluent-hub-components,/usr/local/share/kafka/plugins,/usr/share/filestream-connectors,/config"
volumes:
  - C:\Programs\cp-all-in-one\config:/config

What am I doing wrong?


Solution

  • Problem was that my Confluent Platform was hosted in Docker and MySQL server was installed locally.

    Once I changed localhost:3306 to host.docker.internal , connector started to work:

    {
        "name":"mysql-login-connector",
        "config":
        {
            "connector.class":"io.confluent.connect.jdbc.JdbcSourceConnector",
            "connection.url":"jdbc:mysql://host.docker.internal/test",
            "connection.user": "root",
            "connection.password": "Admin",
            "topic.prefix": "mysql-01-",
            "mode":"bulk",
            "table.whitelist": "users"
        }
    }