Skip to content

Commit 1169c54

Browse files
committed
docs(springboot cloudconfig): Write examples and docs for springboot cloudconfig
Signed-off-by: lony2003 <zhangke200377@outlook.com>
1 parent 653bb12 commit 1169c54

File tree

20 files changed

+662
-2
lines changed

20 files changed

+662
-2
lines changed

daprdocs/content/en/java-sdk-docs/spring-boot/_index.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,146 @@ daprWorkflowClient.raiseEvent(instanceId, "MyEvenet", event);
323323

324324
Check the [Dapr Workflow documentation](https://docs.dapr.io/developing-applications/building-blocks/workflow/workflow-overview/) for more information about how to work with Dapr Workflows.
325325

326+
## Using Dapr Cloud Config with Spring Boot
327+
328+
To enable dapr cloud config, you should add following properties in your application's config (properties for example):
329+
330+
```properties
331+
# default enable is true, don't need to specify
332+
dapr.cloudconfig.enabled = true
333+
spring.config.import[0] = <schema>
334+
spring.config.import[1] = <schema>
335+
spring.config.import[2] = <schema>
336+
#... keep going if you want to import more configs
337+
```
338+
339+
There are other config of the dapr cloud config, listed below:
340+
341+
```properties
342+
#enable dapr cloud config or not (default = true).
343+
dapr.cloudconfig.enabled=true
344+
#timeout for getting dapr config (include wait for dapr sidecar) (default = 2000).
345+
dapr.cloudconfig.timeout=2000
346+
#whether enable dapr client wait for sidecar, if no response, will throw IOException (default = false).
347+
dapr.cloudconfig.wait-sidecar-enabled=false
348+
#retries of dapr client wait for sidecar (default = 3).
349+
dapr.cloudconfig.wait-sidecar-retries=3
350+
```
351+
352+
In Dapr Cloud Config component, we support two ways to imprt config: Secret Store API and Configuration API.
353+
354+
Both of them have their schemas, listed below.
355+
356+
### Cloud Config Import Schemas
357+
358+
#### Secret Store Component
359+
360+
##### url structure
361+
362+
`dapr:secret:<store-name>[/<secret-name>][?<paramters>]`
363+
364+
###### paramters
365+
366+
| parameter | description | default | available |
367+
|--------------------|--------------------|--------------------|--------------------|
368+
| type | value type | `value` | `value`/`doc`|
369+
| doc-type | type of doc | `properties` | `yaml`/`properties`/`or any file extensions you want`|
370+
371+
- when type = `value`, if `secret-name` is specified, will treat secret as the value of property, and `secret-name` as the key of property; if none `secret-name` is specified, will get bulk secret and treat every value of secret as the value of property, and every key of secret as the key of property.
372+
- when type = `doc`, if `secret-name` is specified, will treat secret as a bunch of property, and load it with property or yaml loader; if none `secret-name` is specified, will get bulk secret and and treat every value of secret as bunches of property, and load them with property or yaml loader.
373+
- secret store with multiValud = true must specify nestedSeparator = ".", and using type = `doc` is not recommanded
374+
375+
##### demo
376+
377+
###### multiValued = false:
378+
379+
####### store content(file secret store as example)
380+
381+
```json
382+
{
383+
"dapr.spring.demo-config-secret.singlevalue": "testvalue",
384+
"multivalue-properties": "dapr.spring.demo-config-secret.multivalue.v1=spring\ndapr.spring.demo-config-secret.multivalue.v2=dapr",
385+
"multivalue-yaml": "dapr:\n spring:\n demo-config-secret:\n multivalue:\n v3: cloud"
386+
}
387+
```
388+
389+
####### valid demo url
390+
391+
- `dapr:secret:democonfig/multivalue-properties?type=doc&doc-type=properties`
392+
- `dapr:secret:democonfig/multivalue-yaml?type=doc&doc-type=yaml`
393+
- `dapr:secret:democonfig/dapr.spring.demo-config.singlevalue?type=value`
394+
- `dapr:secret:democonfig?type=value`
395+
- `dapr:secret:democonfig?type=doc`
396+
397+
###### multiValued = true, nestedSeparator = ".":
398+
399+
####### store content(file secret store as example)
400+
401+
```json
402+
{
403+
"value1": {
404+
"dapr": {
405+
"spring": {
406+
"demo-config-secret": {
407+
"multivalue": {
408+
"v4": "config"
409+
}
410+
}
411+
}
412+
}
413+
}
414+
}
415+
```
416+
417+
will be read as
418+
419+
```json
420+
{
421+
"value1": {
422+
"dapr.spring.demo-config-secret.multivalue.v4": "config"
423+
}
424+
}
425+
```
426+
427+
####### valid demo url
428+
- `dapr:secret:demo-config-multi/value1?type=value`
429+
- `dapr:secret:demo-config-multi?type=value`
430+
431+
#### Configuration Component
432+
433+
##### url structure
434+
435+
`dapr:config:<store-name>[/<key>][?<paramters>]`
436+
437+
###### paramters
438+
439+
| parameter | description | default | available |
440+
|--------------------|--------------------|--------------------|--------------------|
441+
| type | value type | `value` | `doc`/`value` |
442+
| doc-type | type of doc | `properties` | `yaml`/`properties`/`or any file extensions you want`|
443+
| subscribe | subscribe this configuration | `false` | `true`/`false` |
444+
445+
- when subscribe = `true`, will subscribe update for the configuration.
446+
- when type = `value`, if `key` is specified, will treat config value as the value of property, and `key` as the key of property; if none `key` is specified, will get all key and value in the `config-name` and treat every config value as the value of property, and every `key` as the key of property.
447+
- when type = `doc`, if `key` is specified, will treat config value as a bunch of property, and load it with property or yaml loader; if none `key` is specified, will get all key and value in the `config-name` and treat every config value as bunches of property, and load them with property or yaml loader.
448+
449+
##### Demo
450+
451+
###### store content(table as example)
452+
453+
| key | value |
454+
|--------------------|--------------------|
455+
| dapr.spring.demo-config-config.singlevalue | testvalue |
456+
| multivalue-properties | `dapr.spring.demo-config-config.multivalue.v1=spring\ndapr.spring.demo-config-config.multivalue.v2=dapr` |
457+
| multivalue-yaml | `dapr:\n spring:\n demo-config-config:\n multivalue:\n v3: cloud` |
458+
459+
###### valid demo url
460+
461+
- `dapr:config:democonfigconf/dapr.spring.demo-config-config.singlevalue?type=value`
462+
- `dapr:config:democonfigconf/multivalue-properties?type=doc&doc-type=properties`
463+
- `dapr:config:democonfigconf/multivalue-yaml?type=doc&doc-type=yaml`
464+
- `dapr:config:democonfigconf?type=doc`
465+
- `dapr:config:democonfigconf?type=value`
326466

327467
## Next steps
328468

sdk-tests/components/secret.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"94022f35-25ab-4ffa-a4a0-9b45b602b50c":{"name":"Jon Doe"},"e1f219a2-2689-4689-a18d-372bdf989b05":{"year":"2020","title":"The Metrics IV"}}
1+
{"589f54ec-d0b7-40b5-92d9-6ab7ddef3c4f":{"name":"Jon Doe"},"969595f8-859c-4f7d-ae6a-864704f94a10":{"year":"2020","title":"The Metrics IV"}}

