首页 > 解决方案 > Mongodb 到 Kafka 连接器

问题描述

你能帮忙配置connect-mongo-source.properties吗?

下面是connect-mongo-source.properties

    name=mongodb-source-connector
    connector.class=io.debezium.connector.mongodb.MongoDbConnector
    mongodb.hosts=mongodb://admin:password@ipaddress:27017/test
    mongodb.name=mongo_conn
    initial.sync.max.threads=1
    tasks.max=1

我收到此错误

 [2020-04-22 16:26:58,723] ERROR Error while reading the 'shards' collection in the 'config' database: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, 
servers=

[{address=test?authsource=admin&replicaset=quickfoodcluster-shard-0&readpreference=primary&appname=mongodb%20compass%20community&ssl=true:27017, type=UNKNOWN, state=CONNECTING, 
exception={com.mongodb.MongoSocketException: test?authsource=admin&replicaset=quickfoodcluster-shard-0&readpreference=primary&appname=mongodb%20compass%20community&ssl=true}, 
caused by {java.net.UnknownHostException: test?authsource=admin&replicaset=quickfoodcluster-shard-0&readpreference=primary&appname=mongodb%20compass%20community&ssl=true}}, 

{address=quickfoodcluster-shard-00-01-zxbxk.azure.mongodb.net:27017, 
type=UNKNOWN, 
state=CONNECTING, 
exception={com.mongodb.MongoSocketException: quickfoodcluster-shard-00-01-zxbxk.azure.mongodb.net}, 
caused by {java.net.UnknownHostException: quickfoodcluster-shard-00-01-zxbxk.azure.mongodb.net}}] (io.debezium.connector.mongodb.ReplicaSetDiscovery)
    com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, 
servers=[{address=test?authsource=admin&replicaset=quickfoodcluster-shard-0&readpreference=primary&appname=mongodb%20compass%20community&ssl=true:27017, 
type=UNKNOWN, 
state=CONNECTING, 
exception={com.mongodb.MongoSocketException: test?authsource=admin&replicaset=quickfoodcluster-shard-0&readpreference=primary&appname=mongodb%20compass%20community&ssl=true}, 
caused by {java.net.UnknownHostException: test?authsource=admin&replicaset=quickfoodcluster-shard-0&readpreference=primary&appname=mongodb%20compass%20community&ssl=true}}, 
{address=quickfoodcluster-shard-00-01-zxbxk.azure.mongodb.net:27017, 
type=UNKNOWN, state=CON


NECTING, exception={com.mongodb.MongoSocketException: quickfoodcluster-shard-00-01-zxbxk.azure.mongodb.net}, caused by {java.net.UnknownHostException: quickfoodcluster-shard-00-01-zxbxk.azure.mongodb.net}}]   

标签: mongodb

解决方案


我认为您不能在 中使用 DSN 字符串mongodb.hosts,应该在此处host:port文档中提到的单独字段中提供用户和密码。

name=mongodb-source-connector
connector.class=io.debezium.connector.mongodb.MongoDbConnector
mongodb.hosts=ipaddress:27017
mongodb.user=admin
mongodb.password=password
mongodb.name=mongo_conn
initial.sync.max.threads=1
tasks.max=1

推荐阅读