Skip to content

Commit

Permalink
Merge branch 'v1.11' into nats-deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
msfussell authored Aug 8, 2023
2 parents 57e6f4c + d4e1907 commit 3f38678
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ Using Dapr's bindings API, you can trigger your app with events coming in from e
- Switch between bindings at runtime.
- Build portable applications with environment-specific bindings set-up and no required code changes.

For example, with bindings, your microservice can respond to incoming Twilio/SMS messages without:
For example, with bindings, your application can respond to incoming Twilio/SMS messages without:

- Adding or configuring a third-party Twilio SDK
- Worrying about polling from Twilio (or using WebSockets, etc.)

{{% alert title="Note" color="primary" %}}
<img src="/images/binding-overview.png" width=1000 alt="Diagram showing bindings">

In the above diagram:
- The input binding triggers a method on your application.
- Execute output binding operations on the component, such as `"create"`.

Bindings are developed independently of Dapr runtime. You can [view and contribute to the bindings](https://github.com/dapr/components-contrib/tree/master/bindings).
{{% /alert %}}

{{% alert title="Note" color="primary" %}}
If you are using the HTTP Binding, then it is preferable to use [service invocation]({{< ref service_invocation_api.md >}}) instead. Read [How-To: Invoke Non-Dapr Endpoints using HTTP]({{< ref "howto-invoke-non-dapr-endpoints.md" >}}) for more information.
Expand Down Expand Up @@ -53,7 +57,12 @@ With output bindings, you can invoke external resources. An optional payload and
To invoke an output binding:

1. Define the component YAML that describes the binding type and its metadata (connection info, etc.).
2. Use the HTTP endpoint or gRPC method to invoke the binding with an optional payload.
1. Use the HTTP endpoint or gRPC method to invoke the binding with an optional payload.
1. Specify an output operation. Output operations depend on the binding component you use, and can include:
- `"create"`
- `"update"`
- `"delete"`
- `"exec"`

Read the [Use output bindings to interface with external resources guide]({{< ref howto-bindings.md >}}) to get started with output bindings.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ spec:
metadata:
- name: schedule
value: "@every 10s" # valid cron schedule
- name: direction
value: "input" # direction of the cron binding
```
**Note:** The `metadata` section of `binding-cron.yaml` contains a [Cron expression]({{< ref cron.md >}}) that specifies how often the binding is invoked.
Expand Down Expand Up @@ -216,6 +218,8 @@ spec:
metadata:
- name: url # Required
value: "user=postgres password=docker host=localhost port=5432 dbname=orders pool_min_conns=1 pool_max_conns=10"
- name: direction
value: "output" # direction of the postgresql binding
```
In the YAML file:
Expand Down Expand Up @@ -391,6 +395,8 @@ spec:
metadata:
- name: schedule
value: "@every 10s" # valid cron schedule
- name: direction
value: "input" # direction of the cron binding
```
**Note:** The `metadata` section of `binding-cron.yaml` contains a [Cron expression]({{< ref cron.md >}}) that specifies how often the binding is invoked.
Expand Down Expand Up @@ -418,6 +424,8 @@ spec:
metadata:
- name: url # Required
value: "user=postgres password=docker host=localhost port=5432 dbname=orders pool_min_conns=1 pool_max_conns=10"
- name: direction
value: "output" # direction of the postgresql binding
```
In the YAML file:
Expand Down Expand Up @@ -595,6 +603,8 @@ spec:
metadata:
- name: schedule
value: "@every 10s" # valid cron schedule
- name: direction
value: "input" # direction of the cron binding
```
**Note:** The `metadata` section of `binding-cron.yaml` contains a [Cron expression]({{< ref cron.md >}}) that specifies how often the binding is invoked.
Expand Down Expand Up @@ -622,6 +632,8 @@ spec:
metadata:
- name: url # Required
value: "user=postgres password=docker host=localhost port=5432 dbname=orders pool_min_conns=1 pool_max_conns=10"
- name: direction
value: "output" # direction of the postgresql binding
```
In the YAML file:
Expand Down Expand Up @@ -805,6 +817,8 @@ spec:
metadata:
- name: schedule
value: "@every 10s" # valid cron schedule
- name: direction
value: "input" # direction of the cron binding
```
**Note:** The `metadata` section of `binding-cron.yaml` contains a [Cron expression]({{< ref cron.md >}}) that specifies how often the binding is invoked.
Expand Down Expand Up @@ -832,6 +846,8 @@ spec:
metadata:
- name: url # Required
value: "user=postgres password=docker host=localhost port=5432 dbname=orders pool_min_conns=1 pool_max_conns=10"
- name: direction
value: "output" # direction of the postgresql binding
```
In the YAML file:
Expand Down Expand Up @@ -1017,6 +1033,8 @@ spec:
metadata:
- name: schedule
value: "@every 10s" # valid cron schedule
- name: direction
value: "input" # direction of the cron binding
```
**Note:** The `metadata` section of `binding-cron.yaml` contains a [Cron expression]({{< ref cron.md >}}) that specifies how often the binding is invoked.
Expand Down Expand Up @@ -1044,6 +1062,8 @@ spec:
metadata:
- name: url # Required
value: "user=postgres password=docker host=localhost port=5432 dbname=orders pool_min_conns=1 pool_max_conns=10"
- name: direction
value: "output" # direction of the postgresql binding
```
In the YAML file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ spec:
metadata:
- name: url
value: "file://router.wasm"
- guestConfig
value: {"environment":"production"}
```
## Spec metadata fields
Expand All @@ -49,6 +51,7 @@ How to compile this is described later.
| Field | Details | Required | Example |
|-------|----------------------------------------------------------------|----------|----------------|
| url | The URL of the resource including the Wasm binary to instantiate. The supported schemes include `file://`, `http://`, and `https://`. The path of a `file://` URL is relative to the Dapr process unless it begins with `/`. | true | `file://hello.wasm`, `https://example.com/hello.wasm` |
| guestConfig | An optional configuration passed to Wasm guests. Users can pass an arbitrary string to be parsed by the guest code. | false | `enviroment=production`,`{"environment":"production"}` |

## Dapr configuration

Expand Down Expand Up @@ -120,6 +123,49 @@ If using TinyGo, compile as shown below and set the spec metadata field named
tinygo build -o router.wasm -scheduler=none --no-debug -target=wasi router.go`
```

### Wasm `guestConfig` example

Here is an example of how to use `guestConfig` to pass configurations to Wasm. In Wasm code, you can use the function `handler.Host.GetConfig` defined in guest SDK to get the configuration. In the following example, the Wasm middleware parses the executed `environment` from JSON config defined in the component.

```yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: wasm
spec:
type: middleware.http.wasm
version: v1
metadata:
- name: url
value: "file://router.wasm"
- guestConfig
value: {"environment":"production"}
```
Here's an example in TinyGo:
```go
package main

import (
"encoding/json"
"github.com/http-wasm/http-wasm-guest-tinygo/handler"
"github.com/http-wasm/http-wasm-guest-tinygo/handler/api"
)

type Config struct {
Environment string `json:"environment"`
}

func main() {
// get config bytes, which is the value of guestConfig defined in the component.
configBytes := handler.Host.GetConfig()
config := Config{}
json.Unmarshal(configBytes, &config)
handler.Host.Log(api.LogLevelInfo, "Config environment: "+config.Environment)
}
```


## Related links

Expand Down
Binary file added daprdocs/static/images/binding-overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3f38678

Please sign in to comment.