Merge pull request #2574 from hhunter-ms/quickstart_descriptions

[quickstarts] Small updates and cross-linking
This commit is contained in:
greenie-msft 2022-06-30 13:39:24 -07:00 committed by GitHub
commit 68cb6ed8ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 42 deletions

View File

@ -10,6 +10,11 @@ This guide demonstrates how to use Dapr's secrets API in your code to leverage t
<img src="/images/building-block-secrets-management-example.png" width=1000 alt="Diagram showing secrets management of example service"> <img src="/images/building-block-secrets-management-example.png" width=1000 alt="Diagram showing secrets management of example service">
{{% alert title="Note" color="primary" %}}
If you haven't already, [try out the secrets management quickstart]({{< ref secrets-quickstart.md >}}) for a quick walk-through on how to use the secrets API.
{{% /alert %}}
## Set up a secret store ## Set up a secret store
Before retrieving secrets in your application's code, you must configure a secret store component. This example configures a local secret store which uses a local JSON file to store secrets. Before retrieving secrets in your application's code, you must configure a secret store component. This example configures a local secret store which uses a local JSON file to store secrets.

View File

@ -10,7 +10,10 @@ This article demonstrates how to deploy services each with an unique application
<img src="/images/building-block-service-invocation-example.png" width=1000 height=500 alt="Diagram showing service invocation of example service"> <img src="/images/building-block-service-invocation-example.png" width=1000 height=500 alt="Diagram showing service invocation of example service">
For a complete sample demonstrating service invocation, [walk through the service invocation quickstart](https://github.com/dapr/quickstarts/tree/master/service_invocation). {{% alert title="Note" color="primary" %}}
If you haven't already, [try out the service invocation quickstart]({{< ref serviceinvocation-quickstart.md >}}) for a quick walk-through on how to use the service invocation API.
{{% /alert %}}
## Choose an ID for your service ## Choose an ID for your service

View File

@ -22,11 +22,11 @@ Hit the ground running with our Dapr quickstarts, complete with code samples aim
| Quickstarts | Description | | Quickstarts | Description |
| ----------- | ----------- | | ----------- | ----------- |
| [Service Invocation]({{< ref serviceinvocation-quickstart.md >}}) | Call a method on another service using the service invocation API. | | [Publish and Subscribe]({{< ref pubsub-quickstart.md >}}) | Asynchronous communication between two services using messaging. |
| [State Management]({{< ref statemanagement-quickstart.md >}}) | Create stateful applications using the state management API. | | [Service Invocation]({{< ref serviceinvocation-quickstart.md >}}) | Asynchronous communication between two services using HTTP. |
| [Publish and Subscribe]({{< ref pubsub-quickstart.md >}}) | Send and receive messages using the publish and subscribe API. | | [State Management]({{< ref statemanagement-quickstart.md >}}) | Store a service's data as key/value pairs in supported state stores. |
| [Bindings]({{< ref bindings-quickstart.md >}}) | Schedule a database insert job using the input and output bindings API. | | [Bindings]({{< ref bindings-quickstart.md >}}) | Work with external systems using input bindings to respond to events and output bindings to call operations. |
| [Secrets Management]({{< ref secrets-quickstart.md >}}) | Retrieve secrets in the application code from a configured secret store using the secrets management API. | | [Secrets Management]({{< ref secrets-quickstart.md >}}) | Securely fetch secrets. |
| Actors | Coming soon. | | Actors | Coming soon. |
| Observability | Coming soon. | | Observability | Coming soon. |
| Configuration | Coming soon. | | Configuration | Coming soon. |

View File

@ -100,22 +100,19 @@ The `batch-sdk` service uses the PostgreSQL output binding defined in the [`bind
```python ```python
with DaprClient() as d: with DaprClient() as d:
sqlCmd = ('insert into orders (orderid, customer, price) values' + sqlCmd = ('insert into orders (orderid, customer, price) values ' +
'(%s, \'%s\', %s)' % (order_line['orderid'], '(%s, \'%s\', %s)' % (order_line['orderid'],
order_line['customer'], order_line['customer'],
order_line['price'])) order_line['price']))
payload = {'sql': sqlCmd} payload = {'sql': sqlCmd}
print(sqlCmd, flush=True) print(sqlCmd, flush=True)
try: try:
# Insert order using Dapr output binding via HTTP Post # Insert order using Dapr output binding via HTTP Post
resp = d.invoke_binding(binding_name=sql_binding, operation='exec', resp = d.invoke_binding(binding_name=sql_binding, operation='exec',
binding_metadata=payload, data='') binding_metadata=payload, data='')
return resp return resp
except Exception as e:
print(e, flush=True)
raise SystemExit(e)
``` ```
### Step 4: View the output of the job ### Step 4: View the output of the job
@ -499,22 +496,29 @@ dapr run --app-id batch-sdk --app-port 7002 --components-path ../../../component
The code inside the `process_batch` function is executed every 10 seconds (defined in [`binding-cron.yaml`]({{< ref "#componentsbinding-cronyaml-component-file" >}}) in the `components` directory). The binding trigger looks for a route called via HTTP POST in your Flask application by the Dapr sidecar. The code inside the `process_batch` function is executed every 10 seconds (defined in [`binding-cron.yaml`]({{< ref "#componentsbinding-cronyaml-component-file" >}}) in the `components` directory). The binding trigger looks for a route called via HTTP POST in your Flask application by the Dapr sidecar.
```csharp ```csharp
Console.WriteLine("Processing batch.."); app.MapPost("/" + cronBindingName, async () => {
string jsonFile = File.ReadAllText("../../orders.json"); // ...
var ordersArray = JsonSerializer.Deserialize<Orders>(jsonFile); });
``` ```
The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgres.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgres.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table.
```csharp ```csharp
// ...
string jsonFile = File.ReadAllText("../../../orders.json");
var ordersArray = JsonSerializer.Deserialize<Orders>(jsonFile);
using var client = new DaprClientBuilder().Build(); using var client = new DaprClientBuilder().Build();
foreach(Order ord in ordersArray?.orders ?? new Order[] {}){ foreach(Order ord in ordersArray?.orders ?? new Order[] {}){
var sqlText = $"insert into orders (orderid, customer, price) values ({ord.OrderId}, '{ord.Customer}', {ord.Price});"; var sqlText = $"insert into orders (orderid, customer, price) values ({ord.OrderId}, '{ord.Customer}', {ord.Price});";
var command = new Dictionary<string,string>(){ var command = new Dictionary<string,string>(){
{"sql", {"sql",
sqlText} sqlText}
}; };
Console.WriteLine(sqlText); // ...
}
// Insert order using Dapr output binding via Dapr Client SDK
await client.InvokeBindingAsync(bindingName: sqlBindingName, operation: "exec", data: "", metadata: command);
``` ```
### Step 4: View the output of the job ### Step 4: View the output of the job
@ -905,23 +909,38 @@ dapr run --app-id batch-sdk --app-port 6002 --dapr-http-port 3502 --dapr-grpc-po
The code inside the `process_batch` function is executed every 10 seconds (defined in [`binding-cron.yaml`]({{< ref "#componentsbinding-cronyaml-component-file" >}}) in the `components` directory). The binding trigger looks for a route called via HTTP POST in your Flask application by the Dapr sidecar. The code inside the `process_batch` function is executed every 10 seconds (defined in [`binding-cron.yaml`]({{< ref "#componentsbinding-cronyaml-component-file" >}}) in the `components` directory). The binding trigger looks for a route called via HTTP POST in your Flask application by the Dapr sidecar.
```go ```go
func processCron(w http.ResponseWriter, r *http.Request) { // Triggered by Dapr input binding
fileContent, err := os.Open("../../orders.json") r.HandleFunc("/"+cronBindingName, processBatch).Methods("POST")
}
``` ```
The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgres.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgres.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table.
```go ```go
client, err := dapr.NewClient() func sqlOutput(order Order) (err error) {
// ...
sqlCmd := fmt.Sprintf("insert into orders (orderid, customer, price) values (%d, '%s', %s);", order.OrderId, order.Customer, strconv.FormatFloat(order.Price, 'f', 2, 64)) client, err := dapr.NewClient()
fmt.Println(sqlCmd) if err != nil {
in := &dapr.InvokeBindingRequest{ return err
Name: bindingName, }
Operation: "exec",
Data: []byte(""), ctx := context.Background()
Metadata: map[string]string{"sql": sqlCmd},
sqlCmd := fmt.Sprintf("insert into orders (orderid, customer, price) values (%d, '%s', %s);", order.OrderId, order.Customer, strconv.FormatFloat(order.Price, 'f', 2, 64))
fmt.Println(sqlCmd)
// Insert order using Dapr output binding via Dapr SDK
in := &dapr.InvokeBindingRequest{
Name: sqlBindingName,
Operation: "exec",
Data: []byte(""),
Metadata: map[string]string{"sql": sqlCmd},
}
err = client.InvokeOutputBinding(ctx, in)
if err != nil {
return err
}
return nil
} }
``` ```