jeanNyil / debezium-syndesis-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IPAAS Syndesis meets Debezium

Follow these instructions to see how the changes to an Order service are propagated to a User service. User and Order are independent microservices with independent databases, no microservice business logic has been harmed during the experiments!

I am using minishift as local openshift development cluster; httpie as http CLI.

oc exec -it $(oc get pods -o custom-columns=NAME:.metadata.name --no-headers -l app=mysql --field-selector status.phase=Running) -- bash -c 'mysql -u root -p$MYSQL_ROOT_PASSWORD -e "CREATE Database user"'
oc exec -it $(oc get pods -o custom-columns=NAME:.metadata.name --no-headers -l app=mysql --field-selector status.phase=Running) -- bash -c 'mysql -u root -p$MYSQL_ROOT_PASSWORD -e "CREATE Database order"'
  • Create order CDC connector
oc exec -i -c kafka broker-kafka-0 -- curl -X POST \
    -H "Accept:application/json" \
    -H "Content-Type:application/json" \
    http://debezium-connect-api:8083/connectors -d @- <<'EOF'

{
    "name": "order-connector",
    "config": {
        "connector.class": "io.debezium.connector.mysql.MySqlConnector",
        "tasks.max": "1",
        "database.hostname": "mysql",
        "database.port": "3306",
        "database.user": "debezium",
        "database.password": "dbz",
        "database.server.id": "184054",
        "database.server.name": "dbserver1",
        "database.whitelist": "order",
        "database.history.kafka.bootstrap.servers": "broker-kafka-bootstrap:9092",
        "database.history.kafka.topic": "schema-changes.order"
    }
}
EOF
  • Deploy user microservice pod
cd user
mvn clean fabric8:deploy -P openshift
  • Deploy order microservice pod
cd order
mvn clean fabric8:deploy -P openshift
  • Create a Debezium integration on Syndesis mapping any new order creation to a user REST addOrder endpoint call and any order deletion to a user REST deleteOrder endpoint call. Wait for the integration to be up and running on your local openshift.

Create a debezium connection, setting kafka broker cluster URI
image 1

Create a new integration with the debezium connection source: select the order table change data topic and the schema change topic
image 2

Select a conditional flow as destination source
image 3

Define the condition events you want to capture: an order create and an order delete
image 4

Conditions will look like these:
image 5

Select the create condition branch
image 6

Set the action to perform when a new order is created: call the User REST API
image 7

Finally map the data coming from change data stream to the ones expected by the REST API
image 8

You must repeat the process for the delete condition branch as well. Here I leave the whole screencast for all details.

  • Create a user (host name can be different, checkout yours)
http POST http://user-syndesis-services.192.168.42.139.nip.io/user userId=123 userName=Foo

{
    "orders": [],
    "userId": 123,
    "userName": "Foo"
}
  • Create a order
http POST http://order-syndesis-services.192.168.42.139.nip.io/order orderId=987 orderPrice=100 userId=123

{
    "items": [],
    "orderId": 987,
    "orderPrice": 100,
    "userId": 123
}
  • Check the order list was updated correctly
http http://user-syndesis-services.192.168.42.139.nip.io/user/123

{
    "orders": [
        "987"
    ],
    "userId": 123,
    "userName": "Foo"
}
  • Delete a order
http DELETE http://order-syndesis-services.192.168.42.139.nip.io/order/987
  • Check the order list was updated correctly
http http://user-syndesis-services.192.168.42.139.nip.io/user/123

{
    "orders": [],
    "userId": 123,
    "userName": "Foo"
}
  • Stop the debezium-connect pod to simulate a downtime / network issue
  • Create an order
http POST http://order-syndesis-services.192.168.42.139.nip.io/order orderId=988 orderPrice=100 userId=123

{
    "items": [],
    "orderId": 988,
    "orderPrice": 100,
    "userId": 123
}
  • Check the order list is not yet updated
http http://user-syndesis-services.192.168.42.139.nip.io/user/123

{
    "orders": [],
    "userId": 123,
    "userName": "Foo"
}
  • Start the debezium-connect pod again
  • Wait a few seconds the process to start up and check the order list was updated correctly
http http://user-syndesis-services.192.168.42.139.nip.io/user/123

{
    "orders": [
        "988"
    ],
    "userId": 123,
    "userName": "Foo"
}

About


Languages

Language:Java 100.0%