Quarkus Dapr – Dev Services
The Quarkus Dapr Extension provides Dev Services to simplify local development when using Quarkus with Dapr. It automatically provisions the required infrastructure and configures the Dapr sidecar so you can focus on application development.
Setting the Dapr Image
Dev Services for Dapr uses container images that are compatible with the version defined by the dapr/java-sdk dependency.
By default, the image version is aligned with the constant declared in the dapr/java-sdk library. This guarantees runtime compatibility between the Java SDK and the Dapr sidecar.
If necessary, you can override the default image by configuring:
quarkus.dapr.devservices.image-name=your-custom-image
Dapr Dev Services – Provisioned Containers
By default, Quarkus Dapr Dev Services starts the following containers:
docker.io/library/postgres
ghcr.io/diagridio/diagrid-dashboard
docker.io/daprio/placement
docker.io/daprio/scheduler
docker.io/daprio/daprd
The first two containers (postgres and diagrid-dashboard) are required to enable Dapr Dashboard integration in the Dev UI.
In addition, Quarkus Dapr automatically provisions a State Store component named kvstore, configured to use the PostgreSQL instance.
You can disable the Dapr Dashboard with:
quarkus.dapr.devservices.dashboard.enabled=false
|
If the Dapr Dashboard is disabled, Quarkus Dapr automatically provisions an in-memory State Store component named |
Provided Dapr Components
As described above, Quarkus Dapr automatically configures the Dapr sidecar with a State Store component.
It also registers a Pub/Sub component. When running with Dev Services, this Pub/Sub component uses an in-memory implementation suitable for development and testing.
|
The component name for Pub/Sub (in-memory) is The component name for the State Store (in-memory or PostgreSQL) is |
Using Dev Services
The following example demonstrates how to use the automatically provisioned Pub/Sub and State Store components.
package io.dapr.docs;
import io.dapr.Topic;
import io.dapr.client.domain.CloudEvent;
import io.dapr.client.domain.State;
import io.quarkiverse.dapr.core.SyncDaprClient;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
import java.util.Map;
import java.util.UUID;
@Path("/dapr")
public class DaprResource {
@Inject
SyncDaprClient client;
@POST
@Path("/state")
public Response saveState() {
client.saveState("kvstore", "identity", UUID.randomUUID().toString()); (1)
return Response.ok().build();
}
@GET
@Path("/state")
public Response getState() {
State<String> state = client.getState("kvstore", "identity", String.class);
return Response.ok(Map.of("identity", state.getValue())).build();
}
@POST
@Path("/pub")
public void pub() {
client.publishEvent("pubsub", "topicName", "Hello from Quarkus!"); (2)
}
@POST
@Topic(name = "topicName") (3)
@Path("/sub") (4)
public void sub(CloudEvent<String> event) {
System.out.println("Received event: " + event.getData());
}
}
| 1 | kvstore is the name of the State Store component created by Dev Services. identity is the key used to store the value. |
| 2 | pubsub is the name of the Pub/Sub component created by Dev Services. topicName is the topic used to publish the message. |
| 3 | topicName must match the topic used in publishEvent. The @io.dapr.Topic annotation maps the endpoint to the topic. |
| 4 | The value sub can be any path. It is used internally to expose the subscription endpoint. |
|
The default value of
|
Adding Custom Dapr Components
To use non in-memory Dapr components, add them to the following directory:
src/main/resources/components
Example: Pub/Sub with Redis
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: pubsub
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: localhost:6379
- name: redisPassword
value: ""
Example: State Store with Redis
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
spec:
type: state.redis
version: v1
metadata:
- name: keyPrefix
value: name
- name: redisHost
value: localhost:6379
- name: redisPassword
value: ""
Quarkus Dapr automatically detects these files and configures the Dapr sidecar with the provided components during application startup.