0

I am having two containers running on host machine, the two containers are communicating over the network e.g --network=kafka-sink-connect and the containers communication happening as expected but when I am trying to create connector instance with below config

{
    "name": "jdbc-sink-connector",
    "config": {
        
        "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
        "tasks.max": "1",
        "topics": "test.table",
        "key.converter": "org.apache.kafka.connect.storage.StringConverter",
        "value.converter": "org.apache.kafka.connect.json.JsonConverter",
        "value.converter.schema.registry.url": "http://schema-registry:8081",
        "schemas.enable": "false",
        "connection.url": "jdbc:postgresql://localhost:5432/postgres",
        "connection.username": "postgres",
        "connection.password": "*******",
        "insert.mode": "upsert",

        "batch.size": "1",
        "auto.create": true,
        "auto.evolve":true,   
        "table.name.format": "test.table",
        "errors.tolerance": "all",
        "errors.retry.delay.max.ms": 60000,
        "errors.retry.timeout": 300000,
        "errors.log.enable": true,
        "errors.log.include.messages": true
    }
}

I am getting the connection refused exception org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

I tried to change connection host and used host.docker.internal like "connection.url": "jdbc:postgresql://host.docker.internal:5432/postgres" in this case I am getting the error org.postgresql.util.PSQLException: FATAL: role "root" does not exist

ABC
  • 4,263
  • 10
  • 45
  • 72

1 Answers1

0

Try replacing localhost with your computer's IP adress. i.e

{
    "name": "jdbc-sink-connector",
    "config": {
        
        "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
        "tasks.max": "1",
        "topics": "test.table",
        "key.converter": "org.apache.kafka.connect.storage.StringConverter",
        "value.converter": "org.apache.kafka.connect.json.JsonConverter",
        "value.converter.schema.registry.url": "http://schema-registry:8081",
        "schemas.enable": "false",
        "connection.url": "jdbc:postgresql://<IP-ADRESS>:5432/postgres",
        "connection.username": "postgres",
        "connection.password": "*******",
        "insert.mode": "upsert",

        "batch.size": "1",
        "auto.create": true,
        "auto.evolve":true,   
        "table.name.format": "test.table",
        "errors.tolerance": "all",
        "errors.retry.delay.max.ms": 60000,
        "errors.retry.timeout": 300000,
        "errors.log.enable": true,
        "errors.log.include.messages": true
    }
}
lyle okoth
  • 31
  • 1
  • Tried with host(my computer) ip address still getting the same excpetion -Caused by: org.postgresql.util.PSQLException: Connection to 192.168.1.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections – ABC Jul 10 '22 at 07:40
  • It is [apparently](https://docs.confluent.io/platform/current/connect/security.html) spelled connection.user, not connection.username. – jjanes Jul 10 '22 at 14:06