mirror of https://github.com/dapr/docs.git
parent
a480f12c61
commit
9066935a22
|
@ -14,7 +14,7 @@ extension.
|
||||||
The Wasm [HTTP middleware]({{< ref middleware.md >}}) allows you to rewrite a
|
The Wasm [HTTP middleware]({{< ref middleware.md >}}) allows you to rewrite a
|
||||||
request URI with custom logic compiled to a Wasm binary. In other words, you
|
request URI with custom logic compiled to a Wasm binary. In other words, you
|
||||||
can extend Dapr using external files that are not pre-compiled into the `daprd`
|
can extend Dapr using external files that are not pre-compiled into the `daprd`
|
||||||
binary. Dapr embeds [wazero][https://wazero.io] to accomplish this without CGO.
|
binary. Dapr embeds [wazero][https://wazero.io] to accomplish this without CGO.
|
||||||
|
|
||||||
Wasm modules are loaded from a filesystem path. On Kubernetes, see [mounting
|
Wasm modules are loaded from a filesystem path. On Kubernetes, see [mounting
|
||||||
volumes to the Dapr sidecar]({{> kubernetes-volume-mounts.md >}}) to configure
|
volumes to the Dapr sidecar]({{> kubernetes-volume-mounts.md >}}) to configure
|
||||||
|
@ -22,7 +22,6 @@ a filesystem mount that can contain Wasm modules.
|
||||||
|
|
||||||
## Component format
|
## Component format
|
||||||
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: dapr.io/v1alpha1
|
apiVersion: dapr.io/v1alpha1
|
||||||
kind: Component
|
kind: Component
|
||||||
|
@ -34,16 +33,22 @@ spec:
|
||||||
metadata:
|
metadata:
|
||||||
- name: path
|
- name: path
|
||||||
value: "./hello.wasm"
|
value: "./hello.wasm"
|
||||||
- name: runtime
|
- name: poolSize
|
||||||
value: "wazero"
|
value: 1
|
||||||
```
|
```
|
||||||
|
|
||||||
## Spec metadata fields
|
## Spec metadata fields
|
||||||
|
|
||||||
| Field | Details | Example |
|
Minimally, a user must specify a Wasm binary that contains the custom logic
|
||||||
|----------|------------------------------------------------|----------------|
|
used to rewrite requests. An instance of the Wasm binary is not safe to use
|
||||||
| path | A relative or absolute path to the Wasm binary | "./hello.wasm" |
|
concurrently. The below configuration fields control both the binary to
|
||||||
| poolSize | The instance count of the Wasm binary | 10 |
|
instantiate and how large an instance pool to use. A larger pool allows higher
|
||||||
|
concurrency while consuming more memory.
|
||||||
|
|
||||||
|
| Field | Details | Required | Example |
|
||||||
|
|----------|----------------------------------------------------------------|----------|----------------|
|
||||||
|
| path | A relative or absolute path to the Wasm binary to instantiate. | false | "./hello.wasm" |
|
||||||
|
| poolSize | Number of concurrent instances of the Wasm binary. Default: 10 | true | 1 |
|
||||||
|
|
||||||
## Dapr configuration
|
## Dapr configuration
|
||||||
|
|
||||||
|
@ -72,6 +77,7 @@ To compile your Wasm, you must compile source using a waPC guest SDK such as
|
||||||
[TinyGo](https://github.com/wapc/wapc-guest-tinygo).
|
[TinyGo](https://github.com/wapc/wapc-guest-tinygo).
|
||||||
|
|
||||||
Here's an example in TinyGo:
|
Here's an example in TinyGo:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -90,7 +96,9 @@ func rewrite(requestURI []byte) ([]byte, error) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If using TinyGo, compile as shown below and set the `path` attribute to the output:
|
If using TinyGo, compile as shown below and set the spec metadata field named
|
||||||
|
"path" to the location of the output (ex "example.wasm"):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tinygo build -o example.wasm -scheduler=none --no-debug -target=wasi example.go`
|
tinygo build -o example.wasm -scheduler=none --no-debug -target=wasi example.go`
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue