forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue 5474][pulsar-io-debezium] Support CDC Connector for MongoDB (a…
…pache#5590) * support mongodb connector * add tester * add tester * add tester * add license header * fix by some comments * add jdbc source sink * add init data * fix code style and default port 27017 of mongodb
- Loading branch information
1 parent
69cd6eb
commit 8d1f793
Showing
12 changed files
with
385 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.pulsar</groupId> | ||
<artifactId>pulsar-io-debezium</artifactId> | ||
<version>2.5.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pulsar-io-debezium-mongodb</artifactId> | ||
<name>Pulsar IO :: Debezium :: mongodb</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>pulsar-io-debezium-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.debezium</groupId> | ||
<artifactId>debezium-connector-mongodb</artifactId> | ||
<version>${debezium.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.nifi</groupId> | ||
<artifactId>nifi-nar-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
36 changes: 36 additions & 0 deletions
36
...um/mongodb/src/main/java/org/apache/pulsar/io/debezium/mongodb/DebeziumMongoDbSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.io.debezium.mongodb; | ||
|
||
import org.apache.kafka.connect.runtime.TaskConfig; | ||
import org.apache.pulsar.io.debezium.DebeziumSource; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* A pulsar source that runs debezium mongodb source | ||
*/ | ||
public class DebeziumMongoDbSource extends DebeziumSource { | ||
static private final String DEFAULT_TASK = "io.debezium.connector.mongodb.MongoDbConnectorTask"; | ||
|
||
@Override | ||
public void setDbConnectorTask(Map<String, Object> config) throws Exception { | ||
throwExceptionIfConfigNotMatch(config, TaskConfig.TASK_CLASS_CONFIG, DEFAULT_TASK); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
pulsar-io/debezium/mongodb/src/main/resources/META-INF/services/pulsar-io.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
name: debezium-mongodb | ||
description: Debezium MongoDb Source | ||
sourceClass: org.apache.pulsar.io.debezium.mongodb.DebeziumMongoDbSource |
38 changes: 38 additions & 0 deletions
38
pulsar-io/debezium/mongodb/src/main/resources/debezium-mongodb-source-config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
tenant: "public" | ||
namespace: "default" | ||
name: "debezium-mongodb-source" | ||
topicName: "debezium-mongodb-topic" | ||
archive: "connectors/pulsar-io-debezium-mongodb-2.4.0-SNAPSHOT.nar" | ||
|
||
parallelism: 1 | ||
|
||
configs: | ||
## config for pg, docker image: debezium/example-mongodb:0.8 | ||
mongodb.hosts: "rs0/mongodb:27017" | ||
mongodb.name: "dbserver1" | ||
mongodb.user: "debezium" | ||
mongodb.password: "dbz" | ||
mongodb.task.id: "1" | ||
database.whitelist: "inventory" | ||
|
||
## PULSAR_SERVICE_URL_CONFIG | ||
pulsar.service.url: "pulsar://127.0.0.1:6650" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...rc/test/java/org/apache/pulsar/tests/integration/containers/DebeziumMongoDbContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.tests.integration.containers; | ||
|
||
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy; | ||
|
||
public class DebeziumMongoDbContainer extends ChaosContainer<DebeziumMongoDbContainer> { | ||
|
||
public static final String NAME = "debezium-mongodb-example"; | ||
|
||
public static final Integer[] PORTS = { 27017 }; | ||
private static final String IMAGE_NAME = "debezium/example-mongodb:0.10"; | ||
|
||
public DebeziumMongoDbContainer(String clusterName) { | ||
super(clusterName, IMAGE_NAME); | ||
this.withEnv("MONGODB_USER", "mongodb"); | ||
this.withEnv("MONGODB_PASSWORD", "mongodb"); | ||
} | ||
@Override | ||
public String getContainerName() { | ||
return clusterName; | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
super.configure(); | ||
this.withNetworkAliases(NAME) | ||
.withExposedPorts(PORTS) | ||
.withCreateContainerCmdModifier(createContainerCmd -> { | ||
createContainerCmd.withHostName(NAME); | ||
createContainerCmd.withName(getContainerName()); | ||
}) | ||
.waitingFor(new HostPortWaitStrategy()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ion/src/test/java/org/apache/pulsar/tests/integration/io/DebeziumMongoDbSourceTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.tests.integration.io; | ||
|
||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.pulsar.tests.integration.containers.DebeziumMongoDbContainer; | ||
import org.apache.pulsar.tests.integration.containers.PulsarContainer; | ||
import org.apache.pulsar.tests.integration.topologies.PulsarCluster; | ||
|
||
import java.io.Closeable; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
public class DebeziumMongoDbSourceTester extends SourceTester<DebeziumMongoDbContainer> implements Closeable { | ||
|
||
private static final String NAME = "debezium-mongodb"; | ||
|
||
private final String pulsarServiceUrl; | ||
|
||
@Getter | ||
private DebeziumMongoDbContainer debeziumMongoDbContainer; | ||
|
||
private final PulsarCluster pulsarCluster; | ||
public DebeziumMongoDbSourceTester(PulsarCluster cluster) { | ||
super(NAME); | ||
this.pulsarCluster = cluster; | ||
pulsarServiceUrl = "pulsar://pulsar-proxy:" + PulsarContainer.BROKER_PORT; | ||
|
||
sourceConfig.put("mongodb.hosts", "rs0/" + DebeziumMongoDbContainer.NAME + ":27017"); | ||
sourceConfig.put("mongodb.name", "dbserver1"); | ||
sourceConfig.put("mongodb.user", "debezium"); | ||
sourceConfig.put("mongodb.password", "dbz"); | ||
sourceConfig.put("mongodb.task.id","1"); | ||
sourceConfig.put("database.whitelist", "inventory"); | ||
sourceConfig.put("pulsar.service.url", pulsarServiceUrl); | ||
} | ||
|
||
@Override | ||
public void setServiceContainer(DebeziumMongoDbContainer container) { | ||
log.info("start debezium mongodb server container."); | ||
debeziumMongoDbContainer = container; | ||
pulsarCluster.startService(DebeziumMongoDbContainer.NAME, debeziumMongoDbContainer); | ||
} | ||
|
||
@Override | ||
public void prepareSource() throws Exception { | ||
this.debeziumMongoDbContainer.execCmd( "bash", "-c", "/usr/local/bin/init-inventory.sh"); | ||
log.info("debezium mongodb server already contains preconfigured data."); | ||
} | ||
|
||
@Override | ||
public Map<String, String> produceSourceMessages(int numMessages) throws Exception { | ||
log.info("debezium mongodb server already contains preconfigured data."); | ||
return null; | ||
} | ||
|
||
@Override | ||
public String valueContains() { | ||
return "dbserver1.inventory.products.Envelope"; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
if (pulsarCluster != null) { | ||
pulsarCluster.stopService(DebeziumMongoDbContainer.NAME, debeziumMongoDbContainer); | ||
} | ||
} | ||
} |
Oops, something went wrong.