Skip to content

speedfl/dapr-example-k8s

Repository files navigation

Dapr Pub/Sub example AWS/AZURE/GCP/Redis

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.

services

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

Install Dapr

You need to setup Dapr on your Kubernetes cluster

dapr init -k -n <namespace>

dapr-resources

Configure tracing

Add tracing

Install Jaeger:

Procedure: https://github.com/jaegertracing/jaeger-operator

Then create the jaeger tracing:

kubectl -n observability apply -f k8s-resources/jaeger-tracing.yaml

jaeger-resources

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

Choose your Pub/Sub middleware

To start you need to choose your Pub/Sub middleware. To do so you can go to dapr-resources

Build and deploy applications

To build an deploy applications you can use:

./lifecycle.sh build
./lifecycle.sh deploy

Or you can do this on each repository.

deployed

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:

producer logs

Consumer notification Logs:

notification logs

Consumer billing Logs:

billing logs

Now let's take a look to the tracing:

Topology:

traces

Traces:

trace1 trace2

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published