From 58811fae1cc90e4b4bbeeffbed8db6a56e3d4592 Mon Sep 17 00:00:00 2001 From: copy rogers <40619032+rogerogers@users.noreply.github.com> Date: Wed, 12 Oct 2022 06:16:48 +0800 Subject: [PATCH] quickstarts code fix (#2877) * quickstarts code fix Signed-off-by: rogerogers * Match quickstart readme files Signed-off-by: rogerogers Signed-off-by: rogerogers --- .../quickstarts/bindings-quickstart.md | 33 ++++++++++--------- .../quickstarts/pubsub-quickstart.md | 12 +++---- .../quickstarts/secrets-quickstart.md | 20 +++++------ .../serviceinvocation-quickstart.md | 8 ++--- .../quickstarts/statemanagement-quickstart.md | 4 +-- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md index b62d1025b..669f53e5d 100644 --- a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md @@ -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. diff --git a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md index 1c22af7dd..bde4c07c4 100644 --- a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md @@ -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 diff --git a/daprdocs/content/en/getting-started/quickstarts/secrets-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/secrets-quickstart.md index 4671f0131..13cb3dd8d 100644 --- a/daprdocs/content/en/getting-started/quickstarts/secrets-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/secrets-quickstart.md @@ -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** diff --git a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md index 0e2a7187a..f31febb77 100644 --- a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md @@ -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. diff --git a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md index 33d00aea4..096ed203a 100644 --- a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md @@ -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.