sdk-tests/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<groupId>redis.clients</groupId>
7474
<artifactId>jedis</artifactId>
7575
<version>5.2.0</version>
76+
<scope>test</scope>
7677
</dependency>
7778
<dependency>
7879
<groupId>io.grpc</groupId>

spring-boot-examples/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Dapr Spring Boot and Testcontainers integration Example
22

3-
This example consists of two applications:
3+
This example consists of three applications:
44
- Producer App:
55
- Publish messages using a Spring Messaging approach
66
- Store and retrieve information using Spring Data CrudRepository
77
- Implements a Workflow with Dapr Workflows
88
- Consumer App:
99
- Subscribe to messages
10+
- Cloud Config Demo:
11+
- Import and use configs
12+
- Can not run in Kubernetes currently, as lack of redis pre-fill data supported
1013

1114
## Running these examples from source code
1215

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: democonfigconf
5+
spec:
6+
type: configuration.redis
7+
version: v1
8+
metadata:
9+
- name: redisHost
10+
value: localhost:6379
11+
- name: redisPassword
12+
value: ""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"value1": {
3+
"dapr": {
4+
"spring": {
5+
"demo-config-secret": {
6+
"multivalue": {
7+
"v4": "config"
8+
}
9+
}
10+
}
11+
}
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dapr.spring.demo-config-secret.singlevalue": "testvalue",
3+
"multivalue-properties": "dapr.spring.demo-config-secret.multivalue.v1=spring\ndapr.spring.demo-config-secret.multivalue.v2=dapr",
4+
"multivalue-yaml": "dapr:\n spring:\n demo-config-secret:\n multivalue:\n v3: cloud"
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: democonfigMultivalued
5+
spec:
6+
type: secretstores.local.file
7+
version: v1
8+
metadata:
9+
- name: secretsFile
10+
value: "./components/secret-spring/multivalued.json"
11+
- name: nestedSeparator
12+
value: "."
13+
- name: multiValued
14+
value: "true"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: democonfig
5+
spec:
6+
type: secretstores.local.file
7+
version: v1
8+
metadata:
9+
- name: secretsFile
10+
value: "./components/secret-spring/singlevalued.json"
11+
- name: multiValued
12+
value: "false"
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>io.dapr</groupId>
8+
<artifactId>spring-boot-examples</artifactId>
9+
<version>0.15.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>cloud-config-demo</artifactId>
13+
<name>cloud-config-demo</name>
14+
<description>Spring Boot, Testcontainers and Dapr Integration Examples :: Cloud Config Demo</description>
15+
16+
17+
<dependencyManagement>
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-dependencies</artifactId>
22+
<version>${springboot.version}</version>
23+
<type>pom</type>
24+
<scope>import</scope>
25+
</dependency>
26+
</dependencies>
27+
</dependencyManagement>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-actuator</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.dapr.spring</groupId>
41+
<artifactId>dapr-spring-boot-starter</artifactId>
42+
<version>${dapr.sdk.alpha.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>io.dapr.spring</groupId>
46+
<artifactId>dapr-spring-boot-starter-test</artifactId>
47+
<version>${dapr.sdk.alpha.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.testcontainers</groupId>
52+
<artifactId>junit-jupiter</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>redis.clients</groupId>
57+
<artifactId>jedis</artifactId>
58+
<version>5.2.0</version>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>com.redis</groupId>
63+
<artifactId>testcontainers-redis</artifactId>
64+
<version>2.2.4</version>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>io.rest-assured</groupId>
69+
<artifactId>rest-assured</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
</dependencies>
73+
74+
<build>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.springframework.boot</groupId>
78+
<artifactId>spring-boot-maven-plugin</artifactId>
79+
</plugin>
80+
<plugin>
81+
<groupId>org.apache.maven.plugins</groupId>
82+
<artifactId>maven-site-plugin</artifactId>
83+
<version>3.12.1</version>
84+
<configuration>
85+
<skip>true</skip>
86+
</configuration>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
</project>

0 commit comments

Comments
 (0)