简体   繁体   English

Apache Kafka 和 MongoDB-4.0 的官方 MongoDB 源连接器

[英]Official MongoDB Source Connector for Apache Kafka with MongoDB-4.0

I have a requirement where I have to capture MongoDB ChangeStream (inserts/updates etc) events and take some actions (save to OracleDB).我有一个要求,我必须捕获 MongoDB ChangeStream(插入/更新等)事件并采取一些措施(保存到 OracleDB)。 I have thought of this design which seems to be good:我想到了这个似乎很好的设计:

"MongoDB-ChangeStream" --> "MongoDB Source Connector for Apache Kafka" --> "Kafka Broker-Topic" --> "Java Service" --> OracleDB

My question here is, I am using MongoDB-4.0 and "MongoDB Source Connector for Apache Kafka" was introduced in MongoDB-4.2.我的问题是,我使用的是 MongoDB-4.0,并且在 MongoDB-4.2 中引入了“用于 Apache Kafka 的 MongoDB 源连接器”。 Can I still use "MongoDB Source Connector for Apache Kafka" with MongoDB-4.0?我还能在 MongoDB-4.0 中使用“用于 Apache Kafka 的 MongoDB 源连接器”吗?

MongoDB Source Connector for Apache Kafka - Official page: https://www.confluent.io/hub/mongodb/kafka-connect-mongodb MongoDB Source Connector for Apache Kafka - 官方页面: https://www.confluent.io/hub/mongodb/kafka-connect-mongodb

Official page of "MongoDB Source Connector for Apache Kafka" does not talk about any prerequisite in terms of the version of MongoDB. “MongoDB Source Connector for Apache Kafka”官方页面没有谈到MongoDB版本的任何先决条件。

My second question, can this(MongoDB Source Connector for Apache Kafka) set up be done on Windows?我的第二个问题,这个(Apache Kafka 的 MongoDB 源连接器)可以在 Windows 上设置吗?

Appreciate any help.感谢任何帮助。

The answer is already in the documentation :答案已经在文档中:

The Kafka Source Connector requires MongoDB 3.6 or later as your data source if you are using change streams with a collection only.如果您仅将更改流与集合一起使用,则 Kafka 源连接器需要 MongoDB 3.6 或更高版本作为您的数据源。 If you need to watch a database or deployment, you need MongoDB 4.0 or later.如果需要监视数据库或部署,则需要 MongoDB 4.0 或更高版本。


Regarding your second question;关于你的第二个问题; Yes, it is possible to run Kafka on Windows.是的,可以在 Windows 上运行 Kafka。

A working solution for MongoDB(4.0) ChangeStreams with Official MongoDB Connector (mongodb-kafka-connect-mongodb-1.1.0) for Apache Kafka without using Confluent Hub Client MongoDB(4.0) ChangeStreams 的工作解决方案,带有官方 MongoDB 连接器 (mongodb-kafka-connect-mongodb-1.1.0),适用于 Apache Kafka,无需使用 Confluent Hub 客户端

  1. Download Official MongoDB Kafka Connector: i. open https://www.confluent.io/hub/ ii. search "mongodb" iii. select from dropdown "MongoDB Connector for Apache Kafka" iv. Click on Download in Download installtion (note I am not using Confluent) v. unzip the downloaded file (on windows) eg. F:\software\mongodb\mongodb-kafka-connect-mongodb-1.1.0 vi. inside "etc" folder open file "MongoSourceConnector.properties" vii. Make only one change with respect to MongoDB url: connection.uri=mongodb://localhost:27017,localhost:27018 viii. One change in Kafka: In F:\software\kafka_2.12-2.4.1\config\connect-standalone.properties: plugin.path=F:\\software\\mongodb\\mongodb-kafka-connect-mongodb-1.1.0下载官方 MongoDB Kafka 连接器: i. open https://www.confluent.io/hub/ ii. search "mongodb" iii. select from dropdown "MongoDB Connector for Apache Kafka" iv. Click on Download in Download installtion (note I am not using Confluent) v. unzip the downloaded file (on windows) eg. F:\software\mongodb\mongodb-kafka-connect-mongodb-1.1.0 vi. inside "etc" folder open file "MongoSourceConnector.properties" vii. Make only one change with respect to MongoDB url: connection.uri=mongodb://localhost:27017,localhost:27018 viii. One change in Kafka: In F:\software\kafka_2.12-2.4.1\config\connect-standalone.properties: plugin.path=F:\\software\\mongodb\\mongodb-kafka-connect-mongodb-1.1.0 i. open https://www.confluent.io/hub/ ii. search "mongodb" iii. select from dropdown "MongoDB Connector for Apache Kafka" iv. Click on Download in Download installtion (note I am not using Confluent) v. unzip the downloaded file (on windows) eg. F:\software\mongodb\mongodb-kafka-connect-mongodb-1.1.0 vi. inside "etc" folder open file "MongoSourceConnector.properties" vii. Make only one change with respect to MongoDB url: connection.uri=mongodb://localhost:27017,localhost:27018 viii. One change in Kafka: In F:\software\kafka_2.12-2.4.1\config\connect-standalone.properties: plugin.path=F:\\software\\mongodb\\mongodb-kafka-connect-mongodb-1.1.0
  2. start Zookeeper: bin/zookeeper-server-start.sh config/zookeeper.properties启动 Zookeeper: bin/zookeeper-server-start.sh config/zookeeper.properties
  3. start Kafka: .\bin\windows\kafka-server-start.bat.\config\server.properties启动 Kafka: .\bin\windows\kafka-server-start.bat.\config\server.properties

  4. start Kafka-Connect: bin\windows\connect-standalone.bat config\connect-standalone.properties F:\software\mongodb\mongodb-kafka-connect-mongodb-1.1.0\etc\MongoSourceConnector.properties启动 Kafka-Connect: bin\windows\connect-standalone.bat config\connect-standalone.properties F:\software\mongodb\mongodb-kafka-connect-mongodb-1.1.0\etc\MongoSourceConnector.properties

  5. Add new Document to MongoDB Collection and you should have a new topic created dbName.collectionName and ChangeStream event should appear on this topic.将新文档添加到 MongoDB 集合中,您应该创建一个新主题 dbName.collectionName 并且 ChangeStream 事件应该出现在该主题上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM