Skip to content

Example of running Dapr Java applications locally with Skaffold.

Notifications You must be signed in to change notification settings

diagrid-labs/dapr-skaffold

Repository files navigation

Dapr Skaffold Example

Overview

This example demonstrates how to perform local development with Dapr, Skaffold, and Diagrid Conductor. It covers:

  • Mocking Dapr client and unit testing applications.
  • Running multiple applications with Dapr multi-app run.
  • Deploying applications to a local Kubernetes cluster with Skaffold, and observing real-time redeployment for application code changes or Dapr CRD changes.

Dapr Skaffold Inner Loops

For a detailed step by step write, check out the blog post walking through these project steps.

Prerequisites

Install Kubernetes

To install Kubernetes on macOS, use the following commands:

brew install minikube
minikube start

Install Dapr and Diagrid Conductor

Follow the steps in the quickstart guide and apply your unique cluster connection token:

kubectl apply -f "YOUR_UNIQUE_CLUSTER_CONNECTION_TOKEN"

Install Skaffold

To install Skaffold, use the following command:

brew install skaffold

Install Redis

Install Redis using Helm:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install redis bitnami/redis --set cluster.enabled=false --set replica.replicaCount=0 --set fullnameOverride=dapr-dev-redis

Build the Application

This project comprises a Java app that publishes messages to Redis and another Java app that consumes these messages.

Clone the repository:

git clone git@github.com:bibryam/dapr-skaffold.git
cd dapr-skaffold

Build the Java applications and run unit tests:

mvn clean install

Run a Single Application

Use Dapr CLI to run a single application with a sidecar:

dapr run --app-id publisher --app-port 5001 --resources-path ./common/local -- java -jar publisher/target/Publisher-0.0.1-SNAPSHOT.jar

Run Multiple Applications

Run both applications at the same time with multi-app run:

dapr run -f dapr.yaml

Deploy the Applications to Kubernetes

To deploy the application, run:

skaffold dev

Sync Changes

Update the application YAML files or modify the Java code followed by a Maven build. The changes will be detected and redeployed automatically.

Test APIs with a Single Request

Publish a single order by calling the Publisher application:

curl -X POST http://localhost:5001/pubsub/orders \
-H "Content-Type: application/json" \
-d @order.json

Or use Dapr CLI to publish an order directly to the pubsub:

dapr publish --publish-app-id publisher --pubsub pubsub --topic orders --data '{"orderId": "123"}'

Test APIs with Multiple Requests

Install Apache Bench

brew install httpd

Perform Load Testing

ab -n 100 -c 100 -p order.json -T "application/json" http://localhost:5001/pubsub/orders       
ab -n 100 -c 100 -p order.json -T "application/json" http://localhost:3501/v1.0/publish/pubsub/orders       

About

Example of running Dapr Java applications locally with Skaffold.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published