mirror of https://github.com/dapr/docs.git
Merge branch 'v1.13' into apk_clarify_otel_host
This commit is contained in:
commit
21bd7971f0
|
@ -537,7 +537,7 @@ Try getting state again. Note that no value is returned.
|
||||||
|
|
||||||
Below are code examples that leverage Dapr SDKs for saving and retrieving multiple states.
|
Below are code examples that leverage Dapr SDKs for saving and retrieving multiple states.
|
||||||
|
|
||||||
{{< tabs Dotnet Java Python Javascript "HTTP API (Bash)" "HTTP API (PowerShell)">}}
|
{{< tabs Dotnet Java Python Go Javascript "HTTP API (Bash)" "HTTP API (PowerShell)">}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
@ -656,6 +656,56 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
```go
|
||||||
|
// dependencies
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
dapr "github.com/dapr/go-sdk/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
// code
|
||||||
|
func main() {
|
||||||
|
const STATE_STORE_NAME = "statestore"
|
||||||
|
rand.Seed(time.Now().UnixMicro())
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
orderId := rand.Intn(1000-1) + 1
|
||||||
|
client, err := dapr.NewClient()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
ctx := context.Background()
|
||||||
|
err = client.SaveState(ctx, STATE_STORE_NAME, "order_1", []byte(strconv.Itoa(orderId)), nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
keys := []string{"key1", "key2", "key3"}
|
||||||
|
items, err := client.GetBulkState(ctx, STATE_STORE_NAME, keys, nil, 100)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
for _, item := range items {
|
||||||
|
log.Println("Item from GetBulkState:", string(item.Value))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To launch a Dapr sidecar for the above example application, run a command similar to the following:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 go run OrderProcessingService.go
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
//dependencies
|
//dependencies
|
||||||
import { DaprClient, HttpMethod, CommunicationProtocolEnum } from '@dapr/dapr';
|
import { DaprClient, HttpMethod, CommunicationProtocolEnum } from '@dapr/dapr';
|
||||||
|
@ -738,7 +788,7 @@ State transactions require a state store that supports multi-item transactions.
|
||||||
|
|
||||||
Below are code examples that leverage Dapr SDKs for performing state transactions.
|
Below are code examples that leverage Dapr SDKs for performing state transactions.
|
||||||
|
|
||||||
{{< tabs Dotnet Java Python Javascript "HTTP API (Bash)" "HTTP API (PowerShell)">}}
|
{{< tabs Dotnet Java Python Go Javascript "HTTP API (Bash)" "HTTP API (PowerShell)">}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
@ -893,6 +943,79 @@ dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-g
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
|
```go
|
||||||
|
// dependencies
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
dapr "github.com/dapr/go-sdk/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
// code
|
||||||
|
func main() {
|
||||||
|
const STATE_STORE_NAME = "statestore"
|
||||||
|
rand.Seed(time.Now().UnixMicro())
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
orderId := rand.Intn(1000-1) + 1
|
||||||
|
client, err := dapr.NewClient()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
ctx := context.Background()
|
||||||
|
err = client.SaveState(ctx, STATE_STORE_NAME, "order_1", []byte(strconv.Itoa(orderId)), nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
result, err := client.GetState(ctx, STATE_STORE_NAME, "order_1", nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ops := make([]*dapr.StateOperation, 0)
|
||||||
|
data1 := "data1"
|
||||||
|
data2 := "data2"
|
||||||
|
|
||||||
|
op1 := &dapr.StateOperation{
|
||||||
|
Type: dapr.StateOperationTypeUpsert,
|
||||||
|
Item: &dapr.SetStateItem{
|
||||||
|
Key: "key1",
|
||||||
|
Value: []byte(data1),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
op2 := &dapr.StateOperation{
|
||||||
|
Type: dapr.StateOperationTypeDelete,
|
||||||
|
Item: &dapr.SetStateItem{
|
||||||
|
Key: "key2",
|
||||||
|
Value: []byte(data2),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ops = append(ops, op1, op2)
|
||||||
|
meta := map[string]string{}
|
||||||
|
err = client.ExecuteStateTransaction(ctx, STATE_STORE_NAME, meta, ops)
|
||||||
|
|
||||||
|
log.Println("Result after get:", string(result.Value))
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
To launch a Dapr sidecar for the above example application, run a command similar to the following:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
dapr run --app-id orderprocessing --app-port 6001 --dapr-http-port 3601 --dapr-grpc-port 60001 go run OrderProcessingService.go
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
//dependencies
|
//dependencies
|
||||||
import { DaprClient, HttpMethod, CommunicationProtocolEnum } from '@dapr/dapr';
|
import { DaprClient, HttpMethod, CommunicationProtocolEnum } from '@dapr/dapr';
|
||||||
|
|
|
@ -42,7 +42,7 @@ dapr run -f <dir_path>
|
||||||
<!--kubernetes-->
|
<!--kubernetes-->
|
||||||
|
|
||||||
```cmd
|
```cmd
|
||||||
dapr run -f -k <dir_path>
|
dapr run -f <dir_path> -k
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ dapr run -f ./path/to/<your-preferred-file-name>.yaml
|
||||||
<!--kubernetes-->
|
<!--kubernetes-->
|
||||||
|
|
||||||
```cmd
|
```cmd
|
||||||
dapr run -f -k ./path/to/<your-preferred-file-name>.yaml
|
dapr run -f ./path/to/<your-preferred-file-name>.yaml -k
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
@ -77,10 +77,27 @@ dapr run -f -k ./path/to/<your-preferred-file-name>.yaml
|
||||||
|
|
||||||
Once the multi-app template is running, you can view the started applications with the following command:
|
Once the multi-app template is running, you can view the started applications with the following command:
|
||||||
|
|
||||||
|
{{< tabs Self-hosted Kubernetes>}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
<!--selfhosted-->
|
||||||
|
|
||||||
```cmd
|
```cmd
|
||||||
dapr list
|
dapr list
|
||||||
```
|
```
|
||||||
|
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{% codetab %}}
|
||||||
|
<!--kubernetes-->
|
||||||
|
|
||||||
|
```cmd
|
||||||
|
dapr list -k
|
||||||
|
```
|
||||||
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
{{< /tabs >}}
|
||||||
|
|
||||||
## Stop the multi-app template
|
## Stop the multi-app template
|
||||||
|
|
||||||
Stop the multi-app run template anytime with either of the following commands:
|
Stop the multi-app run template anytime with either of the following commands:
|
||||||
|
@ -109,12 +126,12 @@ dapr stop -f ./path/to/<your-preferred-file-name>.yaml
|
||||||
```cmd
|
```cmd
|
||||||
# the template file needs to be called `dapr.yaml` by default if a directory path is given
|
# the template file needs to be called `dapr.yaml` by default if a directory path is given
|
||||||
|
|
||||||
dapr stop -f -k
|
dapr stop -f <dir_path> -k
|
||||||
```
|
```
|
||||||
or:
|
or:
|
||||||
|
|
||||||
```cmd
|
```cmd
|
||||||
dapr stop -f -k ./path/to/<your-preferred-file-name>.yaml
|
dapr stop -f ./path/to/<your-preferred-file-name>.yaml -k
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
Loading…
Reference in New Issue