Skip to content

BarbieCue/dapr-state-management

Repository files navigation

dapr example - state management

dapr

The following scenario is implemented here.

scenario

My service simply stores some data in a data store. But, it does not access the data store directly. Instead, it passes the data to its dapr sidecar and instructs it to store the data. Thus, dapr completely abstracts the underlying data store for My service.

Prerequisites

Get started

0. Install dapr

Install dapr on your system. This will start a redis docker container by default.

dapr init

1. Build the service

./gradlew buildFatJar

2. Run the service alongside a dapr sidecar

dapr run --app-id my-service --app-port 8080 --app-protocol http --dapr-http-port 3500 --components-path components/local/ -- java -cp build/libs/fat.jar com.example.MyServiceKt

As you can see, the dapr CLI is used to start up both, the dapr sidecar and the service.

3. Be the client - trigger the saving of the data

curl http://localhost:8080

State store configuration

dapr supports many data stores. A yaml config file specifies which concrete state store implementation is used for a project. This enables us to exchange the underlying state store implementation without making any code changes.

From the docs:

Each component has a specification (or spec) that it conforms to. Components are configured at design-time with a YAML file which is stored in either:

  • A components/local folder within your solution, or
  • Globally in the .dapr folder created when invoking dapr init.

In this project, the configuration file is placed inside the solution (components/local).

References

Releases

No releases published

Packages

No packages published

Languages