java-sdk/spring-boot-examples/kubernetes
salaboy 5dbeafc24a
Adding producer and consumer app examples for Spring Boot integration (#1208)
* adding spring boot producer

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding consumer app

Signed-off-by: salaboy <Salaboy@gmail.com>

* increasing wait for events to popup

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding readme and examples

Signed-off-by: salaboy <Salaboy@gmail.com>

* aligning tests for examples

Signed-off-by: salaboy <Salaboy@gmail.com>

* increasing time out

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding health check from the sidecar

Signed-off-by: salaboy <Salaboy@gmail.com>

* feat: Adding basic HTTPEndpoint configuration support in testcontainers module (#1210)

* feat: Adding basic HTTPEndpoint configuration support in testcontainers module

Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>

* feat: #1209 Adding test for HTTPEndpoint in testcontainers module

Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>

---------

Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* updating example

Signed-off-by: salaboy <Salaboy@gmail.com>

* fixing example

Signed-off-by: salaboy <Salaboy@gmail.com>

* Add app health check support to Dapr Testcontainer (#1213)

* Add app health check support to Dapr Testcontainer

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>

* Some minor cleanup

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>

* Move waiting to beforeEach, it looks more natural

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>

---------

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>
Co-authored-by: Artur Ciocanu <ciocanu@adobe.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* commenting reuse

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding how to run on Kubernetes, unfortunately we need to create containers

Signed-off-by: salaboy <Salaboy@gmail.com>

* removing subscription and fixing scopes

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding license headers and logger

Signed-off-by: salaboy <Salaboy@gmail.com>

* updating logs

Signed-off-by: salaboy <Salaboy@gmail.com>

* updating READMEs and update_sdk_version for new module

Signed-off-by: salaboy <Salaboy@gmail.com>

* removing old line

Signed-off-by: salaboy <Salaboy@gmail.com>

* removing sleeps, using Wait

Signed-off-by: salaboy <Salaboy@gmail.com>

* updating Kubernetes tutorial to use local registry with KIND, and provide steps to create containers with spring boot

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding new lines and formatting

Signed-off-by: salaboy <Salaboy@gmail.com>

* updating reuse and removing comments

Signed-off-by: salaboy <Salaboy@gmail.com>

* fixing reuse

Signed-off-by: salaboy <Salaboy@gmail.com>

* removing line break

Signed-off-by: salaboy <Salaboy@gmail.com>

* fixing custom line breaks

Signed-off-by: salaboy <Salaboy@gmail.com>

* fixing xml indent to 2 spaces

Signed-off-by: salaboy <Salaboy@gmail.com>

* Update spring-boot-examples/README.md

Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Update spring-boot-examples/README.md

Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Update spring-boot-examples/README.md

Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Update spring-boot-examples/README.md

Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Update spring-boot-examples/README.md

Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Update spring-boot-examples/consumer-app/src/test/java/io/dapr/springboot/examples/consumer/ConsumerAppTests.java

Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Update spring-boot-examples/producer-app/src/test/java/io/dapr/springboot/examples/producer/TestSubscriberRestController.java

Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* adding license header to missing files

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding automated testing for spring boot example

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding sb examples to the validation pipeline

Signed-off-by: salaboy <Salaboy@gmail.com>

* updating timeouts

Signed-off-by: salaboy <Salaboy@gmail.com>

* updating return codes

Signed-off-by: salaboy <Salaboy@gmail.com>

---------

Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: Laurent Broudoux <laurent.broudoux@gmail.com>
Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>
Signed-off-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: Laurent Broudoux <laurent.broudoux@gmail.com>
Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com>
Co-authored-by: Artur Ciocanu <ciocanu@adobe.com>
Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Co-authored-by: Cassie Coyle <cassie@diagrid.io>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
2025-02-28 20:33:40 -08:00
..
README.md Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00
consumer-app.yaml Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00
kind-with-registry.sh Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00
kvbinding.yaml Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00
kvstore.yaml Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00
producer-app.yaml Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00
pubsub.yaml Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00

README.md

Running this example on Kubernetes

To run this example on Kubernetes, you can use any Kubernetes distribution. We install Dapr on a Kubernetes cluster and then we will deploy both the producer-app and consumer-app.

Creating a cluster and installing Dapr

If you don't have any Kubernetes cluster you can use Kubernetes KIND to create a local cluster. We will create a cluster with a local container registry, so we can push our container images to it. This is covered in the KIND documentation here.

./kind-with-registry.sh

Once you have the cluster up and running you can install Dapr:

helm repo add dapr https://dapr.github.io/helm-charts/
helm repo update
helm upgrade --install dapr dapr/dapr \
--version=1.14.4 \
--namespace dapr-system \
--create-namespace \
--wait

Creating containers using Spring Boot and pushing to local registry

Now that we have our cluster set up with a local container registry, we need to build our producer-app and consumer-app containers. For this we will use Spring Boot build it functions to create container images using Buildpacks:

From inside the spring-boot-examples/producer-app directory you can run the following command to create a container:

mvn spring-boot:build-image

Once we have the container image created, we need to tag and push to the local registry, so the image can be used from our local cluster. Alternatively, you can push the images to a public registry and update the Kubernetes manifests accordingly.

docker tag producer-app:0.14.0-SNAPSHOT localhost:5001/sb-producer-app
docker push localhost:5001/sb-producer-app

From inside the spring-boot-examples/consumer-app directory you can run the following command to create a container:

mvn spring-boot:build-image

Once we have the container image created, we need to tag and push to the local registry, so the image can be used from our local cluster. Alternatively, you can push the images to a public registry and update the Kubernetes manifests accordingly.

docker tag consumer-app:0.14.0-SNAPSHOT localhost:5001/sb-consumer-app
docker push localhost:5001/sb-consumer-app

Now we are ready to install our application into the cluster.

Installing and interacting with the application

Now that we have a running Kubernetes cluster, we need to first install the components needed by the application. In this case RabbitMQ and PostgreSQL. We will use Helm to do so:

Let's start with RabbitMQ:

helm install rabbitmq  oci://registry-1.docker.io/bitnamicharts/rabbitmq --set auth.username=guest --set auth.password=guest --set auth.erlangCookie=ABC

Then PostgreSQL:

helm install postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --set global.postgresql.auth.database=dapr --set global.postgresql.auth.postgresPassword=password

Once we have these components up and running we can install the application by running from inside the spring-boot-examples/kubernetes/ directory:

kubectl apply -f .

Next you need to use kubectl port-forward to be able to send requests to the applications.

kubectl port-forward svc/producer-app 8080:8080

In a different terminals you can check the logs of the producer-app and consumer-app:

kubectl logs -f producer-app-<POD_ID>

and

kubectl logs -f consumer-app-<POD_ID>