quickstarts code fix (#2877)

* quickstarts code fix

Signed-off-by: rogerogers <rogers@rogerogers.com>

* Match quickstart readme files

Signed-off-by: rogerogers <rogers@rogerogers.com>

Signed-off-by: rogerogers <rogers@rogerogers.com>
This commit is contained in:
copy rogers 2022-10-12 06:16:48 +08:00 committed by GitHub
parent e2a216e246
commit 58811fae1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 37 deletions

View File

@ -102,19 +102,22 @@ The `batch-sdk` service uses the PostgreSQL output binding defined in the [`bind
```python
with DaprClient() as d:
sqlCmd = ('insert into orders (orderid, customer, price) values ' +
'(%s, \'%s\', %s)' % (order_line['orderid'],
order_line['customer'],
order_line['price']))
payload = {'sql': sqlCmd}
sqlCmd = ('insert into orders (orderid, customer, price) values ' +
'(%s, \'%s\', %s)' % (order_line['orderid'],
order_line['customer'],
order_line['price']))
payload = {'sql': sqlCmd}
print(sqlCmd, flush=True)
print(sqlCmd, flush=True)
try:
# Insert order using Dapr output binding via HTTP Post
resp = d.invoke_binding(binding_name=sql_binding, operation='exec',
binding_metadata=payload, data='')
return resp
try:
# Insert order using Dapr output binding via HTTP Post
resp = d.invoke_binding(binding_name=sql_binding, operation='exec',
binding_metadata=payload, data='')
return resp
except Exception as e:
print(e, flush=True)
raise SystemExit(e)
```
### Step 4: View the output of the job
@ -899,20 +902,20 @@ cd quickstarts/bindings/go/sdk/batch
Install the dependencies:
```bash
go build
go build .
```
Run the `batch-sdk` service alongside a Dapr sidecar.
```bash
dapr run --app-id batch-sdk --app-port 6002 --dapr-http-port 3502 --dapr-grpc-port 60002 --components-path ../../../components -- go run
dapr run --app-id batch-sdk --app-port 6002 --dapr-http-port 3502 --dapr-grpc-port 60002 --components-path ../../../components -- go run .
```
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
// Triggered by Dapr input binding
r.HandleFunc("/"+cronBindingName, processBatch).Methods("POST")
// Triggered by Dapr input binding
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.

View File

@ -276,7 +276,7 @@ In the `checkout` publisher service, we're publishing the orderId message to the
const client = new DaprClient(DAPR_HOST, DAPR_HTTP_PORT);
await client.pubsub.publish(PUBSUB_NAME, PUBSUB_TOPIC, order);
console.log("Published data: " + JSON.stringify(order));
console.log("Published data: " + JSON.stringify(order));
```
### Step 5: View the Pub/sub outputs
@ -700,13 +700,13 @@ cd pub_sub/go/sdk/order-processor
Install the dependencies and build the application:
```bash
go build
go build .
```
Run the `order-processor` subscriber service alongside a Dapr sidecar.
```bash
dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 --components-path ../../../components -- go run
dapr run --app-port 6002 --app-id order-processor-sdk --app-protocol http --dapr-http-port 3501 --components-path ../../../components -- go run .
```
In the `order-processor` subscriber, we're subscribing to the Redis instance called `orderpubsub` [(as defined in the `pubsub.yaml` component)]({{< ref "#pubsubyaml-component-file" >}}) and topic `orders`. This enables your app code to talk to the Redis component instance through the Dapr sidecar.
@ -730,13 +730,13 @@ cd pub_sub/go/sdk/checkout
Install the dependencies and build the application:
```bash
go build app.go
go build .
```
Run the `checkout` publisher service alongside a Dapr sidecar.
```bash
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 --components-path ../../../components -- go run app.go
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 --components-path ../../../components -- go run .
```
In the `checkout` publisher, we're publishing the orderId message to the Redis instance called `orderpubsub` [(as defined in the `pubsub.yaml` component)]({{< ref "#pubsubyaml-component-file" >}}) and topic `orders`. As soon as the service starts, it publishes in a loop:
@ -748,7 +748,7 @@ if err := client.PublishEvent(ctx, PUBSUB_NAME, PUBSUB_TOPIC, []byte(order)); er
panic(err)
}
fmt.Sprintf("Published data: ", order)
fmt.Println("Published data: ", order)
```
### Step 5: View the Pub/sub outputs

View File

@ -75,8 +75,8 @@ Notice how the `order-processor` service below points to:
DAPR_SECRET_STORE = 'localsecretstore'
SECRET_NAME = 'secret'
with DaprClient() as client:
secret = client.get_secret(store_name=DAPR_SECRET_STORE, key=SECRET_NAME)
logging.info('Fetched Secret: %s', secret.secret)
secret = client.get_secret(store_name=DAPR_SECRET_STORE, key=SECRET_NAME)
logging.info('Fetched Secret: %s', secret.secret)
```
**`local-secret-store.yaml` component**
@ -488,13 +488,13 @@ cd secrets_management/go/sdk/order-processor
Install the dependencies:
```bash
go build
go build .
```
Run the `order-processor` service alongside a Dapr sidecar.
```bash
dapr run --app-id order-processor --components-path ../../../components/ -- go run
dapr run --app-id order-processor --components-path ../../../components/ -- go run .
```
#### Behind the scenes
@ -508,12 +508,12 @@ Notice how the `order-processor` service below points to:
```go
const DAPR_SECRET_STORE = "localsecretstore"
const SECRET_NAME = "secret"
// ...
secret, err := client.GetSecret(ctx, DAPR_SECRET_STORE, SECRET_NAME, nil)
if secret != nil {
fmt.Println("Fetched Secret: ", secret[SECRET_NAME])
}
const SECRET_NAME = "secret"
// ...
secret, err := client.GetSecret(ctx, DAPR_SECRET_STORE, SECRET_NAME, nil)
if secret != nil {
fmt.Println("Fetched Secret: ", secret[SECRET_NAME])
}
```
**`local-secret-store.yaml` component**

View File

@ -535,13 +535,13 @@ cd service_invocation/go/http/order-processor
Install the dependencies:
```bash
go build app.go
go build .
```
Run the `order-processor` service alongside a Dapr sidecar.
```bash
dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- go run app.go
dapr run --app-port 6001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- go run .
```
Each order is received via an HTTP POST request and processed by the
@ -569,13 +569,13 @@ cd service_invocation/go/http/checkout
Install the dependencies:
```bash
go build app.go
go build .
```
Run the `checkout` service alongside a Dapr sidecar.
```bash
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- go run app.go
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- go run .
```
In the `checkout` service, you'll notice there's no need to rewrite your app code to use Dapr's service invocation. You can enable service invocation by simply adding the `dapr-app-id` header, which specifies the ID of the target service.

View File

@ -532,13 +532,13 @@ cd state_management/go/sdk/order-processor
Install the dependencies and build the application:
```bash
go build
go build .
```
Run the `order-processor` service alongside a Dapr sidecar.
```bash
dapr run --app-id order-processor --components-path ../../../components -- go run
dapr run --app-id order-processor --components-path ../../../components -- go run .
```
The `order-processor` service writes, reads, and deletes an `orderId` key/value pair to the `statestore` instance [defined in the `statestore.yaml` component]({{< ref "#statestoreyaml-component-file" >}}). As soon as the service starts, it performs a loop.