我有两个容器在主机上运行,两个容器通过网络通信,例如--network=kafka-sink-connect
和容器通信按预期发生,但当我试图创建连接器实例与下面的配置
{
"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
}
}
我收到连接被拒绝的异常org.postgresql.util。PSQLException:连接到本地主机:5432拒绝。检查主机名和端口是否正确,postmaster是否接受TCP/IP连接
我尝试更改连接主机并使用host.docker.internal
"connection.url"jdbc: postgresql://host.docker.internal: 5432/postgres"在这种情况下,我得到了错误org.postgresql.util。PSQLException: FATAL: role "root"不存在
尝试用您的计算机IP地址替换localhost。即
{
"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
}
}