Skip to content

Commit 0b599d8

Browse files
committed
optimize structuredformat docs
Signed-off-by: seal90 <578935869@qq.com>
1 parent 659f761 commit 0b599d8

2 files changed

Lines changed: 113 additions & 84 deletions

File tree

daprdocs/content/en/reference/components-reference/supported-name-resolution/nr-structformat.md

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
type: docs
3+
title: "StructuredFormat"
4+
linkTitle: "StructuredFormat"
5+
description: Detailed information on the StructuredFormat name resolution component
6+
---
7+
8+
9+
The **Structured Format** name resolver enables you to explicitly define service instances using structured configuration in **JSON or YAML**, either as inline strings or external files. It is designed for scenarios where service topology is **static and known in advance**, such as:
10+
11+
- Local development and testing
12+
- Integration or end-to-end test environments
13+
- Edge deployments
14+
15+
## Configuration format
16+
17+
Name resolution is configured via the [Dapr Configuration]({{< ref configuration-overview.md >}}).
18+
19+
```yaml
20+
apiVersion: dapr.io/v1alpha1
21+
kind: Configuration
22+
metadata:
23+
name: appconfig
24+
spec:
25+
nameResolution:
26+
component: "structuredformat"
27+
configuration:
28+
structuredType: "json" # or "yaml", "jsonFile", "yamlFile"
29+
stringValue: '{"appInstances":{"myapp":[{"ipv4":"127.0.0.1","port":4433}]}}'
30+
```
31+
32+
## Spec configuration fields
33+
34+
| Field | Required? | Description | Example |
35+
|------------------|-----------|-----------------------------------------------------------------------------|---------|
36+
| `structuredType` | Yes | Format and source type. Must be one of: `json`, `yaml`, `jsonFile`, `yamlFile` | `json` |
37+
| `stringValue` | Conditional | Required when `structuredType` is `json` or `yaml` | `{"appInstances":{"myapp":[{"ipv4":"127.0.0.1","port":4433}]}}` |
38+
| `filePath` | Conditional | Required when `structuredType` is `jsonFile` or `yamlFile` | `/etc/dapr/services.yaml` |
39+
40+
> **Important**: Only one of `stringValue` or `filePath` should be provided, based on `structuredType`.
41+
42+
## `appInstances` Schema
43+
44+
The configuration must contain a top-level `appInstances` object that maps **service IDs** to **lists of address instances**.
45+
46+
### Supported Address Fields
47+
48+
| Field | Type | Required? | Description |
49+
|----------|--------|-----------|-------------|
50+
| `domain` | string | No | Hostname or FQDN (e.g., `"api.example.com"`). Highest priority. |
51+
| `ipv4` | string | No | IPv4 address in dotted-decimal format (e.g., `"192.168.1.10"`). |
52+
| `ipv6` | string | No | Unbracketed IPv6 address (e.g., `"::1"`, `"2001:db8::1"`). |
53+
| `port` | int | **Yes** | TCP port number (**must be 1–65535**). |
54+
55+
> **Notes**:
56+
> - Service IDs must be non-empty strings.
57+
> - **At least one** of `domain`, `ipv4`, or `ipv6` must be non-empty per instance.
58+
> - Invalid or missing ports will cause initialization to fail.
59+
60+
## Address Selection Logic
61+
62+
For each instance, the resolver selects the **first non-empty address** in this priority order:
63+
64+
1. `domain` → e.g., `github.com`
65+
2. `ipv4` → e.g., `192.168.1.10`
66+
3. `ipv6` → e.g., `::1`
67+
68+
The final target address is formatted as:
69+
70+
- `host:port` for domain/IPv4
71+
- `[ipv6]:port` for IPv6 (automatically bracketed)
72+
73+
If a service has **multiple instances**, one is selected **uniformly at random** on each call.
74+
75+
## Examples
76+
77+
### Inline JSON
78+
```yaml
79+
configuration:
80+
structuredType: "json"
81+
stringValue: '{"appInstances":{"myapp":[{"ipv4":"127.0.0.1","port":4433}]}}'
82+
```
83+
→ Resolves `"myapp"` to `127.0.0.1:4433`
84+
85+
### Inline YAML (multi-line)
86+
```yaml
87+
configuration:
88+
structuredType: "yaml"
89+
stringValue: |
90+
appInstances:
91+
myapp:
92+
- domain: "example.com"
93+
port: 80
94+
- ipv6: "::1"
95+
port: 8080
96+
```
97+
→ Possible results: `example.com:80` or `[::1]:8080` (chosen randomly)
98+
99+
### From External File
100+
```yaml
101+
configuration:
102+
structuredType: "yamlFile"
103+
filePath: "/etc/dapr/services.yaml"
104+
```
105+
106+
With `/etc/dapr/services.yaml`:
107+
```yaml
108+
appInstances:
109+
backend:
110+
- ipv4: "10.0.0.5"
111+
port: 3000
112+
```
113+
→ Resolves `"backend"` to `10.0.0.5:3000`

0 commit comments

Comments
 (0)