This example showcases how Zeebe could orchestrate a payment microservice from within an order fulfillment microservice when Kafka is used as transport.
The
Logger
tasks are there only demo purposes to follow along on the console.
It leverages the connector's source to push a message onto Kafka whenever a payment is required, expecting some payment service to process it and emit an event (or send a response message) later on. This response is correlated to the waiting order fulfillment process using the connectors sink.
The example needs the payment service to be simulated, means you need to publish a record to the payment-confirm
topic. You could do that using the kafka-console-producer:
{
"eventType": "OrderPaid",
"orderId": 1,
"amount": 4000
}
You can visualize the records published by the source connector using the kafka-console-consumer or simply Control Center. The records are published on the topic
payment-request
.
- Install and run Kafka, Kafka Connect and Zeebe as described here. The following description assumes that you leverage a managed Zeebe Cluster in Camunda Cloud.
Follow the following steps
You can use zbctl
or the Camunda Modeler to deploy the process to Camunda Cloud.
Hint: If curl
is not available, you can also use Control Center to create the connectors.
Make sure to configure them according to the following properties: source connector properties, sink connector properties
Now create the source connector:
curl -X POST -H "Content-Type: application/json" --data @payment-source.json http://localhost:8083/connectors
Next, create the sink connector:
curl -X POST -H "Content-Type: application/json" --data @payment-sink.json http://localhost:8083/connectors
Now use the command line to to start a process instance, as you then can easily pass variables as JSON. Make sure to replace the Camunda Cloud connection information with your own:
zbctl --address 8fdfbf36-5c3a-49ff-b5c6-7057d396c88c.bru-2.zeebe.camunda.io:443 --clientId 6NlBrCXH5knkZsJod2xNaR~Z2Af45mYN --clientSecret TKJVqOUkauL-m93LjGaSlry6q.8~BsVIAiCFXsriK096qTEUbgGKw5q.SjE_YGhi create instance --variables "{\"orderId\": 1}" order
Replace the value of the orderId
variable to change the correlation key.
Using Linux (or Mac) you can easily open a separate console, navigate to the root project directory, and run a worker directing all jobs to the console:
zbctl --address 8fdfbf36-5c3a-49ff-b5c6-7057d396c88c.bru-2.zeebe.camunda.io:443 --clientId 6NlBrCXH5knkZsJod2xNaR~Z2Af45mYN --clientSecret TKJVqOUkauL-m93LjGaSlry6q.8~BsVIAiCFXsriK096qTEUbgGKw5q.SjE_YGhi create worker --handler cat --maxJobsActive 1 payment-requested & zbctl --address 8fdfbf36-5c3a-49ff-b5c6-7057d396c88c.bru-2.zeebe.camunda.io:443 --clientId 6NlBrCXH5knkZsJod2xNaR~Z2Af45mYN --clientSecret TKJVqOUkauL-m93LjGaSlry6q.8~BsVIAiCFXsriK096qTEUbgGKw5q.SjE_YGhi create worker --handler cat --maxJobsActive 1 payment-confirmed
If you do not want to start this worker, you can also simply wait 30 seconds for the time in BPMN to kick in and just skip the logging step.
In order to simulate the external payment confirmation service, let's start a Kafka producer.
docker-compose -f docker/docker-compose.yml exec kafka kafka-console-producer --request-required-acks 1 --broker-list kafka:19092 --topic payment-confirm
To confirm the order, we can write a record of the following format:
{"eventType": "OrderPaid", "orderId": 1, "amount": 4000}
Make sure to update the orderId
to match the expected correlation key.