Skip to content

Commit

Permalink
Improve the documentation (#190)
Browse files Browse the repository at this point in the history
* Improve the documentation

* Add dot

* Improve the documentation

---------

Co-authored-by: Matheus Cruz <matheus.mcruz@mercadolivre.com>
  • Loading branch information
mcruzdev and mathecruz authored Aug 9, 2024
1 parent 25dc79c commit a1aec60
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ For more information about Dapr, please go https://dapr.io/.

Quarkus Dapr is a Quarkus extension to integrate with Dapr.

Please, see the [latest released documentation](https://docs.quarkiverse.io/quarkus-dapr/dev/index.html) if you are looking for instructions.

Quarkus Dapr Extension enables Java developers to create ultra lightweight Java native applications for Function
Computing and FaaS scenes, which is also particularly suitable for running as serverless.

Expand Down
77 changes: 74 additions & 3 deletions docs/modules/ROOT/pages/includes/devservices.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,83 @@ Dev Services for Dapr are disabled by default unless:

Dev Services for Dapr uses the latest `daprio/daprd` image (`diagrid/daprd:latest`). You can change this image using the `quarkus.dapr.devservices.image-name` property.

== Adding Dapr Components
== Using In-Memory Dapr Components

> [NOTE]
The link:https://docs.dapr.io/concepts/components-concept[component] name for link:https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-inmemory[Pub/Sub in-memory] is called `pubsub` and for link:https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-inmemory/[State Store in-memory] is called `kvstore`.

Example of code using Pub/Sub and State Store in-memory:

[source,java]
.DaprResource.java
----
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();
}
By default, Dapr DevServices create a Dapr container containing in-memory Pub/Sub and in-memory State Store building blocks.
@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 in-memory State Store component created by DevServices, and `identity` is the key used to store the value.
<2> `pubsub` is the name of the in-memory Pub/Sub component created by DevServices, and `topicName` is the name of the topic used to publish the message (`Hello from Quarkus!`).
<3> `topicName` is the name of the topic used to subscribe to the message, you need to add the `@io.dapr.Topic` annotation to map the topic.
If you want to add a custom Dapr component, you need to add it to the `src/main/resources/components` folder.
<4> The value `sub` can be any value, it is used behind the scenes to map the endpoint to the topic.

> [IMPORTANT]
> The default `quarkus.dapr.default-pub-sub` value is `redis`, so you need to change to `pubsub` if you want to use the in-memory Pub/Sub component.

== Adding Dapr Components

By default, Dapr DevServices create a Dapr container containing in-memory Pub/Sub and in-memory State Store building blocks. If you want to use a non-in-memory Dapr component, you need to add it to the `src/main/resources/components` folder.

Example of Pub/Sub using Redis.

[source,yaml]
.src/main/resources/components/redis-pubsub.yaml
----
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
Expand All @@ -31,10 +99,13 @@ spec:
value: localhost:6379
- name: redisPassword
value: ""
----

Example of State Store using Redis:

[source,yaml]
.src/main/resources/components/redis-statestore.yaml
----
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
Expand All @@ -49,7 +120,7 @@ spec:
value: localhost:6379
- name: redisPassword
value: ""

----
== Network

By default, Dev Services for Dapr utilize a network named `dapr`.
Expand Down
82 changes: 82 additions & 0 deletions docs/modules/ROOT/pages/includes/quarkus-dapr.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

:summaryTableId: quarkus-dapr
[.configuration-legend]
icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime
[.configuration-reference.searchable, cols="80,.^10,.^10"]
|===

h|[[quarkus-dapr_configuration]]link:#quarkus-dapr_configuration[Configuration property]

h|Type
h|Default

a|icon:lock[title=Fixed at build time] [[quarkus-dapr_quarkus-dapr-default-pub-sub]]`link:#quarkus-dapr_quarkus-dapr-default-pub-sub[quarkus.dapr.default-pub-sub]`


[.description]
--
default pub sub config

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_DAPR_DEFAULT_PUB_SUB+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_DAPR_DEFAULT_PUB_SUB+++`
endif::add-copy-button-to-env-var[]
--|string
|`redis`


a|icon:lock[title=Fixed at build time] [[quarkus-dapr_quarkus-dapr-pub-sub-pub-sub-type]]`link:#quarkus-dapr_quarkus-dapr-pub-sub-pub-sub-type[quarkus.dapr.pub-sub."pub-sub".type]`


[.description]
--
pub sub type

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_DAPR_PUB_SUB__PUB_SUB__TYPE+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_DAPR_PUB_SUB__PUB_SUB__TYPE+++`
endif::add-copy-button-to-env-var[]
--|string
|`redis`


a|icon:lock[title=Fixed at build time] [[quarkus-dapr_quarkus-dapr-pub-sub-pub-sub-publish-metadata-publish-metadata]]`link:#quarkus-dapr_quarkus-dapr-pub-sub-pub-sub-publish-metadata-publish-metadata[quarkus.dapr.pub-sub."pub-sub".publish-metadata."publish-metadata"]`


[.description]
--
publish pub sub default metadata

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_DAPR_PUB_SUB__PUB_SUB__PUBLISH_METADATA__PUBLISH_METADATA_+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_DAPR_PUB_SUB__PUB_SUB__PUBLISH_METADATA__PUBLISH_METADATA_+++`
endif::add-copy-button-to-env-var[]
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]

|


a|icon:lock[title=Fixed at build time] [[quarkus-dapr_quarkus-dapr-pub-sub-pub-sub-consume-metadata-consume-metadata]]`link:#quarkus-dapr_quarkus-dapr-pub-sub-pub-sub-consume-metadata-consume-metadata[quarkus.dapr.pub-sub."pub-sub".consume-metadata."consume-metadata"]`


[.description]
--
consume pub sub default metadata

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_DAPR_PUB_SUB__PUB_SUB__CONSUME_METADATA__CONSUME_METADATA_+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_DAPR_PUB_SUB__PUB_SUB__CONSUME_METADATA__CONSUME_METADATA_+++`
endif::add-copy-button-to-env-var[]
--|link:https://docs.oracle.com/javase/8/docs/api/java/lang/String.html[String]

|

|===
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.13.1</quarkus.version>
<dapr.version>1.11.0</dapr.version>
<okhttp.version>4.10.0</okhttp.version>
<okhttp.version>4.12.0</okhttp.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down

0 comments on commit a1aec60

Please sign in to comment.