This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
forked from vdesabou/kafka-docker-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo.sh
executable file
·60 lines (48 loc) · 1.6 KB
/
mongo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
source ${DIR}/../../scripts/utils.sh
${DIR}/../../environment/plaintext/start.sh "${PWD}/docker-compose.plaintext.yml"
log "Initialize MongoDB replica set"
docker exec -it mongodb mongo --eval 'rs.initiate({_id: "myuser", members:[{_id: 0, host: "mongodb:27017"}]})'
sleep 5
log "Create a user profile"
docker exec -i mongodb mongo << EOF
use admin
db.createUser(
{
user: "myuser",
pwd: "mypassword",
roles: ["dbOwner"]
}
)
EOF
sleep 2
log "Creating MongoDB source connector"
curl -X PUT \
-H "Content-Type: application/json" \
--data '{
"connector.class" : "com.mongodb.kafka.connect.MongoSourceConnector",
"tasks.max" : "1",
"connection.uri" : "mongodb://myuser:mypassword@mongodb:27017",
"database":"inventory",
"collection":"customers",
"topic.prefix":"mongo"
}' \
http://localhost:8083/connectors/mongodb-source/config | jq .
sleep 5
log "Insert a record"
docker exec -i mongodb mongo << EOF
use inventory
db.customers.insert([
{ _id : 1, first_name : 'Bob', last_name : 'Hopper', email : '[email protected]' }
]);
EOF
log "View record"
docker exec -i mongodb mongo << EOF
use inventory
db.customers.find().pretty();
EOF
sleep 5
log "Verifying topic mongo.inventory.customers"
timeout 60 docker exec connect kafka-avro-console-consumer -bootstrap-server broker:9092 --property schema.registry.url=http://schema-registry:8081 --topic mongo.inventory.customers --from-beginning --max-messages 1