java-sdk/spring-boot-examples
salaboy 447e2bfa86
Adding remote endpoint request from inside activity with retry (#1388)
* adding remote endpoint request from inside activity with retry

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

* adding retry with Microcks payloads

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

* fixing review comments

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

* chore: New task execution task id test (#1352)

* chore: New task execution task id test

test how taskExecutionTaskId can be used for idempotency

Signed-off-by: Javier Aliaga <javier@diagrid.io>

* chore: Clean up not used files

Signed-off-by: Javier Aliaga <javier@diagrid.io>

* docs: Task execution keys

Signed-off-by: Javier Aliaga <javier@diagrid.io>

* test: Modify unit tests

Signed-off-by: Javier Aliaga <javier@diagrid.io>

* Remove new lines

Signed-off-by: artur-ciocanu <artur.ciocanu@gmail.com>

---------

Signed-off-by: Javier Aliaga <javier@diagrid.io>
Signed-off-by: artur-ciocanu <artur.ciocanu@gmail.com>
Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Revert "chore: New task execution task id test (#1352)" (#1389)

This reverts commit 949584f69f.

Signed-off-by: Javier Aliaga <javier@diagrid.io>
Signed-off-by: salaboy <Salaboy@gmail.com>

* 1.5.5 (#1390)

Signed-off-by: Cassandra Coyle <cassie@diagrid.io>
Signed-off-by: salaboy <Salaboy@gmail.com>

* Add Documentation for Conversation AI SDK (#1387)

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

* Cleanup Spring Dependencies (#1334)

* Update CONTRIBUTING.md

Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>

* Fix spring

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Add context

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Phase 1

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix things

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix things

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix spring

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Add context

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Phase 1

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix things

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix things

Signed-off-by: siri-varma <siri.varma@outlook.com>

* move version

Signed-off-by: sirivarma <siri.varma@outlook.com>

* Fix pom

Signed-off-by: sirivarma <siri.varma@outlook.com>

* change version

Signed-off-by: sirivarma <siri.varma@outlook.com>

* remove unused

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Address comments

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix test

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix test

Signed-off-by: siri-varma <siri.varma@outlook.com>

* Fix things

Signed-off-by: sirivarma <siri.varma@outlook.com>

---------

Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>
Signed-off-by: siri-varma <siri.varma@outlook.com>
Signed-off-by: sirivarma <siri.varma@outlook.com>
Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com>
Signed-off-by: salaboy <Salaboy@gmail.com>

* network is needed

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

---------

Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: Javier Aliaga <javier@diagrid.io>
Signed-off-by: artur-ciocanu <artur.ciocanu@gmail.com>
Signed-off-by: Cassandra Coyle <cassie@diagrid.io>
Signed-off-by: Siri Varma Vegiraju <siri.varma@outlook.com>
Signed-off-by: siri-varma <siri.varma@outlook.com>
Signed-off-by: sirivarma <siri.varma@outlook.com>
Co-authored-by: Javier Aliaga <javier@diagrid.io>
Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com>
Co-authored-by: Siri Varma Vegiraju <siri.varma@outlook.com>
2025-05-30 18:28:18 -07:00
..
consumer-app Cleanup Spring Dependencies (#1334) 2025-05-28 21:37:23 -07:00
kubernetes Fix : Typo in code comments (#1381) 2025-05-21 09:01:09 -07:00
producer-app Update master version to 1.16.0-SNAPSHOT 2025-05-08 18:32:56 +00:00
workflows Adding remote endpoint request from inside activity with retry (#1388) 2025-05-30 18:28:18 -07:00
README.md Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00
pom.xml Spring boot workflow patterns examples with mechanical markdown and tests (#1377) 2025-05-21 14:56:55 -05:00
spotbugs-exclude.xml Adding producer and consumer app examples for Spring Boot integration (#1208) 2025-02-28 20:33:40 -08:00

README.md

Dapr Spring Boot and Testcontainers integration Example

This example consists of two applications:

  • Producer App:
    • Publish messages using a Spring Messaging approach
    • Store and retrieve information using Spring Data CrudRepository
    • Implements a Workflow with Dapr Workflows
  • Consumer App:
    • Subscribe to messages

Running these examples from source code

To run these examples you will need:

  • Java SDK
  • Maven
  • Docker or a container runtime such as Podman

From the spring-boot-examples/ directory you can start each service using the test configuration that uses Testcontainers to boostrap Dapr by running the following command:

cd producer-app/
../../mvnw -Dspring-boot.run.arguments="--reuse=true" spring-boot:test-run

This will start the producer-app with Dapr services and the infrastructure needed by the application to run, in this case RabbitMQ and PostgreSQL. The producer-app starts on port 8080 by default.

The -Dspring-boot.run.arguments="--reuse=true" flag helps the application to connect to an existing shared infrastructure if it already exists. For development purposes, and to connect both applications we will set the flag in both. For more details check the DaprTestContainersConfig.java classes in both, the producer-app and the consumer-app.

Then run in a different terminal:

cd consumer-app/
../../mvnw -Dspring-boot.run.arguments="--reuse=true" spring-boot:test-run

The consumer-app starts in port 8081 by default.

Interacting with the applications

Now that both applications are up you can place an order by sending a POST request to :8080/orders/ You can use curl to send a POST request to the producer-app:

curl -X POST localhost:8080/orders -H 'Content-Type: application/json' -d '{ "item": "the mars volta EP", "amount": 1 }'

If you check the producer-app logs you should see the following lines:

...
Storing Order: Order{id='null', item='the mars volta EP', amount=1}
Publishing Order Event: Order{id='d4f8ea15-b774-441e-bcd2-7a4208a80bec', item='the mars volta EP', amount=1}

If you check the consumer-app logs you should see the following lines, showing that the message published by the producer-app was correctly consumed by the consumer-app:

Order Event Received: Order{id='d4f8ea15-b774-441e-bcd2-7a4208a80bec', item='the mars volta EP', amount=1}

Next, you can create a new customer to trigger the customer's tracking workflow:

curl -X POST localhost:8080/customers -H 'Content-Type: application/json' -d '{ "customerName": "salaboy" }'

A new Workflow Instance was created to track the customers interactions. Now, the workflow instance is waiting for the customer to request a follow-up.

You should see in the producer-app logs:

Workflow instance <Workflow Instance Id> started
Let's register the customer: salaboy
Customer: salaboy registered.
Let's wait for the customer: salaboy to request a follow up.

Send an event simulating the customer request for a follow-up:

curl -X POST localhost:8080/customers/followup -H 'Content-Type: application/json' -d '{ "customerName": "salaboy" }'

In the producer-app logs you should see that the workflow instance id moved forward to the Customer Follow Up activity:

Customer follow-up requested: salaboy
Let's book a follow up for the customer: salaboy
Customer: salaboy follow-up done.
Congratulations the customer: salaboy is happy!

Running on Kubernetes

You can run the same example on a Kubernetes cluster. Check the Kubernetes tutorial here.