This repository contains a real life example of Pub/Sub using Dapr. It will show you how it is simple to switch from one pub/sub to another.
We will build a simple software with a micro-service exposing an endpoint to create an Order. This will Publish an event when the Order is Created. Two applications will subscribe to this event, a Notification service and a Billing service.
The backends are Quarkus applications.
I am using:
- Quarkus for Application development
- jib for image building
- k3d for local kubernetes cluster
- lens as Kubernetes IDE
You need to setup Dapr on your Kubernetes cluster
dapr init -k -n <namespace>
Install Jaeger:
Procedure: https://github.com/jaegertracing/jaeger-operator
Then create the jaeger tracing:
kubectl -n observability apply -f k8s-resources/jaeger-tracing.yaml
Source: https://docs.dapr.io/operations/monitoring/tracing/supported-tracing-backends/jaeger/
Then you need to create the configuration:
kubectl apply -f dapr-resources/dapr-tracing-configuration.yaml
To access jaeger UI:
kubectl port-forward svc/jaeger-query 16686 -n observability
Then access to http://127.0.0.1:16686/jaeger/trace
To start you need to choose your Pub/Sub middleware. To do so you can go to dapr-resources
To build an deploy applications you can use:
./lifecycle.sh build
./lifecycle.sh deploy
Or you can do this on each repository.
Now let's shoot our API:
curl --location --request POST 'http://order.127.0.0.1.nip.io/order' \
--header 'Content-Type: application/json' \
--data-raw '{
"total": {
"amount": 1000,
"currency": "EUR"
}
}'
{
"id": "96bfeb1c-2d72-45c2-92a6-ac4d88ea43d6",
"creationTime": 1633428351398,
"total": {
"amount": 1000,
"currency": "EUR"
}
}
Let's now check the logs of our micro-services.
Producer Logs:
Consumer notification Logs:
Consumer billing Logs:
Now let's take a look to the tracing:
Topology:
Traces: