簡體   English   中英

有沒有辦法將 MongoSourceConnector 用於具有單個 kafka 主題的多個數據庫?

[英]Is there any way to use MongoSourceConnector for multiple database with single kafka topic?

我正在使用 MongoSourceConnector 將 kafka 主題與 mongo 數據庫集合連接起來。 對於具有單個 kafka 主題的單個數據庫,它工作正常,但是有什么方法可以為具有單個 kafka 主題的多個 mongo 數據庫建立連接。

如果您在分布式模式下運行 kafka-connect,那么您可以使用上述配置創建另一個連接器配置文件

我不太確定多個數據庫和單個 Kafka 主題,但您肯定可以聽到多個數據庫更改流並將數據推送到主題。 由於主題創建取決於database_name.collection_name ,因此您將擁有更多主題。

您可以提供正則表達式來偵聽pipeline中的多個數據庫。

"pipeline": "[{\"$match\":{\"$and\":[{\"ns.db\":{\"$regex\":/^database-names_.*/}},{\"ns.coll\":{\"$regex\":/^collection_name$/}}]}}]"

這是完整的 Kafka 連接器配置。

Mongo 到 Kafka 源連接器

{
  "name": "mongo-to-kafka-connect",
  "config": {
    "connector.class": "com.mongodb.kafka.connect.MongoSourceConnector",
    "publish.full.document.only": "true",
    "tasks.max": "3",
    "key.converter.schemas.enable": "false",
    "topic.creation.enable": "true",
    "poll.await.time.ms": 1000,
    "poll.max.batch.size": 100,
    "topic.prefix": "any prefix for topic name",
    "output.json.formatter": "com.mongodb.kafka.connect.source.json.formatter.SimplifiedJson",
    "connection.uri": "mongodb://<username>:<password>@ip:27017,ip:27017,ip:27017,ip:27017/?authSource=admin&replicaSet=xyz&tls=true",
    "value.converter.schemas.enable": "false",
    "copy.existing": "true",
    "topic.creation.default.replication.factor": 3,
    "topic.creation.default.partitions": 3,
    "topic.creation.compacted.cleanup.policy": "compact",
    "value.converter": "org.apache.kafka.connect.storage.StringConverter",
    "key.converter": "org.apache.kafka.connect.storage.StringConverter",
    "mongo.errors.log.enable": "true",
    "heartbeat.interval.ms": 10000,
    "pipeline": "[{\"$match\":{\"$and\":[{\"ns.db\":{\"$regex\":/^database-names_.*/}},{\"ns.coll\":{\"$regex\":/^collection_name$/}}]}}]"
  }
}

您可以從官方文檔中獲得更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM