-
Notifications
You must be signed in to change notification settings - Fork 846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DBZ-848 Adding demo for fail-over in MongoDB replica set #47
Open
gunnarmorling
wants to merge
1
commit into
debezium:main
Choose a base branch
from
gunnarmorling:mongodb_replicaset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Using Debezium with Multi-Node MongoDB Replica Set | ||
|
||
This demo shows how the Debezium connector for MongoDB supports failover to secondary nodes elected as new primaries in a MongoDB replica set. | ||
It's based on the services as defined in the [Debezium Tutorial](http://debezium.io/docs/tutorial/). | ||
|
||
Start the topology as defined in http://debezium.io/docs/tutorial/ (using a replica set with three nodes): | ||
|
||
$ export DEBEZIUM_VERSION=0.9 | ||
$ docker-compose up | ||
|
||
Initialize MongoDB replica set and insert some test data: | ||
|
||
$ docker-compose exec mongodb-1 bash -c '/usr/local/bin/init-inventory-replicaset.sh "mongodb-1:27017 mongodb-2:27017 mongodb-3:27017"' | ||
|
||
Start MongoDB connector: | ||
|
||
$ curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" http://localhost:8083/connectors/ -d @register-mongodb-replicaset.json | ||
|
||
Consume messages from the topic created for the "customers" collection: | ||
|
||
$ docker-compose exec kafka /kafka/bin/kafka-console-consumer.sh \ | ||
--bootstrap-server kafka:9092 \ | ||
--from-beginning \ | ||
--property print.key=true \ | ||
--topic dbserver1.inventory.customers | ||
|
||
Shut down the current primary node: | ||
|
||
$ docker-compose stop mongodb-1 | ||
|
||
Find out which MongoDB node is the new primary one: | ||
|
||
$ docker-compose exec mongodb-2 bash -c 'mongo inventory --eval "rs.status()"' | ||
|
||
Modify records in the database via MongoDB client, connecting to new primary | ||
(assuming this is _mongodb-2_ in the following): | ||
|
||
$ docker-compose exec mongodb-2 bash -c 'mongo inventory' | ||
|
||
rs0:PRIMARY> db.customers.insert([ | ||
{ \_id : NumberLong("1005"), first_name : 'Bob', last_name : 'Hopper', email : 'thebob@example.com' } | ||
]); | ||
|
||
The connector should have automatically failed over to the new primary, so the new record should show up in the topic inspected above. | ||
|
||
Step down as primary, which will make the third node the new primary: | ||
|
||
rs0:PRIMARY> rs.stepDown(120); | ||
rs0:PRIMARY> exit; | ||
|
||
Modify records in the database via MongoDB client, connecting to new primary | ||
(assuming this is _mongodb-3_ in the following): | ||
|
||
$ docker-compose exec mongodb-3 bash -c 'mongo inventory' | ||
|
||
rs0:PRIMARY> db.customers.insert([ | ||
{ \_id : NumberLong("1006"), first_name : 'Bob', last_name : 'Hopper', email : 'thebob@example.com' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. Also it might be better to change the other test data not only id |
||
]); | ||
|
||
Again the connector should have automatically failed over to the new primary, so the new record should show up in the topic inspected above. | ||
|
||
Shut down the cluster: | ||
|
||
docker-compose down |
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,43 @@ | ||
version: '2' | ||
services: | ||
zookeeper: | ||
image: debezium/zookeeper:${DEBEZIUM_VERSION} | ||
ports: | ||
- 2181:2181 | ||
- 2888:2888 | ||
- 3888:3888 | ||
kafka: | ||
image: debezium/kafka:${DEBEZIUM_VERSION} | ||
ports: | ||
- 9092:9092 | ||
links: | ||
- zookeeper | ||
environment: | ||
- ZOOKEEPER_CONNECT=zookeeper:2181 | ||
mongodb-1: | ||
image: debezium/example-mongodb:${DEBEZIUM_VERSION} | ||
ports: | ||
- 27017:27017 | ||
mongodb-2: | ||
image: debezium/example-mongodb:${DEBEZIUM_VERSION} | ||
ports: | ||
- 27018:27017 | ||
mongodb-3: | ||
image: debezium/example-mongodb:${DEBEZIUM_VERSION} | ||
ports: | ||
- 27019:27017 | ||
connect: | ||
image: debezium/connect:${DEBEZIUM_VERSION} | ||
ports: | ||
- 8083:8083 | ||
links: | ||
- kafka | ||
- mongodb-1 | ||
- mongodb-2 | ||
- mongodb-3 | ||
environment: | ||
- BOOTSTRAP_SERVERS=kafka:9092 | ||
- GROUP_ID=1 | ||
- CONFIG_STORAGE_TOPIC=my_connect_configs | ||
- OFFSET_STORAGE_TOPIC=my_connect_offsets | ||
- STATUS_STORAGE_TOPIC=my_connect_statuses |
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,11 @@ | ||
{ | ||
"name": "inventory-connector", | ||
"config": { | ||
"connector.class" : "io.debezium.connector.mongodb.MongoDbConnector", | ||
"tasks.max" : "1", | ||
"mongodb.hosts" : "rs0/mongodb-1:27017", | ||
"mongodb.name" : "dbserver1", | ||
"database.whitelist" : "inventory", | ||
"database.history.kafka.bootstrap.servers" : "kafka:9092" | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the backslash should not be present