From 3706c74591200cfc5a8b6c5b1dcabe60127d0353 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 21 Sep 2023 11:10:13 -0400 Subject: [PATCH 1/7] add multi-app run Signed-off-by: Hannah Hunter --- .../quickstarts/pubsub-quickstart.md | 755 ++++++++++++++++++ .../serviceinvocation-quickstart.md | 674 +++++++++++++++- .../quickstarts/statemanagement-quickstart.md | 684 +++++++++++++++- 3 files changed, 2111 insertions(+), 2 deletions(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md index cb6096c519b..96dbd8bdc44 100644 --- a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md @@ -14,6 +14,761 @@ Let's take a look at Dapr's [Publish and Subscribe (Pub/sub) building block]({{< +You can try out this pub/sub quickstart by either: + +- [Running all applications in this sample simultaneously with the Multi-App Run template file]({{< ref "#run-using-multi-app-run" >}}), or +- [Running one application at a time]({{< ref "#run-one-application-at-a-time" >}}) + +## Run using Multi-App Run + +{{% alert title="Note" color="primary" %}} + [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. +{{% /alert %}} + +Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. + +{{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Python 3.7+ installed](https://www.python.org/downloads/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/pub_sub). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstarts directory, navigate into the pub/sub directory: + +```bash +cd pub_sub/python/sdk +``` + +### Step 3: Run the publisher and subscriber + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` subscriber +- The `checkout` publisher + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - checkout-sdk == Published data: Order { OrderId = 1 } +== APP - order-processor == Subscriber received : Order { OrderId = 1 } +== APP - checkout-sdk == Published data: Order { OrderId = 2 } +== APP - order-processor == Subscriber received : Order { OrderId = 2 } +== APP - checkout-sdk == Published data: Order { OrderId = 3 } +== APP - order-processor == Subscriber received : Order { OrderId = 3 } +== APP - checkout-sdk == Published data: Order { OrderId = 4 } +== APP - order-processor == Subscriber received : Order { OrderId = 4 } +== APP - checkout-sdk == Published data: Order { OrderId = 5 } +== APP - order-processor == Subscriber received : Order { OrderId = 5 } +== APP - checkout-sdk == Published data: Order { OrderId = 6 } +== APP - order-processor == Subscriber received : Order { OrderId = 6 } +== APP - checkout-sdk == Published data: Order { OrderId = 7 } +== APP - order-processor == Subscriber received : Order { OrderId = 7 } +== APP - checkout-sdk == Published data: Order { OrderId = 8 } +== APP - order-processor == Subscriber received : Order { OrderId = 8 } +== APP - checkout-sdk == Published data: Order { OrderId = 9 } +== APP - order-processor == Subscriber received : Order { OrderId = 9 } +== APP - checkout-sdk == Published data: Order { OrderId = 10 } +== APP - order-processor == Subscriber received : Order { OrderId = 10 } +Exited App successfully +``` + +### What happened? + +When you ran `dapr init` during Dapr install, the following YAML files were generated in the `.dapr/components` directory: +- [`dapr.yaml` Multi-App Run template file]({{< ref "#dapryaml-multi-app-run-template-file" >}}) +- [`pubsub.yaml` component file]({{< ref "#pubsubyaml-component-file" >}}) + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-sdk + appDirPath: ./order-processor/ + appPort: 6001 + command: ["uvicorn", "app:app"] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["python3", "app.py"] +``` + +#### `pubsub.yaml` component file + +With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. + +The Redis `pubsub.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: orderpubsub +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" +``` + +In the component YAML file: + +- `metadata/name` is how your application talks to the component. +- `spec/metadata` defines the connection to the instance of the component. +- `scopes` specify which application can use the component. + +#### `order-processor` subscriber + +In the `order-processor` subscriber, you subscribe 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. + +```py +# Register Dapr pub/sub subscriptions +@app.route('/dapr/subscribe', methods=['GET']) +def subscribe(): + subscriptions = [{ + 'pubsubname': 'orderpubsub', + 'topic': 'orders', + 'route': 'orders' + }] + print('Dapr pub/sub is subscribed to: ' + json.dumps(subscriptions)) + return jsonify(subscriptions) + + +# Dapr subscription in /dapr/subscribe sets up this route +@app.route('/orders', methods=['POST']) +def orders_subscriber(): + event = from_http(request.headers, request.get_data()) + print('Subscriber received : ' + event.data['orderid'], flush=True) + return json.dumps({'success': True}), 200, { + 'ContentType': 'application/json'} + + +app.run(port=5001) +``` + +#### `checkout` publisher + +In the `checkout` publisher, you publish 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: + +```python +with DaprClient() as client: + # Publish an event/message using Dapr PubSub + result = client.publish_event( + pubsub_name='orderpubsub', + topic_name='orders', + data=json.dumps(order), + data_content_type='application/json', + ) +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest Node.js installed](https://nodejs.org/download/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/pub_sub). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstarts directory, navigate into the pub/sub directory: + +```bash +cd pub_sub/javascript/sdk +``` + +### Step 3: Run the publisher and subscriber + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` subscriber +- The `checkout` publisher + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - checkout-sdk == Published data: Order { OrderId = 1 } +== APP - order-processor == Subscriber received : Order { OrderId = 1 } +== APP - checkout-sdk == Published data: Order { OrderId = 2 } +== APP - order-processor == Subscriber received : Order { OrderId = 2 } +== APP - checkout-sdk == Published data: Order { OrderId = 3 } +== APP - order-processor == Subscriber received : Order { OrderId = 3 } +== APP - checkout-sdk == Published data: Order { OrderId = 4 } +== APP - order-processor == Subscriber received : Order { OrderId = 4 } +== APP - checkout-sdk == Published data: Order { OrderId = 5 } +== APP - order-processor == Subscriber received : Order { OrderId = 5 } +== APP - checkout-sdk == Published data: Order { OrderId = 6 } +== APP - order-processor == Subscriber received : Order { OrderId = 6 } +== APP - checkout-sdk == Published data: Order { OrderId = 7 } +== APP - order-processor == Subscriber received : Order { OrderId = 7 } +== APP - checkout-sdk == Published data: Order { OrderId = 8 } +== APP - order-processor == Subscriber received : Order { OrderId = 8 } +== APP - checkout-sdk == Published data: Order { OrderId = 9 } +== APP - order-processor == Subscriber received : Order { OrderId = 9 } +== APP - checkout-sdk == Published data: Order { OrderId = 10 } +== APP - order-processor == Subscriber received : Order { OrderId = 10 } +Exited App successfully +``` + +### What happened? + +When you ran `dapr init` during Dapr install, the following YAML files were generated in the `.dapr/components` directory: +- [`dapr.yaml` Multi-App Run template file]({{< ref "#dapryaml-multi-app-run-template-file" >}}) +- [`pubsub.yaml` component file]({{< ref "#pubsubyaml-component-file" >}}) + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + appPort: 5002 + command: ["npm", "run", "start"] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["npm", "run", "start"] +``` + +#### `pubsub.yaml` component file + +With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. + +The Redis `pubsub.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: orderpubsub +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" +``` + +In the component YAML file: + +- `metadata/name` is how your application talks to the component. +- `spec/metadata` defines the connection to the instance of the component. +- `scopes` specify which application can use the component. + +#### `order-processor` subscriber + +In the `order-processor` subscriber, you subscribe 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. + +```js +server.pubsub.subscribe("orderpubsub", "orders", (data) => console.log("Subscriber received: " + JSON.stringify(data))); +``` + +#### `checkout` publisher + +In the `checkout` publisher service, you publish 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: + +```js +const client = new DaprClient(); + +await client.pubsub.publish(PUBSUB_NAME, PUBSUB_TOPIC, order); +console.log("Published data: " + JSON.stringify(order)); +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [.NET SDK or .NET 6 SDK installed](https://dotnet.microsoft.com/download). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/pub_sub). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstarts directory, navigate into the pub/sub directory: + +```bash +cd pub_sub/csharp/sdk +``` + +### Step 3: Run the publisher and subscriber + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` subscriber +- The `checkout` publisher + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - checkout-sdk == Published data: Order { OrderId = 1 } +== APP - order-processor == Subscriber received : Order { OrderId = 1 } +== APP - checkout-sdk == Published data: Order { OrderId = 2 } +== APP - order-processor == Subscriber received : Order { OrderId = 2 } +== APP - checkout-sdk == Published data: Order { OrderId = 3 } +== APP - order-processor == Subscriber received : Order { OrderId = 3 } +== APP - checkout-sdk == Published data: Order { OrderId = 4 } +== APP - order-processor == Subscriber received : Order { OrderId = 4 } +== APP - checkout-sdk == Published data: Order { OrderId = 5 } +== APP - order-processor == Subscriber received : Order { OrderId = 5 } +== APP - checkout-sdk == Published data: Order { OrderId = 6 } +== APP - order-processor == Subscriber received : Order { OrderId = 6 } +== APP - checkout-sdk == Published data: Order { OrderId = 7 } +== APP - order-processor == Subscriber received : Order { OrderId = 7 } +== APP - checkout-sdk == Published data: Order { OrderId = 8 } +== APP - order-processor == Subscriber received : Order { OrderId = 8 } +== APP - checkout-sdk == Published data: Order { OrderId = 9 } +== APP - order-processor == Subscriber received : Order { OrderId = 9 } +== APP - checkout-sdk == Published data: Order { OrderId = 10 } +== APP - order-processor == Subscriber received : Order { OrderId = 10 } +Exited App successfully +``` + +### What happened? + +When you ran `dapr init` during Dapr install, the following YAML files were generated in the `.dapr/components` directory: +- [`dapr.yaml` Multi-App Run template file]({{< ref "#dapryaml-multi-app-run-template-file" >}}) +- [`pubsub.yaml` component file]({{< ref "#pubsubyaml-component-file" >}}) + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + appPort: 7006 + command: ["dotnet", "run"] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["dotnet", "run"] +``` + +#### `pubsub.yaml` component file + +With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. + +The Redis `pubsub.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: orderpubsub +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" +``` + +In the component YAML file: + +- `metadata/name` is how your application talks to the component. +- `spec/metadata` defines the connection to the instance of the component. +- `scopes` specify which application can use the component. + +#### `order-processor` subscriber + +In the `order-processor` subscriber, you subscribe 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. + +```cs +// Dapr subscription in [Topic] routes orders topic to this route +app.MapPost("/orders", [Topic("orderpubsub", "orders")] (Order order) => { + Console.WriteLine("Subscriber received : " + order); + return Results.Ok(order); +}); + +public record Order([property: JsonPropertyName("orderId")] int OrderId); +``` + +#### `checkout` publisher + +In the `checkout` publisher, you publish 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: + +```cs +using var client = new DaprClientBuilder().Build(); +await client.PublishEventAsync("orderpubsub", "orders", order); +Console.WriteLine("Published data: " + order); +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- Java JDK 11 (or greater): + - [Oracle JDK](https://www.oracle.com/java/technologies/downloads), or + - OpenJDK +- [Apache Maven](https://maven.apache.org/install.html), version 3.x. + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/pub_sub). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstarts directory, navigate into the pub/sub directory: + +```bash +cd pub_sub/java/sdk +``` + +### Step 3: Run the publisher and subscriber + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` subscriber +- The `checkout` publisher + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - checkout-sdk == Published data: Order { OrderId = 1 } +== APP - order-processor == Subscriber received : Order { OrderId = 1 } +== APP - checkout-sdk == Published data: Order { OrderId = 2 } +== APP - order-processor == Subscriber received : Order { OrderId = 2 } +== APP - checkout-sdk == Published data: Order { OrderId = 3 } +== APP - order-processor == Subscriber received : Order { OrderId = 3 } +== APP - checkout-sdk == Published data: Order { OrderId = 4 } +== APP - order-processor == Subscriber received : Order { OrderId = 4 } +== APP - checkout-sdk == Published data: Order { OrderId = 5 } +== APP - order-processor == Subscriber received : Order { OrderId = 5 } +== APP - checkout-sdk == Published data: Order { OrderId = 6 } +== APP - order-processor == Subscriber received : Order { OrderId = 6 } +== APP - checkout-sdk == Published data: Order { OrderId = 7 } +== APP - order-processor == Subscriber received : Order { OrderId = 7 } +== APP - checkout-sdk == Published data: Order { OrderId = 8 } +== APP - order-processor == Subscriber received : Order { OrderId = 8 } +== APP - checkout-sdk == Published data: Order { OrderId = 9 } +== APP - order-processor == Subscriber received : Order { OrderId = 9 } +== APP - checkout-sdk == Published data: Order { OrderId = 10 } +== APP - order-processor == Subscriber received : Order { OrderId = 10 } +Exited App successfully +``` + +### What happened? + +When you ran `dapr init` during Dapr install, the following YAML files were generated in the `.dapr/components` directory: +- [`dapr.yaml` Multi-App Run template file]({{< ref "#dapryaml-multi-app-run-template-file" >}}) +- [`pubsub.yaml` component file]({{< ref "#pubsubyaml-component-file" >}}) + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor-sdk + appDirPath: ./order-processor/target/ + appPort: 8080 + command: ["java", "-jar", "OrderProcessingService-0.0.1-SNAPSHOT.jar"] + - appID: checkout-sdk + appDirPath: ./checkout/target/ + command: ["java", "-jar", "CheckoutService-0.0.1-SNAPSHOT.jar"] +``` + +#### `pubsub.yaml` component file + +With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. + +The Redis `pubsub.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: orderpubsub +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" +``` + +In the component YAML file: + +- `metadata/name` is how your application talks to the component. +- `spec/metadata` defines the connection to the instance of the component. +- `scopes` specify which application can use the component. + +#### `order-processor` subscriber + +In the `order-processor` subscriber, you subscribe 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. + +```java +@Topic(name = "orders", pubsubName = "orderpubsub") +@PostMapping(path = "/orders", consumes = MediaType.ALL_VALUE) +public Mono getCheckout(@RequestBody(required = false) CloudEvent cloudEvent) { + return Mono.fromSupplier(() -> { + try { + logger.info("Subscriber received: " + cloudEvent.getData().getOrderId()); + return ResponseEntity.ok("SUCCESS"); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); +} +``` + +#### `checkout` publisher + +In the `checkout` publisher, you publish 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: + +```java +DaprClient client = new DaprClientBuilder().build(); +client.publishEvent( + PUBSUB_NAME, + TOPIC_NAME, + order).block(); +logger.info("Published data: " + order.getOrderId()); +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest version of Go](https://go.dev/dl/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/pub_sub). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstarts directory, navigate into the pub/sub directory: + +```bash +cd pub_sub/go/sdk +``` + +### Step 3: Run the publisher and subscriber + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` subscriber +- The `checkout` publisher + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - checkout-sdk == Published data: Order { OrderId = 1 } +== APP - order-processor == Subscriber received : Order { OrderId = 1 } +== APP - checkout-sdk == Published data: Order { OrderId = 2 } +== APP - order-processor == Subscriber received : Order { OrderId = 2 } +== APP - checkout-sdk == Published data: Order { OrderId = 3 } +== APP - order-processor == Subscriber received : Order { OrderId = 3 } +== APP - checkout-sdk == Published data: Order { OrderId = 4 } +== APP - order-processor == Subscriber received : Order { OrderId = 4 } +== APP - checkout-sdk == Published data: Order { OrderId = 5 } +== APP - order-processor == Subscriber received : Order { OrderId = 5 } +== APP - checkout-sdk == Published data: Order { OrderId = 6 } +== APP - order-processor == Subscriber received : Order { OrderId = 6 } +== APP - checkout-sdk == Published data: Order { OrderId = 7 } +== APP - order-processor == Subscriber received : Order { OrderId = 7 } +== APP - checkout-sdk == Published data: Order { OrderId = 8 } +== APP - order-processor == Subscriber received : Order { OrderId = 8 } +== APP - checkout-sdk == Published data: Order { OrderId = 9 } +== APP - order-processor == Subscriber received : Order { OrderId = 9 } +== APP - checkout-sdk == Published data: Order { OrderId = 10 } +== APP - order-processor == Subscriber received : Order { OrderId = 10 } +Exited App successfully +``` + +### What happened? + +When you ran `dapr init` during Dapr install, the following YAML files were generated in the `.dapr/components` directory: +- [`dapr.yaml` Multi-App Run template file]({{< ref "#dapryaml-multi-app-run-template-file" >}}) +- [`pubsub.yaml` component file]({{< ref "#pubsubyaml-component-file" >}}) + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../components/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + appPort: 6005 + command: ["go", "run", "."] + - appID: checkout-sdk + appDirPath: ./checkout/ + command: ["go", "run", "."] +``` + +#### `pubsub.yaml` component file + +With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. + +The Redis `pubsub.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: orderpubsub +spec: + type: pubsub.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" +``` + +In the component YAML file: + +- `metadata/name` is how your application talks to the component. +- `spec/metadata` defines the connection to the instance of the component. +- `scopes` specify which application can use the component. + +#### `order-processor` subscriber + +In the `order-processor` subscriber, you subscribe 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. + +```go +func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) { + fmt.Println("Subscriber received: ", e.Data) + return false, nil +} +``` + +#### `checkout` publisher + +In the `checkout` publisher, you publish 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: + +```go +client, err := dapr.NewClient() + +if err := client.PublishEvent(ctx, PUBSUB_NAME, PUBSUB_TOPIC, []byte(order)); err != nil { + panic(err) +} + +fmt.Println("Published data: ", order) +``` + +{{% /codetab %}} + +{{< /tabs >}} + +## Run one application at a time + Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} diff --git a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md index fc61df703cf..bd866aa2478 100644 --- a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md @@ -10,10 +10,682 @@ With [Dapr's Service Invocation building block](https://docs.dapr.io/developing- Diagram showing the steps of service invocation -Dapr offers several methods for service invocation, which you can choose depending on your scenario. For this Quickstart, you'll enable the checkout service to invoke a method using HTTP proxy in the order-processor service. +Dapr offers several methods for service invocation, which you can choose depending on your scenario. For this Quickstart, you'll enable the checkout service to invoke a method using HTTP proxy in the order-processor service and by either: +- [Running all applications in this sample simultaneously with the Multi-App Run template file]({{< ref "#run-using-multi-app-run" >}}), or +- [Running one application at a time]({{< ref "#run-one-application-at-a-time" >}}) Learn more about Dapr's methods for service invocation in the [overview article]({{< ref service-invocation-overview.md >}}). +## Run using Multi-App Run + +{{% alert title="Note" color="primary" %}} + [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. +{{% /alert %}} + +Select your preferred language before proceeding with the Quickstart. + +{{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Python 3.7+ installed](https://www.python.org/downloads/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/service_invocation). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstart clone directory, navigate to the quickstart directory. + +```bash +cd service_invocation/python/http +``` + +### Step 3: Run the `order-processor` and `checkout` services + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` service +- The `checkout` service + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - order-processor == Order received : Order { orderId = 1 } +== APP - checkout == Order passed: Order { OrderId = 1 } +== APP - order-processor == Order received : Order { orderId = 2 } +== APP - checkout == Order passed: Order { OrderId = 2 } +== APP - order-processor == Order received : Order { orderId = 3 } +== APP - checkout == Order passed: Order { OrderId = 3 } +== APP - order-processor == Order received : Order { orderId = 4 } +== APP - checkout == Order passed: Order { OrderId = 4 } +== APP - order-processor == Order received : Order { orderId = 5 } +== APP - checkout == Order passed: Order { OrderId = 5 } +== APP - order-processor == Order received : Order { orderId = 6 } +== APP - checkout == Order passed: Order { OrderId = 6 } +== APP - order-processor == Order received : Order { orderId = 7 } +== APP - checkout == Order passed: Order { OrderId = 7 } +== APP - order-processor == Order received : Order { orderId = 8 } +== APP - checkout == Order passed: Order { OrderId = 8 } +== APP - order-processor == Order received : Order { orderId = 9 } +== APP - checkout == Order passed: Order { OrderId = 9 } +== APP - order-processor == Order received : Order { orderId = 10 } +== APP - checkout == Order passed: Order { OrderId = 10 } +== APP - order-processor == Order received : Order { orderId = 11 } +== APP - checkout == Order passed: Order { OrderId = 11 } +== APP - order-processor == Order received : Order { orderId = 12 } +== APP - checkout == Order passed: Order { OrderId = 12 } +== APP - order-processor == Order received : Order { orderId = 13 } +== APP - checkout == Order passed: Order { OrderId = 13 } +== APP - order-processor == Order received : Order { orderId = 14 } +== APP - checkout == Order passed: Order { OrderId = 14 } +== APP - order-processor == Order received : Order { orderId = 15 } +== APP - checkout == Order passed: Order { OrderId = 15 } +== APP - order-processor == Order received : Order { orderId = 16 } +== APP - checkout == Order passed: Order { OrderId = 16 } +== APP - order-processor == Order received : Order { orderId = 17 } +== APP - checkout == Order passed: Order { OrderId = 17 } +== APP - order-processor == Order received : Order { orderId = 18 } +== APP - checkout == Order passed: Order { OrderId = 18 } +== APP - order-processor == Order received : Order { orderId = 19 } +== APP - checkout == Order passed: Order { OrderId = 19 } +== APP - order-processor == Order received : Order { orderId = 20 } +== APP - checkout == Order passed: Order { OrderId = 20 } +Exited App successfully +``` + +### What happened? + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +apps: + - appDirPath: ./order-processor/ + appID: order-processor + appPort: 8001 + command: ["python3", "app.py"] + - appID: checkout + appDirPath: ./checkout/ + command: ["python3", "app.py"] +``` + +#### `order-processor` service + +The `order-processor` service receives the call from the `checkout` service: + +```py +@app.route('/orders', methods=['POST']) +def getOrder(): + data = request.json + print('Order received : ' + json.dumps(data), flush=True) + return json.dumps({'success': True}), 200, { + 'ContentType': 'application/json'} + + +app.run(port=8001) +``` + +#### `checkout` service + +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. + +```python +headers = {'dapr-app-id': 'order-processor'} + +result = requests.post( + url='%s/orders' % (base_url), + data=json.dumps(order), + headers=headers +) +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest Node.js installed](https://nodejs.org/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/service_invocation). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstart clone directory, navigate to the quickstart directory. + +```bash +cd service_invocation/javascript/http +``` + +### Step 3: Run the `order-processor` and `checkout` services + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` service +- The `checkout` service + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - order-processor == Order received : Order { orderId = 1 } +== APP - checkout == Order passed: Order { OrderId = 1 } +== APP - order-processor == Order received : Order { orderId = 2 } +== APP - checkout == Order passed: Order { OrderId = 2 } +== APP - order-processor == Order received : Order { orderId = 3 } +== APP - checkout == Order passed: Order { OrderId = 3 } +== APP - order-processor == Order received : Order { orderId = 4 } +== APP - checkout == Order passed: Order { OrderId = 4 } +== APP - order-processor == Order received : Order { orderId = 5 } +== APP - checkout == Order passed: Order { OrderId = 5 } +== APP - order-processor == Order received : Order { orderId = 6 } +== APP - checkout == Order passed: Order { OrderId = 6 } +== APP - order-processor == Order received : Order { orderId = 7 } +== APP - checkout == Order passed: Order { OrderId = 7 } +== APP - order-processor == Order received : Order { orderId = 8 } +== APP - checkout == Order passed: Order { OrderId = 8 } +== APP - order-processor == Order received : Order { orderId = 9 } +== APP - checkout == Order passed: Order { OrderId = 9 } +== APP - order-processor == Order received : Order { orderId = 10 } +== APP - checkout == Order passed: Order { OrderId = 10 } +== APP - order-processor == Order received : Order { orderId = 11 } +== APP - checkout == Order passed: Order { OrderId = 11 } +== APP - order-processor == Order received : Order { orderId = 12 } +== APP - checkout == Order passed: Order { OrderId = 12 } +== APP - order-processor == Order received : Order { orderId = 13 } +== APP - checkout == Order passed: Order { OrderId = 13 } +== APP - order-processor == Order received : Order { orderId = 14 } +== APP - checkout == Order passed: Order { OrderId = 14 } +== APP - order-processor == Order received : Order { orderId = 15 } +== APP - checkout == Order passed: Order { OrderId = 15 } +== APP - order-processor == Order received : Order { orderId = 16 } +== APP - checkout == Order passed: Order { OrderId = 16 } +== APP - order-processor == Order received : Order { orderId = 17 } +== APP - checkout == Order passed: Order { OrderId = 17 } +== APP - order-processor == Order received : Order { orderId = 18 } +== APP - checkout == Order passed: Order { OrderId = 18 } +== APP - order-processor == Order received : Order { orderId = 19 } +== APP - checkout == Order passed: Order { OrderId = 19 } +== APP - order-processor == Order received : Order { orderId = 20 } +== APP - checkout == Order passed: Order { OrderId = 20 } +Exited App successfully +``` + +### What happened? + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +apps: + - appDirPath: ./order-processor/ + appID: order-processor + appPort: 5001 + command: ["npm", "start"] + - appID: checkout + appDirPath: ./checkout/ + command: ["npm", "start"] +``` + +#### `order-processor` service + +The `order-processor` service receives the call from the `checkout` service: + +```javascript +app.post('/orders', (req, res) => { + console.log("Order received:", req.body); + res.sendStatus(200); +}); +``` + +#### `checkout` service + +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. + +```javascript +let axiosConfig = { + headers: { + "dapr-app-id": "order-processor" + } +}; +const res = await axios.post(`${DAPR_HOST}:${DAPR_HTTP_PORT}/orders`, order , axiosConfig); +console.log("Order passed: " + res.config.data); +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [.NET SDK or .NET 7 SDK installed](https://dotnet.microsoft.com/download). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/service_invocation). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstart clone directory, navigate to the quickstart directory. + +```bash +cd service_invocation/csharp/http +``` + +### Step 3: Run the `order-processor` and `checkout` services + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` service +- The `checkout` service + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - order-processor == Order received : Order { orderId = 1 } +== APP - checkout == Order passed: Order { OrderId = 1 } +== APP - order-processor == Order received : Order { orderId = 2 } +== APP - checkout == Order passed: Order { OrderId = 2 } +== APP - order-processor == Order received : Order { orderId = 3 } +== APP - checkout == Order passed: Order { OrderId = 3 } +== APP - order-processor == Order received : Order { orderId = 4 } +== APP - checkout == Order passed: Order { OrderId = 4 } +== APP - order-processor == Order received : Order { orderId = 5 } +== APP - checkout == Order passed: Order { OrderId = 5 } +== APP - order-processor == Order received : Order { orderId = 6 } +== APP - checkout == Order passed: Order { OrderId = 6 } +== APP - order-processor == Order received : Order { orderId = 7 } +== APP - checkout == Order passed: Order { OrderId = 7 } +== APP - order-processor == Order received : Order { orderId = 8 } +== APP - checkout == Order passed: Order { OrderId = 8 } +== APP - order-processor == Order received : Order { orderId = 9 } +== APP - checkout == Order passed: Order { OrderId = 9 } +== APP - order-processor == Order received : Order { orderId = 10 } +== APP - checkout == Order passed: Order { OrderId = 10 } +== APP - order-processor == Order received : Order { orderId = 11 } +== APP - checkout == Order passed: Order { OrderId = 11 } +== APP - order-processor == Order received : Order { orderId = 12 } +== APP - checkout == Order passed: Order { OrderId = 12 } +== APP - order-processor == Order received : Order { orderId = 13 } +== APP - checkout == Order passed: Order { OrderId = 13 } +== APP - order-processor == Order received : Order { orderId = 14 } +== APP - checkout == Order passed: Order { OrderId = 14 } +== APP - order-processor == Order received : Order { orderId = 15 } +== APP - checkout == Order passed: Order { OrderId = 15 } +== APP - order-processor == Order received : Order { orderId = 16 } +== APP - checkout == Order passed: Order { OrderId = 16 } +== APP - order-processor == Order received : Order { orderId = 17 } +== APP - checkout == Order passed: Order { OrderId = 17 } +== APP - order-processor == Order received : Order { orderId = 18 } +== APP - checkout == Order passed: Order { OrderId = 18 } +== APP - order-processor == Order received : Order { orderId = 19 } +== APP - checkout == Order passed: Order { OrderId = 19 } +== APP - order-processor == Order received : Order { orderId = 20 } +== APP - checkout == Order passed: Order { OrderId = 20 } +Exited App successfully +``` + +### What happened? + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +apps: + - appDirPath: ./order-processor/ + appID: order-processor + appPort: 7001 + command: ["dotnet", "run"] + - appID: checkout + appDirPath: ./checkout/ + command: ["dotnet", "run"] +``` + +#### `order-processor` service + +The `order-processor` service receives the call from the `checkout` service: + +```csharp +app.MapPost("/orders", (Order order) => +{ + Console.WriteLine("Order received : " + order); + return order.ToString(); +}); +``` + +#### `checkout` service + +In the Program.cs file for 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. + +```csharp +var client = new HttpClient(); +client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); + +client.DefaultRequestHeaders.Add("dapr-app-id", "order-processor"); + +var response = await client.PostAsync($"{baseURL}/orders", content); + Console.WriteLine("Order passed: " + order); +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- Java JDK 11 (or greater): + - [Oracle JDK](https://www.oracle.com/java/technologies/downloads), or + - OpenJDK +- [Apache Maven](https://maven.apache.org/install.html), version 3.x. + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/service_invocation). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstart clone directory, navigate to the quickstart directory. + +```bash +cd service_invocation/java/http +``` + +### Step 3: Run the `order-processor` and `checkout` services + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` service +- The `checkout` service + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - order-processor == Order received : Order { orderId = 1 } +== APP - checkout == Order passed: Order { OrderId = 1 } +== APP - order-processor == Order received : Order { orderId = 2 } +== APP - checkout == Order passed: Order { OrderId = 2 } +== APP - order-processor == Order received : Order { orderId = 3 } +== APP - checkout == Order passed: Order { OrderId = 3 } +== APP - order-processor == Order received : Order { orderId = 4 } +== APP - checkout == Order passed: Order { OrderId = 4 } +== APP - order-processor == Order received : Order { orderId = 5 } +== APP - checkout == Order passed: Order { OrderId = 5 } +== APP - order-processor == Order received : Order { orderId = 6 } +== APP - checkout == Order passed: Order { OrderId = 6 } +== APP - order-processor == Order received : Order { orderId = 7 } +== APP - checkout == Order passed: Order { OrderId = 7 } +== APP - order-processor == Order received : Order { orderId = 8 } +== APP - checkout == Order passed: Order { OrderId = 8 } +== APP - order-processor == Order received : Order { orderId = 9 } +== APP - checkout == Order passed: Order { OrderId = 9 } +== APP - order-processor == Order received : Order { orderId = 10 } +== APP - checkout == Order passed: Order { OrderId = 10 } +== APP - order-processor == Order received : Order { orderId = 11 } +== APP - checkout == Order passed: Order { OrderId = 11 } +== APP - order-processor == Order received : Order { orderId = 12 } +== APP - checkout == Order passed: Order { OrderId = 12 } +== APP - order-processor == Order received : Order { orderId = 13 } +== APP - checkout == Order passed: Order { OrderId = 13 } +== APP - order-processor == Order received : Order { orderId = 14 } +== APP - checkout == Order passed: Order { OrderId = 14 } +== APP - order-processor == Order received : Order { orderId = 15 } +== APP - checkout == Order passed: Order { OrderId = 15 } +== APP - order-processor == Order received : Order { orderId = 16 } +== APP - checkout == Order passed: Order { OrderId = 16 } +== APP - order-processor == Order received : Order { orderId = 17 } +== APP - checkout == Order passed: Order { OrderId = 17 } +== APP - order-processor == Order received : Order { orderId = 18 } +== APP - checkout == Order passed: Order { OrderId = 18 } +== APP - order-processor == Order received : Order { orderId = 19 } +== APP - checkout == Order passed: Order { OrderId = 19 } +== APP - order-processor == Order received : Order { orderId = 20 } +== APP - checkout == Order passed: Order { OrderId = 20 } +Exited App successfully +``` + +### What happened? + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +apps: + - appDirPath: ./order-processor/ + appID: order-processor + appPort: 9001 + command: ["java", "-jar", "target/OrderProcessingService-0.0.1-SNAPSHOT.jar"] + - appID: checkout + appDirPath: ./checkout/ + command: ["java", "-jar", "target/CheckoutService-0.0.1-SNAPSHOT.jar"] +``` + +#### `order-processor` service + +The `order-processor` service receives the call from the `checkout` service: + +```java +public String processOrders(@RequestBody Order body) { + System.out.println("Order received: "+ body.getOrderId()); + return "CID" + body.getOrderId(); + } +``` + +#### `checkout` service + +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. + +```java +.header("Content-Type", "application/json") +.header("dapr-app-id", "order-processor") + +HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println("Order passed: "+ orderId) +``` + +{{% /codetab %}} + + +{{% codetab %}} + +### Step 1: Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest version of Go](https://go.dev/dl/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 2: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/service_invocation). + + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +From the root of the Quickstart clone directory, navigate to the quickstart directory. + +```bash +cd service_invocation/go/http +``` + +### Step 3: Run the `order-processor` and `checkout` services + +With the following command, simultaneously run the following services alongside their own Dapr sidecars: +- The `order-processor` service +- The `checkout` service + +```bash +dapr run -f . +``` + +**Expected output** + +``` +== APP - order-processor == Order received : Order { orderId = 1 } +== APP - checkout == Order passed: Order { OrderId = 1 } +== APP - order-processor == Order received : Order { orderId = 2 } +== APP - checkout == Order passed: Order { OrderId = 2 } +== APP - order-processor == Order received : Order { orderId = 3 } +== APP - checkout == Order passed: Order { OrderId = 3 } +== APP - order-processor == Order received : Order { orderId = 4 } +== APP - checkout == Order passed: Order { OrderId = 4 } +== APP - order-processor == Order received : Order { orderId = 5 } +== APP - checkout == Order passed: Order { OrderId = 5 } +== APP - order-processor == Order received : Order { orderId = 6 } +== APP - checkout == Order passed: Order { OrderId = 6 } +== APP - order-processor == Order received : Order { orderId = 7 } +== APP - checkout == Order passed: Order { OrderId = 7 } +== APP - order-processor == Order received : Order { orderId = 8 } +== APP - checkout == Order passed: Order { OrderId = 8 } +== APP - order-processor == Order received : Order { orderId = 9 } +== APP - checkout == Order passed: Order { OrderId = 9 } +== APP - order-processor == Order received : Order { orderId = 10 } +== APP - checkout == Order passed: Order { OrderId = 10 } +== APP - order-processor == Order received : Order { orderId = 11 } +== APP - checkout == Order passed: Order { OrderId = 11 } +== APP - order-processor == Order received : Order { orderId = 12 } +== APP - checkout == Order passed: Order { OrderId = 12 } +== APP - order-processor == Order received : Order { orderId = 13 } +== APP - checkout == Order passed: Order { OrderId = 13 } +== APP - order-processor == Order received : Order { orderId = 14 } +== APP - checkout == Order passed: Order { OrderId = 14 } +== APP - order-processor == Order received : Order { orderId = 15 } +== APP - checkout == Order passed: Order { OrderId = 15 } +== APP - order-processor == Order received : Order { orderId = 16 } +== APP - checkout == Order passed: Order { OrderId = 16 } +== APP - order-processor == Order received : Order { orderId = 17 } +== APP - checkout == Order passed: Order { OrderId = 17 } +== APP - order-processor == Order received : Order { orderId = 18 } +== APP - checkout == Order passed: Order { OrderId = 18 } +== APP - order-processor == Order received : Order { orderId = 19 } +== APP - checkout == Order passed: Order { OrderId = 19 } +== APP - order-processor == Order received : Order { orderId = 20 } +== APP - checkout == Order passed: Order { OrderId = 20 } +Exited App successfully +``` + +### What happened? + +Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. + +#### `dapr.yaml` Multi-App Run template file + +Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: + +```yml +version: 1 +apps: + - appDirPath: ./order-processor/ + appID: order-processor + appPort: 6006 + command: ["go", "run", "."] + - appID: checkout + appDirPath: ./checkout/ + command: ["go", "run", "."] +``` + +#### `order-processor` service + +In the `order-processor` service, each order is received via an HTTP POST request and processed by the `getOrder` function. + +```go +func getOrder(w http.ResponseWriter, r *http.Request) { + data, err := ioutil.ReadAll(r.Body) + if err != nil { + log.Fatal(err) + } + log.Printf("Order received : %s", string(data)) +} +``` + +#### `checkout` service + +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. + +```go +req.Header.Add("dapr-app-id", "order-processor") + +response, err := client.Do(req) +``` + +{{% /codetab %}} + +{{% /tabs %}} + +## Run one application at a time + Select your preferred language before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} diff --git a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md index f73aa37f494..7c80c4c2304 100644 --- a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md @@ -6,10 +6,692 @@ weight: 72 description: "Get started with Dapr's State Management building block" --- -Let's take a look at Dapr's [State Management building block]({{< ref state-management >}}). In this Quickstart, you will save, get, and delete state using a Redis state store, but you can swap this out for any one of the [supported state stores]({{< ref supported-state-stores.md >}}). +Let's take a look at Dapr's [State Management building block]({{< ref state-management >}}). In this Quickstart, you will save, get, and delete state using a Redis state store by either: +- [Running all applications simultaneously with the Multi-App Run template file]({{< ref "#run-using-multi-app-run" >}}), or +- [Running a single application at a time]({{< ref "#run-one-application-at-a-time" >}}) +While this sample uses Redis, you can swap it out for any one of the [supported state stores]({{< ref supported-state-stores.md >}}). + +## Run using Multi-App Run + +{{% alert title="Note" color="primary" %}} + [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. +{{% /alert %}} + +Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. + +{{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Python 3.7+ installed](https://www.python.org/downloads/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/state_management). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Manipulate service state + +In a terminal window, navigate to the `order-processor` directory. + +```bash +cd state_management/python/sdk/order-processor +``` + +Install the dependencies: + +```bash +pip3 install -r requirements.txt +``` + +Run the `order-processor` service alongside a Dapr sidecar using [Multi-App Run]({{< ref multi-app-dapr-run >}}). + +```bash +dapr run -f +``` + +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. + +```python +with DaprClient() as client: + + # Save state into the state store + client.save_state(DAPR_STORE_NAME, orderId, str(order)) + logging.info('Saving Order: %s', order) + + # Get state from the state store + result = client.get_state(DAPR_STORE_NAME, orderId) + logging.info('Result after get: ' + str(result.data)) + + # Delete state from the state store + client.delete_state(store_name=DAPR_STORE_NAME, key=orderId) + logging.info('Deleting Order: %s', order) +``` + +### Step 3: View the order-processor outputs + +Notice, as specified in the code above, the code saves application state in the Dapr state store, reads it, then deletes it. + +Order-processor output: +``` +== APP == INFO:root:Saving Order: {'orderId': '1'} +== APP == INFO:root:Result after get: b"{'orderId': '1'}" +== APP == INFO:root:Deleting Order: {'orderId': '1'} +== APP == INFO:root:Saving Order: {'orderId': '2'} +== APP == INFO:root:Result after get: b"{'orderId': '2'}" +== APP == INFO:root:Deleting Order: {'orderId': '2'} +== APP == INFO:root:Saving Order: {'orderId': '3'} +== APP == INFO:root:Result after get: b"{'orderId': '3'}" +== APP == INFO:root:Deleting Order: {'orderId': '3'} +== APP == INFO:root:Saving Order: {'orderId': '4'} +== APP == INFO:root:Result after get: b"{'orderId': '4'}" +== APP == INFO:root:Deleting Order: {'orderId': '4'} +``` + +#### `dapr.yaml` Multi-App Run template file + +When you run `dapr init`, Dapr creates a default [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../../resources/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + command: ["dotnet", "run"] +``` + +#### `statestore.yaml` component file + +When you run `dapr init`, Dapr also creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: + +- On Windows, under `%UserProfile%\.dapr\components\statestore.yaml` +- On Linux/MacOS, under `~/.dapr/components/statestore.yaml` + +With the `statestore.yaml` component, you can easily swap out the [state store](/reference/components-reference/supported-state-stores/) without making code changes. + +The Redis `statestore.yaml` file included for this quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" + - name: actorStateStore + value: "true" +``` + +In the YAML file: + +- `metadata/name` is how your application talks to the component (called `DAPR_STORE_NAME` in the code sample). +- `spec/metadata` defines the connection to the Redis instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest Node.js installed](https://nodejs.org/download/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/state_management). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Manipulate service state + +In a terminal window, navigate to the `order-processor` directory. + +```bash +cd state_management/javascript/sdk/order-processor +``` + +Install dependencies, which will include the `@dapr/dapr` package from the JavaScript SDK: + +```bash +npm install +``` + +Verify you have the following files included in the service directory: + +- `package.json` +- `package-lock.json` + +Run the `order-processor` service alongside a Dapr sidecar. + +```bash +dapr run -f +``` + +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. + +```js +const client = new DaprClient() + +// Save state into a state store +await client.state.save(DAPR_STATE_STORE_NAME, order) +console.log("Saving Order: ", order) + +// Get state from a state store +const savedOrder = await client.state.get(DAPR_STATE_STORE_NAME, order.orderId) +console.log("Getting Order: ", savedOrder) + +// Delete state from the state store +await client.state.delete(DAPR_STATE_STORE_NAME, order.orderId) +console.log("Deleting Order: ", order) +``` +### Step 3: View the order-processor outputs + +Notice, as specified in the code above, the code saves application state in the Dapr state store, reads it, then deletes it. + +Order-processor output: +``` +== APP == > order-processor@1.0.0 start +== APP == > node index.js +== APP == Saving Order: { orderId: 1 } +== APP == Saving Order: { orderId: 2 } +== APP == Saving Order: { orderId: 3 } +== APP == Saving Order: { orderId: 4 } +== APP == Saving Order: { orderId: 5 } +== APP == Getting Order: { orderId: 1 } +== APP == Deleting Order: { orderId: 1 } +== APP == Getting Order: { orderId: 2 } +== APP == Deleting Order: { orderId: 2 } +== APP == Getting Order: { orderId: 3 } +== APP == Deleting Order: { orderId: 3 } +== APP == Getting Order: { orderId: 4 } +== APP == Deleting Order: { orderId: 4 } +== APP == Getting Order: { orderId: 5 } +== APP == Deleting Order: { orderId: 5 } +``` + +#### `dapr.yaml` Multi-App Run template file + +When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../../resources/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + command: ["dotnet", "run"] +``` + +#### `statestore.yaml` component file + +When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: + +- On Windows, under `%UserProfile%\.dapr\components\statestore.yaml` +- On Linux/MacOS, under `~/.dapr/components/statestore.yaml` + +With the `statestore.yaml` component, you can easily swap out the [state store](/reference/components-reference/supported-state-stores/) without making code changes. + +The Redis `statestore.yaml` file included for this quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" + - name: actorStateStore + value: "true" +``` + +In the YAML file: + +- `metadata/name` is how your application talks to the component (called `DAPR_STORE_NAME` in the code sample). +- `spec/metadata` defines the connection to the Redis instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [.NET SDK or .NET 6 SDK installed](https://dotnet.microsoft.com/download). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/state_management). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Manipulate service state + +In a terminal window, navigate to the `order-processor` directory. + +```bash +cd state_management/csharp/sdk/order-processor +``` + +Recall NuGet packages: + +```bash +dotnet restore +dotnet build +``` + +Run the `order-processor` service alongside a Dapr sidecar. + +```bash +dapr run -f +``` + +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. + +```cs +var client = new DaprClientBuilder().Build(); + +// Save state into the state store +await client.SaveStateAsync(DAPR_STORE_NAME, orderId.ToString(), order.ToString()); +Console.WriteLine("Saving Order: " + order); + +// Get state from the state store +var result = await client.GetStateAsync(DAPR_STORE_NAME, orderId.ToString()); +Console.WriteLine("Getting Order: " + result); + +// Delete state from the state store +await client.DeleteStateAsync(DAPR_STORE_NAME, orderId.ToString()); +Console.WriteLine("Deleting Order: " + order); +``` +### Step 3: View the order-processor outputs + +Notice, as specified in the code above, the code saves application state in the Dapr state store, reads it, then deletes it. + +Order-processor output: +``` +== APP == Saving Order: Order { orderId = 1 } +== APP == Getting Order: Order { orderId = 1 } +== APP == Deleting Order: Order { orderId = 1 } +== APP == Saving Order: Order { orderId = 2 } +== APP == Getting Order: Order { orderId = 2 } +== APP == Deleting Order: Order { orderId = 2 } +== APP == Saving Order: Order { orderId = 3 } +== APP == Getting Order: Order { orderId = 3 } +== APP == Deleting Order: Order { orderId = 3 } +== APP == Saving Order: Order { orderId = 4 } +== APP == Getting Order: Order { orderId = 4 } +== APP == Deleting Order: Order { orderId = 4 } +== APP == Saving Order: Order { orderId = 5 } +== APP == Getting Order: Order { orderId = 5 } +== APP == Deleting Order: Order { orderId = 5 } +``` + +#### `dapr.yaml` Multi-App Run template file + +When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../../resources/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + command: ["dotnet", "run"] +``` + +#### `statestore.yaml` component file + +When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: + +- On Windows, under `%UserProfile%\.dapr\components\statestore.yaml` +- On Linux/MacOS, under `~/.dapr/components/statestore.yaml` + +With the `statestore.yaml` component, you can easily swap out the [state store](/reference/components-reference/supported-state-stores/) without making code changes. + +The Redis `statestore.yaml` file included for this quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" + - name: actorStateStore + value: "true" +``` + +In the YAML file: + +- `metadata/name` is how your application talks to the component (called `DAPR_STORE_NAME` in the code sample). +- `spec/metadata` defines the connection to the Redis instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- Java JDK 11 (or greater): + - [Oracle JDK](https://www.oracle.com/java/technologies/downloads), or + - OpenJDK +- [Apache Maven](https://maven.apache.org/install.html), version 3.x. + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/state_management). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Manipulate service state + +In a terminal window, navigate to the `order-processor` directory. + +```bash +cd state_management/java/sdk/order-processor +``` + +Install the dependencies: + +```bash +mvn clean install +``` + +Run the `order-processor` service alongside a Dapr sidecar. + +```bash +dapr run -f +``` + +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. + +```java +try (DaprClient client = new DaprClientBuilder().build()) { + for (int i = 1; i <= 10; i++) { + int orderId = i; + Order order = new Order(); + order.setOrderId(orderId); + + // Save state into the state store + client.saveState(DAPR_STATE_STORE, String.valueOf(orderId), order).block(); + LOGGER.info("Saving Order: " + order.getOrderId()); + + // Get state from the state store + State response = client.getState(DAPR_STATE_STORE, String.valueOf(orderId), Order.class).block(); + LOGGER.info("Getting Order: " + response.getValue().getOrderId()); + + // Delete state from the state store + client.deleteState(DAPR_STATE_STORE, String.valueOf(orderId)).block(); + LOGGER.info("Deleting Order: " + orderId); + TimeUnit.MILLISECONDS.sleep(1000); + } +``` +### Step 3: View the order-processor outputs + +Notice, as specified in the code above, the code saves application state in the Dapr state store, reads it, then deletes it. + +Order-processor output: +``` +== APP == INFO:root:Saving Order: {'orderId': '1'} +== APP == INFO:root:Result after get: b"{'orderId': '1'}" +== APP == INFO:root:Deleting Order: {'orderId': '1'} +== APP == INFO:root:Saving Order: {'orderId': '2'} +== APP == INFO:root:Result after get: b"{'orderId': '2'}" +== APP == INFO:root:Deleting Order: {'orderId': '2'} +== APP == INFO:root:Saving Order: {'orderId': '3'} +== APP == INFO:root:Result after get: b"{'orderId': '3'}" +== APP == INFO:root:Deleting Order: {'orderId': '3'} +== APP == INFO:root:Saving Order: {'orderId': '4'} +== APP == INFO:root:Result after get: b"{'orderId': '4'}" +== APP == INFO:root:Deleting Order: {'orderId': '4'} +``` + +#### `dapr.yaml` Multi-App Run template file + +When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../../resources/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + command: ["dotnet", "run"] +``` + +#### `statestore.yaml` component file + +When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: + +- On Windows, under `%UserProfile%\.dapr\components\statestore.yaml` +- On Linux/MacOS, under `~/.dapr/components/statestore.yaml` + +With the `statestore.yaml` component, you can easily swap out the [state store](/reference/components-reference/supported-state-stores/) without making code changes. + +The Redis `statestore.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" + - name: actorStateStore + value: "true" +``` + +In the YAML file: + +- `metadata/name` is how your application talks to the component (called `DAPR_STORE_NAME` in the code sample). +- `spec/metadata` defines the connection to the Redis instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest version of Go](https://go.dev/dl/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/state_management). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Manipulate service state + +In a terminal window, navigate to the `order-processor` directory. + +```bash +cd state_management/go/sdk/order-processor +``` + +Install the dependencies and build the application: + +```bash +go build . +``` + +Run the `order-processor` service alongside a Dapr sidecar. + +```bash +dapr run -f +``` + +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. + +```go + client, err := dapr.NewClient() + + // Save state into the state store + _ = client.SaveState(ctx, STATE_STORE_NAME, strconv.Itoa(orderId), []byte(order)) + log.Print("Saving Order: " + string(order)) + + // Get state from the state store + result, _ := client.GetState(ctx, STATE_STORE_NAME, strconv.Itoa(orderId)) + fmt.Println("Getting Order: " + string(result.Value)) + + // Delete state from the state store + _ = client.DeleteState(ctx, STATE_STORE_NAME, strconv.Itoa(orderId)) + log.Print("Deleting Order: " + string(order)) +``` + +### Step 3: View the order-processor outputs + +Notice, as specified in the code above, the code saves application state in the Dapr state store, reads it, then deletes it. + +Order-processor output: +``` +== APP == dapr client initializing for: 127.0.0.1:53689 +== APP == 2022/04/01 09:16:03 Saving Order: {"orderId":1} +== APP == Getting Order: {"orderId":1} +== APP == 2022/04/01 09:16:03 Deleting Order: {"orderId":1} +== APP == 2022/04/01 09:16:03 Saving Order: {"orderId":2} +== APP == Getting Order: {"orderId":2} +== APP == 2022/04/01 09:16:03 Deleting Order: {"orderId":2} +== APP == 2022/04/01 09:16:03 Saving Order: {"orderId":3} +== APP == Getting Order: {"orderId":3} +== APP == 2022/04/01 09:16:03 Deleting Order: {"orderId":3} +== APP == 2022/04/01 09:16:03 Saving Order: {"orderId":4} +== APP == Getting Order: {"orderId":4} +== APP == 2022/04/01 09:16:03 Deleting Order: {"orderId":4} +== APP == 2022/04/01 09:16:03 Saving Order: {"orderId":5} +== APP == Getting Order: {"orderId":5} +== APP == 2022/04/01 09:16:03 Deleting Order: {"orderId":5} +``` + +#### `dapr.yaml` Multi-App Run template file + +When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: + +```yml +version: 1 +common: + resourcesPath: ../../../resources/ +apps: + - appID: order-processor + appDirPath: ./order-processor/ + command: ["dotnet", "run"] +``` + +#### `statestore.yaml` component file + +When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: + +- On Windows, under `%UserProfile%\.dapr\components\statestore.yaml` +- On Linux/MacOS, under `~/.dapr/components/statestore.yaml` + +With the `statestore.yaml` component, you can easily swap out the [state store](/reference/components-reference/supported-state-stores/) without making code changes. + +The Redis `statestore.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: localhost:6379 + - name: redisPassword + value: "" + - name: actorStateStore + value: "true" +``` + +In the YAML file: + +- `metadata/name` is how your application talks to the component (called `DAPR_STORE_NAME` in the code sample). +- `spec/metadata` defines the connection to the Redis instance used by the component. + +{{% /codetab %}} + +{{< /tabs >}} + + +## Run one application at a time + Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} From 821ca0fb08306b8a9ec3905256646e59b9ddff8d Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 21 Sep 2023 11:16:40 -0400 Subject: [PATCH 2/7] update headings Signed-off-by: Hannah Hunter --- .../quickstarts/pubsub-quickstart.md | 50 +++++++++---------- .../serviceinvocation-quickstart.md | 28 +++++------ .../quickstarts/statemanagement-quickstart.md | 30 +++++------ 3 files changed, 54 insertions(+), 54 deletions(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md index 96dbd8bdc44..3581606d0a4 100644 --- a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md @@ -99,7 +99,7 @@ When you ran `dapr init` during Dapr install, the following YAML files were gene Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -117,7 +117,7 @@ apps: command: ["python3", "app.py"] ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. @@ -144,7 +144,7 @@ In the component YAML file: - `spec/metadata` defines the connection to the instance of the component. - `scopes` specify which application can use the component. -#### `order-processor` subscriber +##### `order-processor` subscriber In the `order-processor` subscriber, you subscribe 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. @@ -173,7 +173,7 @@ def orders_subscriber(): app.run(port=5001) ``` -#### `checkout` publisher +##### `checkout` publisher In the `checkout` publisher, you publish 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: @@ -261,7 +261,7 @@ When you ran `dapr init` during Dapr install, the following YAML files were gene Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -279,7 +279,7 @@ apps: command: ["npm", "run", "start"] ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. @@ -306,7 +306,7 @@ In the component YAML file: - `spec/metadata` defines the connection to the instance of the component. - `scopes` specify which application can use the component. -#### `order-processor` subscriber +##### `order-processor` subscriber In the `order-processor` subscriber, you subscribe 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. @@ -314,7 +314,7 @@ In the `order-processor` subscriber, you subscribe to the Redis instance called server.pubsub.subscribe("orderpubsub", "orders", (data) => console.log("Subscriber received: " + JSON.stringify(data))); ``` -#### `checkout` publisher +##### `checkout` publisher In the `checkout` publisher service, you publish 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: @@ -398,7 +398,7 @@ When you ran `dapr init` during Dapr install, the following YAML files were gene Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -416,7 +416,7 @@ apps: command: ["dotnet", "run"] ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. @@ -443,7 +443,7 @@ In the component YAML file: - `spec/metadata` defines the connection to the instance of the component. - `scopes` specify which application can use the component. -#### `order-processor` subscriber +##### `order-processor` subscriber In the `order-processor` subscriber, you subscribe 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. @@ -457,7 +457,7 @@ app.MapPost("/orders", [Topic("orderpubsub", "orders")] (Order order) => { public record Order([property: JsonPropertyName("orderId")] int OrderId); ``` -#### `checkout` publisher +##### `checkout` publisher In the `checkout` publisher, you publish 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: @@ -543,7 +543,7 @@ When you ran `dapr init` during Dapr install, the following YAML files were gene Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -561,7 +561,7 @@ apps: command: ["java", "-jar", "CheckoutService-0.0.1-SNAPSHOT.jar"] ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. @@ -588,7 +588,7 @@ In the component YAML file: - `spec/metadata` defines the connection to the instance of the component. - `scopes` specify which application can use the component. -#### `order-processor` subscriber +##### `order-processor` subscriber In the `order-processor` subscriber, you subscribe 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. @@ -607,7 +607,7 @@ public Mono getCheckout(@RequestBody(required = false) CloudEven } ``` -#### `checkout` publisher +##### `checkout` publisher In the `checkout` publisher, you publish 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: @@ -693,7 +693,7 @@ When you ran `dapr init` during Dapr install, the following YAML files were gene Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-subscriber" >}}) and [publisher]({{< ref "#checkout-publisher" >}}) applications. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -711,7 +711,7 @@ apps: command: ["go", "run", "."] ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file With the `pubsub.yaml` component, you can easily swap out underlying components without application code changes. @@ -738,7 +738,7 @@ In the component YAML file: - `spec/metadata` defines the connection to the instance of the component. - `scopes` specify which application can use the component. -#### `order-processor` subscriber +##### `order-processor` subscriber In the `order-processor` subscriber, you subscribe 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. @@ -749,7 +749,7 @@ func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err er } ``` -#### `checkout` publisher +##### `checkout` publisher In the `checkout` publisher, you publish 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: @@ -912,7 +912,7 @@ Subscriber output: == APP == INFO:root:Subscriber received: {"orderId": 10} ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file When you run `dapr init`, Dapr creates a default Redis `pubsub.yaml` and runs a Redis container on your local machine, located: @@ -1070,7 +1070,7 @@ Subscriber output: ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file When you run `dapr init`, Dapr creates a default Redis `pubsub.yaml` and runs a Redis container on your local machine, located: @@ -1223,7 +1223,7 @@ Subscriber output: == APP == Subscriber received: Order { OrderId = 10 } ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file When you run `dapr init`, Dapr creates a default Redis `pubsub.yaml` and runs a Redis container on your local machine, located: @@ -1385,7 +1385,7 @@ Subscriber output: == APP == 2022-03-07 13:31:37.919 INFO 43512 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 10 ``` -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file When you run `dapr init`, Dapr creates a default Redis `pubsub.yaml` and runs a Redis container on your local machine, located: @@ -1543,7 +1543,7 @@ Subscriber output: Note: the order in which they are received may vary. -#### `pubsub.yaml` component file +##### `pubsub.yaml` component file When you run `dapr init`, Dapr creates a default Redis `pubsub.yaml` and runs a Redis container on your local machine, located: diff --git a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md index bd866aa2478..08014b5e10b 100644 --- a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md @@ -112,7 +112,7 @@ Exited App successfully Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -128,7 +128,7 @@ apps: command: ["python3", "app.py"] ``` -#### `order-processor` service +##### `order-processor` service The `order-processor` service receives the call from the `checkout` service: @@ -247,7 +247,7 @@ Exited App successfully Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -263,7 +263,7 @@ apps: command: ["npm", "start"] ``` -#### `order-processor` service +##### `order-processor` service The `order-processor` service receives the call from the `checkout` service: @@ -274,7 +274,7 @@ app.post('/orders', (req, res) => { }); ``` -#### `checkout` service +##### `checkout` service 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. @@ -377,7 +377,7 @@ Exited App successfully Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -393,7 +393,7 @@ apps: command: ["dotnet", "run"] ``` -#### `order-processor` service +##### `order-processor` service The `order-processor` service receives the call from the `checkout` service: @@ -405,7 +405,7 @@ app.MapPost("/orders", (Order order) => }); ``` -#### `checkout` service +##### `checkout` service In the Program.cs file for 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. @@ -511,7 +511,7 @@ Exited App successfully Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -527,7 +527,7 @@ apps: command: ["java", "-jar", "target/CheckoutService-0.0.1-SNAPSHOT.jar"] ``` -#### `order-processor` service +##### `order-processor` service The `order-processor` service receives the call from the `checkout` service: @@ -538,7 +538,7 @@ public String processOrders(@RequestBody Order body) { } ``` -#### `checkout` service +##### `checkout` service 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. @@ -640,7 +640,7 @@ Exited App successfully Running `dapr run -f .` in this Quickstart started both the [subscriber]({{< ref "#order-processor-service" >}}) and [publisher]({{< ref "#checkout-service" >}}) applications using the `dapr.yaml` Multi-App Run template file. -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file Running the [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) with `dapr run -f .` starts all applications in your project. In this Quickstart, the `dapr.yaml` file contains the following: @@ -656,7 +656,7 @@ apps: command: ["go", "run", "."] ``` -#### `order-processor` service +##### `order-processor` service In the `order-processor` service, each order is received via an HTTP POST request and processed by the `getOrder` function. @@ -670,7 +670,7 @@ func getOrder(w http.ResponseWriter, r *http.Request) { } ``` -#### `checkout` service +##### `checkout` service 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 7c80c4c2304..e360c660076 100644 --- a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md @@ -102,7 +102,7 @@ Order-processor output: == APP == INFO:root:Deleting Order: {'orderId': '4'} ``` -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file When you run `dapr init`, Dapr creates a default [Multi-App Run template file]({{< ref multi-app-dapr-run >}}) named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: @@ -116,7 +116,7 @@ apps: command: ["dotnet", "run"] ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr also creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -239,7 +239,7 @@ Order-processor output: == APP == Deleting Order: { orderId: 5 } ``` -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: @@ -253,7 +253,7 @@ apps: command: ["dotnet", "run"] ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -370,7 +370,7 @@ Order-processor output: == APP == Deleting Order: Order { orderId = 5 } ``` -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: @@ -384,7 +384,7 @@ apps: command: ["dotnet", "run"] ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -506,7 +506,7 @@ Order-processor output: == APP == INFO:root:Deleting Order: {'orderId': '4'} ``` -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: @@ -520,7 +520,7 @@ apps: command: ["dotnet", "run"] ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -638,7 +638,7 @@ Order-processor output: == APP == 2022/04/01 09:16:03 Deleting Order: {"orderId":5} ``` -#### `dapr.yaml` Multi-App Run template file +##### `dapr.yaml` Multi-App Run template file When you run `dapr init`, Dapr creates a default Multi-App Run template file named `dapr.yaml`. Running `dapr run -f` starts all applications in your project. In this sample, the `dapr.yaml` file contains the following: @@ -652,7 +652,7 @@ apps: command: ["dotnet", "run"] ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -776,7 +776,7 @@ Order-processor output: == APP == INFO:root:Deleting Order: {'orderId': '4'} ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -898,7 +898,7 @@ Order-processor output: == APP == Deleting Order: { orderId: 5 } ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -1015,7 +1015,7 @@ Order-processor output: == APP == Deleting Order: Order { orderId = 5 } ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -1137,7 +1137,7 @@ Order-processor output: == APP == INFO:root:Deleting Order: {'orderId': '4'} ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: @@ -1255,7 +1255,7 @@ Order-processor output: == APP == 2022/04/01 09:16:03 Deleting Order: {"orderId":5} ``` -#### `statestore.yaml` component file +##### `statestore.yaml` component file When you run `dapr init`, Dapr creates a default Redis `statestore.yaml` and runs a Redis container on your local machine, located: From eecadf3de60b50ef2861eb5045a889ec3ac3ae1a Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Thu, 21 Sep 2023 11:24:42 -0400 Subject: [PATCH 3/7] start bindings quickstart ahead of changes Signed-off-by: Hannah Hunter --- .../quickstarts/bindings-quickstart.md | 1072 ++++++++++++++++- 1 file changed, 1071 insertions(+), 1 deletion(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md index b818c434836..64731de6852 100644 --- a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md @@ -11,10 +11,1080 @@ Let's take a look at Dapr's [Bindings building block]({{< ref bindings >}}). Usi - Trigger your app with events coming in from external systems. - Interface with external systems. -In this Quickstart, you will schedule a batch script to run every 10 seconds using an input [Cron]({{< ref cron.md >}}) binding. The script processes a JSON file and outputs data to a SQL database using the [PostgreSQL]({{< ref postgresql.md >}}) Dapr binding. +In this Quickstart, you will schedule a batch script to run every 10 seconds using an input [Cron]({{< ref cron.md >}}) binding. The script processes a JSON file and outputs data to a SQL database using the [PostgreSQL]({{< ref postgresql.md >}}) Dapr binding. You can run this quickstart by either: +- [Running all applications in this sample simultaneously with the Multi-App Run template file]({{< ref "#run-using-multi-app-run" >}}), or +- [Running one application at a time]({{< ref "#run-one-application-at-a-time" >}}) +## Run using Multi-App Run + +{{% alert title="Note" color="primary" %}} + [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. +{{% /alert %}} + +Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. + +{{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Python 3.7+ installed](https://www.python.org/downloads/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Run PostgreSQL Docker container locally + +Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. + +In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following command to set up the container: + +```bash +docker compose up +``` + +Verify that the container is running locally. + +```bash +docker ps +``` + +The output should include: + +```bash +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db +``` + +### Step 3: Schedule a Cron job and write to the database + +In a new terminal window, navigate to the SDK directory. + +```bash +cd bindings/python/sdk/batch +``` + +Install the dependencies: + +```bash +pip3 install -r requirements.txt +``` + +Run the `batch-sdk` service alongside a Dapr sidecar. + +```bash +dapr run --app-id batch-sdk --app-port 50051 --resources-path ../../../components -- python3 app.py +``` + +> **Note**: Since Python3.exe is not defined in Windows, you may need to use `python app.py` instead of `python3 app.py`. + +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 application by the Dapr sidecar. + +```python +# Triggered by Dapr input binding +@app.route('/' + cron_binding_name, methods=['POST']) +def process_batch(): +``` + +The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. + +```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} + + 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 + except Exception as e: + print(e, flush=True) + raise SystemExit(e) +``` + +### Step 4: View the output of the job + +Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. + +Your output binding's `print` statement output: + +``` +== APP == Processing batch.. +== APP == insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32) +== APP == insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4) +== APP == insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56) +== APP == Finished processing batch +``` + +In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following to start the interactive *psql* CLI: + +```bash +docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password +``` + +At the `admin=#` prompt, change to the `orders` table: + +```bash +\c orders; +``` + +At the `orders=#` prompt, select all rows: + +```bash +select * from orders; +``` + +The output should look like this: + +``` + orderid | customer | price +---------+------------+-------- + 1 | John Smith | 100.32 + 2 | Jane Bond | 15.4 + 3 | Tony James | 35.56 +``` + +#### `components\binding-cron.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the Cron [binding building block]({{< ref bindings >}}) +- Calls the binding endpoint (`batch`) every 10 seconds + +The Cron `binding-cron.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: cron + namespace: quickstarts +spec: + type: bindings.cron + version: v1 + 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. + +#### `component\binding-postgresql.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) +- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file + +With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. + +The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: sqldb + namespace: quickstarts +spec: + type: bindings.postgresql + version: v1 + 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: + +- `spec/type` specifies that PostgreSQL is used for this binding. +- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest Node.js installed](https://nodejs.org/download/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Run PostgreSQL Docker container locally + +Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. + +In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following command to set up the container: + +```bash +docker compose up +``` + +Verify that the container is running locally. + +```bash +docker ps +``` + +The output should include: + +```bash +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db +``` + +### Step 3: Schedule a Cron job and write to the database + +In a new terminal window, navigate to the SDK directory. + +```bash +cd bindings/javascript/sdk/batch +``` + +Install the dependencies: + +```bash +npm install +``` + +Run the `batch-sdk` service alongside a Dapr sidecar. + +```bash +dapr run --app-id batch-sdk --app-port 5002 --dapr-http-port 3500 --resources-path ../../../components -- node index.js +``` + +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 application by the Dapr sidecar. + +```javascript +async function start() { + await server.binding.receive(cronBindingName,processBatch); + await server.start(); +} +``` + +The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "##componentsbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. + +```javascript +async function processBatch(){ + const loc = '../../orders.json'; + fs.readFile(loc, 'utf8', (err, data) => { + const orders = JSON.parse(data).orders; + orders.forEach(order => { + let sqlCmd = `insert into orders (orderid, customer, price) values (${order.orderid}, '${order.customer}', ${order.price});`; + let payload = `{ "sql": "${sqlCmd}" } `; + console.log(payload); + client.binding.send(postgresBindingName, "exec", "", JSON.parse(payload)); + }); + console.log('Finished processing batch'); + }); + return 0; +} +``` + +### Step 4: View the output of the job + +Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. + +Your output binding's `print` statement output: + +``` +== APP == Processing batch.. +== APP == insert into orders (orderid, customer, price) values(1, 'John Smith', 100.32) +== APP == insert into orders (orderid, customer, price) values(2, 'Jane Bond', 15.4) +== APP == insert into orders (orderid, customer, price) values(3, 'Tony James', 35.56) +``` + +In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following to start the interactive Postgres CLI: + +```bash +docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password +``` + +At the `admin=#` prompt, change to the `orders` table: + +```bash +\c orders; +``` + +At the `orders=#` prompt, select all rows: + +```bash +select * from orders; +``` + +The output should look like this: + +``` + orderid | customer | price +---------+------------+-------- + 1 | John Smith | 100.32 + 2 | Jane Bond | 15.4 + 3 | Tony James | 35.56 +``` + +#### `components\binding-cron.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the Cron [binding building block]({{< ref bindings >}}) +- Calls the binding endpoint (`batch`) every 10 seconds + +The Cron `binding-cron.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: cron + namespace: quickstarts +spec: + type: bindings.cron + version: v1 + 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. + +#### `component\binding-postgresql.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) +- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file + +With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. + +The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: sqldb + namespace: quickstarts +spec: + type: bindings.postgresql + version: v1 + 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: + +- `spec/type` specifies that PostgreSQL is used for this binding. +- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [.NET SDK or .NET 6 SDK installed](https://dotnet.microsoft.com/download). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Run PostgreSQL Docker container locally + +Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. + +In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following command to set up the container: + +```bash +docker compose up +``` + +Verify that the container is running locally. + +```bash +docker ps +``` + +The output should include: + +```bash +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db +``` + +### Step 3: Schedule a Cron job and write to the database + +In a new terminal window, navigate to the SDK directory. + +```bash +cd bindings/csharp/sdk/batch +``` + +Install the dependencies: + +```bash +dotnet restore +dotnet build batch.csproj +``` + +Run the `batch-sdk` service alongside a Dapr sidecar. + +```bash +dapr run --app-id batch-sdk --app-port 7002 --resources-path ../../../components -- dotnet 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 application by the Dapr sidecar. + +```csharp +app.MapPost("/" + cronBindingName, async () => { +// ... +}); +``` + +The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. + +```csharp +// ... +string jsonFile = File.ReadAllText("../../../orders.json"); +var ordersArray = JsonSerializer.Deserialize(jsonFile); +using var client = new DaprClientBuilder().Build(); +foreach(Order ord in ordersArray?.orders ?? new Order[] {}){ + var sqlText = $"insert into orders (orderid, customer, price) values ({ord.OrderId}, '{ord.Customer}', {ord.Price});"; + var command = new Dictionary(){ + {"sql", + 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 + +Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. + +Your output binding's `print` statement output: + +``` +== APP == Processing batch.. +== APP == insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32); +== APP == insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4); +== APP == insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56); +== APP == Finished processing batch +``` + +In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following to start the interactive Postgres CLI: + +```bash +docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password +``` + +At the `admin=#` prompt, change to the `orders` table: + +```bash +\c orders; +``` + +At the `orders=#` prompt, select all rows: + +```bash +select * from orders; +``` + +The output should look like this: + +``` + orderid | customer | price +---------+------------+-------- + 1 | John Smith | 100.32 + 2 | Jane Bond | 15.4 + 3 | Tony James | 35.56 +``` + +#### `components\binding-cron.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the Cron [binding building block]({{< ref bindings >}}) +- Calls the binding endpoint (`batch`) every 10 seconds + +The Cron `binding-cron.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: cron + namespace: quickstarts +spec: + type: bindings.cron + version: v1 + 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. + +#### `component\binding-postgresql.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) +- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file + +With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. + +The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: sqldb + namespace: quickstarts +spec: + type: bindings.postgresql + version: v1 + 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: + +- `spec/type` specifies that PostgreSQL is used for this binding. +- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- Java JDK 11 (or greater): + - [Oracle JDK](https://www.oracle.com/java/technologies/downloads), or + - OpenJDK +- [Apache Maven](https://maven.apache.org/install.html), version 3.x. + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Run PostgreSQL Docker container locally + +Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. + +In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following command to set up the container: + +```bash +docker compose up +``` + +Verify that the container is running locally. + +```bash +docker ps +``` + +The output should include: + +```bash +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db +``` + +### Step 3: Schedule a Cron job and write to the database + +In a new terminal window, navigate to the SDK directory. + +```bash +cd bindings/java/sdk/batch +``` + +Install the dependencies: + +```bash +mvn clean install +``` + +Run the `batch-sdk` service alongside a Dapr sidecar. + +```bash +dapr run --app-id batch-sdk --app-port 8080 --resources-path ../../../components -- java -jar target/BatchProcessingService-0.0.1-SNAPSHOT.jar +``` + +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 application by the Dapr sidecar. + +```java +@PostMapping(path = cronBindingPath, consumes = MediaType.ALL_VALUE) +public ResponseEntity processBatch() throws IOException, Exception +``` + +The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. + +```java +try (DaprClient client = new DaprClientBuilder().build()) { + + for (Order order : ordList.orders) { + String sqlText = String.format( + "insert into orders (orderid, customer, price) " + + "values (%s, '%s', %s);", + order.orderid, order.customer, order.price); + logger.info(sqlText); + + Map metadata = new HashMap(); + metadata.put("sql", sqlText); + + // Invoke sql output binding using Dapr SDK + client.invokeBinding(sqlBindingName, "exec", null, metadata).block(); + } + + logger.info("Finished processing batch"); + + return ResponseEntity.ok("Finished processing batch"); +} +``` + +### Step 4: View the output of the job + +Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. + +Your output binding's `print` statement output: + +``` +== APP == 2022-06-22 16:39:17.012 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : Processing batch.. +== APP == 2022-06-22 16:39:17.268 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32); +== APP == 2022-06-22 16:39:17.838 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4); +== APP == 2022-06-22 16:39:17.844 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56); +== APP == 2022-06-22 16:39:17.848 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : Finished processing batch +``` + +In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following to start the interactive Postgres CLI: + +```bash +docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password +``` + +At the `admin=#` prompt, change to the `orders` table: + +```bash +\c orders; +``` + +At the `orders=#` prompt, select all rows: + +```bash +select * from orders; +``` + +The output should look like this: + +``` + orderid | customer | price +---------+------------+-------- + 1 | John Smith | 100.32 + 2 | Jane Bond | 15.4 + 3 | Tony James | 35.56 +``` + +#### `components\binding-cron.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the Cron [binding building block]({{< ref bindings >}}) +- Calls the binding endpoint (`batch`) every 10 seconds + +The Cron `binding-cron.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: cron + namespace: quickstarts +spec: + type: bindings.cron + version: v1 + 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. + +#### `component\binding-postgresql.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) +- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file + +With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. + +The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: sqldb + namespace: quickstarts +spec: + type: bindings.postgresql + version: v1 + 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: + +- `spec/type` specifies that PostgreSQL is used for this binding. +- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. + +{{% /codetab %}} + + +{{% codetab %}} + +### Pre-requisites + +For this example, you will need: + +- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). +- [Latest version of Go](https://go.dev/dl/). + +- [Docker Desktop](https://www.docker.com/products/docker-desktop) + + +### Step 1: Set up the environment + +Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). + +```bash +git clone https://github.com/dapr/quickstarts.git +``` + +### Step 2: Run PostgreSQL Docker container locally + +Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. + +In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following command to set up the container: + +```bash +docker compose up +``` + +Verify that the container is running locally. + +```bash +docker ps +``` + +The output should include: + +```bash +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db +``` + +### Step 3: Schedule a Cron job and write to the database + +In a new terminal window, navigate to the SDK directory. + +```bash +cd bindings/go/sdk/batch +``` + +Install the dependencies: + +```bash +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 --resources-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 application by the Dapr sidecar. + +```go +// Triggered by Dapr input binding +r.HandleFunc("/"+cronBindingName, processBatch).Methods("POST") +``` + +The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. + +```go +func sqlOutput(order Order) (err error) { + + client, err := dapr.NewClient() + if err != nil { + return err + } + + ctx := context.Background() + + 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 +} +``` + +### Step 4: View the output of the job + +Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. + +Your output binding's `print` statement output: + +``` +== APP == Processing batch.. +== APP == insert into orders (orderid, customer, price) values(1, 'John Smith', 100.32) +== APP == insert into orders (orderid, customer, price) values(2, 'Jane Bond', 15.4) +== APP == insert into orders (orderid, customer, price) values(3, 'Tony James', 35.56) +``` + +In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. + +```bash +cd bindings/db +``` + +Run the following to start the interactive Postgres CLI: + +```bash +docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password +``` + +At the `admin=#` prompt, change to the `orders` table: + +```bash +\c orders; +``` + +At the `orders=#` prompt, select all rows: + +```bash +select * from orders; +``` + +The output should look like this: + +``` + orderid | customer | price +---------+------------+-------- + 1 | John Smith | 100.32 + 2 | Jane Bond | 15.4 + 3 | Tony James | 35.56 +``` + +#### `components\binding-cron.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the Cron [binding building block]({{< ref bindings >}}) +- Calls the binding endpoint (`batch`) every 10 seconds + +The Cron `binding-cron.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: cron + namespace: quickstarts +spec: + type: bindings.cron + version: v1 + 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. + +#### `component\binding-postgresql.yaml` component file + +When you execute the `dapr run` command and specify the component path, the Dapr sidecar: + +- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) +- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file + +With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. + +The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: + +```yaml +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: sqldb + namespace: quickstarts +spec: + type: bindings.postgresql + version: v1 + 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: + +- `spec/type` specifies that PostgreSQL is used for this binding. +- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. + +{{% /codetab %}} + +{{< /tabs >}} + +## Run one application at a time + Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} From 3af5b954bf0226cea8d5cec88aeda39cba8aed85 Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 22 Sep 2023 18:38:08 -0400 Subject: [PATCH 4/7] remove bindings quickstart changes for now and preview alerts Signed-off-by: Hannah Hunter --- .../quickstarts/bindings-quickstart.md | 1072 +---------------- .../quickstarts/pubsub-quickstart.md | 4 - .../serviceinvocation-quickstart.md | 4 - .../quickstarts/statemanagement-quickstart.md | 4 - 4 files changed, 1 insertion(+), 1083 deletions(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md index 64731de6852..22c56afe25b 100644 --- a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md @@ -11,1080 +11,10 @@ Let's take a look at Dapr's [Bindings building block]({{< ref bindings >}}). Usi - Trigger your app with events coming in from external systems. - Interface with external systems. -In this Quickstart, you will schedule a batch script to run every 10 seconds using an input [Cron]({{< ref cron.md >}}) binding. The script processes a JSON file and outputs data to a SQL database using the [PostgreSQL]({{< ref postgresql.md >}}) Dapr binding. You can run this quickstart by either: -- [Running all applications in this sample simultaneously with the Multi-App Run template file]({{< ref "#run-using-multi-app-run" >}}), or -- [Running one application at a time]({{< ref "#run-one-application-at-a-time" >}}) +In this Quickstart, you will schedule a batch script to run every 10 seconds using an input [Cron]({{< ref cron.md >}}) binding. The script processes a JSON file and outputs data to a SQL database using the [PostgreSQL]({{< ref postgresql.md >}}) Dapr binding. -## Run using Multi-App Run - -{{% alert title="Note" color="primary" %}} - [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. -{{% /alert %}} - -Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. - -{{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} - -{{% codetab %}} - -### Pre-requisites - -For this example, you will need: - -- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). -- [Python 3.7+ installed](https://www.python.org/downloads/). - -- [Docker Desktop](https://www.docker.com/products/docker-desktop) - - -### Step 1: Set up the environment - -Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). - -```bash -git clone https://github.com/dapr/quickstarts.git -``` - -### Step 2: Run PostgreSQL Docker container locally - -Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. - -In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following command to set up the container: - -```bash -docker compose up -``` - -Verify that the container is running locally. - -```bash -docker ps -``` - -The output should include: - -```bash -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db -``` - -### Step 3: Schedule a Cron job and write to the database - -In a new terminal window, navigate to the SDK directory. - -```bash -cd bindings/python/sdk/batch -``` - -Install the dependencies: - -```bash -pip3 install -r requirements.txt -``` - -Run the `batch-sdk` service alongside a Dapr sidecar. - -```bash -dapr run --app-id batch-sdk --app-port 50051 --resources-path ../../../components -- python3 app.py -``` - -> **Note**: Since Python3.exe is not defined in Windows, you may need to use `python app.py` instead of `python3 app.py`. - -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 application by the Dapr sidecar. - -```python -# Triggered by Dapr input binding -@app.route('/' + cron_binding_name, methods=['POST']) -def process_batch(): -``` - -The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. - -```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} - - 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 - except Exception as e: - print(e, flush=True) - raise SystemExit(e) -``` - -### Step 4: View the output of the job - -Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. - -Your output binding's `print` statement output: - -``` -== APP == Processing batch.. -== APP == insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32) -== APP == insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4) -== APP == insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56) -== APP == Finished processing batch -``` - -In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following to start the interactive *psql* CLI: - -```bash -docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password -``` - -At the `admin=#` prompt, change to the `orders` table: - -```bash -\c orders; -``` - -At the `orders=#` prompt, select all rows: - -```bash -select * from orders; -``` - -The output should look like this: - -``` - orderid | customer | price ----------+------------+-------- - 1 | John Smith | 100.32 - 2 | Jane Bond | 15.4 - 3 | Tony James | 35.56 -``` - -#### `components\binding-cron.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the Cron [binding building block]({{< ref bindings >}}) -- Calls the binding endpoint (`batch`) every 10 seconds - -The Cron `binding-cron.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron - namespace: quickstarts -spec: - type: bindings.cron - version: v1 - 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. - -#### `component\binding-postgresql.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) -- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file - -With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. - -The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sqldb - namespace: quickstarts -spec: - type: bindings.postgresql - version: v1 - 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: - -- `spec/type` specifies that PostgreSQL is used for this binding. -- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. - -{{% /codetab %}} - - -{{% codetab %}} - -### Pre-requisites - -For this example, you will need: - -- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). -- [Latest Node.js installed](https://nodejs.org/download/). - -- [Docker Desktop](https://www.docker.com/products/docker-desktop) - - -### Step 1: Set up the environment - -Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). - -```bash -git clone https://github.com/dapr/quickstarts.git -``` - -### Step 2: Run PostgreSQL Docker container locally - -Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. - -In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following command to set up the container: - -```bash -docker compose up -``` - -Verify that the container is running locally. - -```bash -docker ps -``` - -The output should include: - -```bash -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db -``` - -### Step 3: Schedule a Cron job and write to the database - -In a new terminal window, navigate to the SDK directory. - -```bash -cd bindings/javascript/sdk/batch -``` - -Install the dependencies: - -```bash -npm install -``` - -Run the `batch-sdk` service alongside a Dapr sidecar. - -```bash -dapr run --app-id batch-sdk --app-port 5002 --dapr-http-port 3500 --resources-path ../../../components -- node index.js -``` - -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 application by the Dapr sidecar. - -```javascript -async function start() { - await server.binding.receive(cronBindingName,processBatch); - await server.start(); -} -``` - -The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "##componentsbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. - -```javascript -async function processBatch(){ - const loc = '../../orders.json'; - fs.readFile(loc, 'utf8', (err, data) => { - const orders = JSON.parse(data).orders; - orders.forEach(order => { - let sqlCmd = `insert into orders (orderid, customer, price) values (${order.orderid}, '${order.customer}', ${order.price});`; - let payload = `{ "sql": "${sqlCmd}" } `; - console.log(payload); - client.binding.send(postgresBindingName, "exec", "", JSON.parse(payload)); - }); - console.log('Finished processing batch'); - }); - return 0; -} -``` - -### Step 4: View the output of the job - -Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. - -Your output binding's `print` statement output: - -``` -== APP == Processing batch.. -== APP == insert into orders (orderid, customer, price) values(1, 'John Smith', 100.32) -== APP == insert into orders (orderid, customer, price) values(2, 'Jane Bond', 15.4) -== APP == insert into orders (orderid, customer, price) values(3, 'Tony James', 35.56) -``` - -In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following to start the interactive Postgres CLI: - -```bash -docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password -``` - -At the `admin=#` prompt, change to the `orders` table: - -```bash -\c orders; -``` - -At the `orders=#` prompt, select all rows: - -```bash -select * from orders; -``` - -The output should look like this: - -``` - orderid | customer | price ----------+------------+-------- - 1 | John Smith | 100.32 - 2 | Jane Bond | 15.4 - 3 | Tony James | 35.56 -``` - -#### `components\binding-cron.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the Cron [binding building block]({{< ref bindings >}}) -- Calls the binding endpoint (`batch`) every 10 seconds - -The Cron `binding-cron.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron - namespace: quickstarts -spec: - type: bindings.cron - version: v1 - 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. - -#### `component\binding-postgresql.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) -- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file - -With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. - -The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sqldb - namespace: quickstarts -spec: - type: bindings.postgresql - version: v1 - 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: - -- `spec/type` specifies that PostgreSQL is used for this binding. -- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. - -{{% /codetab %}} - - -{{% codetab %}} - -### Pre-requisites - -For this example, you will need: - -- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). -- [.NET SDK or .NET 6 SDK installed](https://dotnet.microsoft.com/download). - -- [Docker Desktop](https://www.docker.com/products/docker-desktop) - - -### Step 1: Set up the environment - -Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). - -```bash -git clone https://github.com/dapr/quickstarts.git -``` - -### Step 2: Run PostgreSQL Docker container locally - -Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. - -In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following command to set up the container: - -```bash -docker compose up -``` - -Verify that the container is running locally. - -```bash -docker ps -``` - -The output should include: - -```bash -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db -``` - -### Step 3: Schedule a Cron job and write to the database - -In a new terminal window, navigate to the SDK directory. - -```bash -cd bindings/csharp/sdk/batch -``` - -Install the dependencies: - -```bash -dotnet restore -dotnet build batch.csproj -``` - -Run the `batch-sdk` service alongside a Dapr sidecar. - -```bash -dapr run --app-id batch-sdk --app-port 7002 --resources-path ../../../components -- dotnet 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 application by the Dapr sidecar. - -```csharp -app.MapPost("/" + cronBindingName, async () => { -// ... -}); -``` - -The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. - -```csharp -// ... -string jsonFile = File.ReadAllText("../../../orders.json"); -var ordersArray = JsonSerializer.Deserialize(jsonFile); -using var client = new DaprClientBuilder().Build(); -foreach(Order ord in ordersArray?.orders ?? new Order[] {}){ - var sqlText = $"insert into orders (orderid, customer, price) values ({ord.OrderId}, '{ord.Customer}', {ord.Price});"; - var command = new Dictionary(){ - {"sql", - 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 - -Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. - -Your output binding's `print` statement output: - -``` -== APP == Processing batch.. -== APP == insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32); -== APP == insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4); -== APP == insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56); -== APP == Finished processing batch -``` - -In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following to start the interactive Postgres CLI: - -```bash -docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password -``` - -At the `admin=#` prompt, change to the `orders` table: - -```bash -\c orders; -``` - -At the `orders=#` prompt, select all rows: - -```bash -select * from orders; -``` - -The output should look like this: - -``` - orderid | customer | price ----------+------------+-------- - 1 | John Smith | 100.32 - 2 | Jane Bond | 15.4 - 3 | Tony James | 35.56 -``` - -#### `components\binding-cron.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the Cron [binding building block]({{< ref bindings >}}) -- Calls the binding endpoint (`batch`) every 10 seconds - -The Cron `binding-cron.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron - namespace: quickstarts -spec: - type: bindings.cron - version: v1 - 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. - -#### `component\binding-postgresql.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) -- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file - -With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. - -The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sqldb - namespace: quickstarts -spec: - type: bindings.postgresql - version: v1 - 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: - -- `spec/type` specifies that PostgreSQL is used for this binding. -- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. - -{{% /codetab %}} - - -{{% codetab %}} - -### Pre-requisites - -For this example, you will need: - -- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). -- Java JDK 11 (or greater): - - [Oracle JDK](https://www.oracle.com/java/technologies/downloads), or - - OpenJDK -- [Apache Maven](https://maven.apache.org/install.html), version 3.x. - -- [Docker Desktop](https://www.docker.com/products/docker-desktop) - - -### Step 1: Set up the environment - -Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). - -```bash -git clone https://github.com/dapr/quickstarts.git -``` - -### Step 2: Run PostgreSQL Docker container locally - -Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. - -In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following command to set up the container: - -```bash -docker compose up -``` - -Verify that the container is running locally. - -```bash -docker ps -``` - -The output should include: - -```bash -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db -``` - -### Step 3: Schedule a Cron job and write to the database - -In a new terminal window, navigate to the SDK directory. - -```bash -cd bindings/java/sdk/batch -``` - -Install the dependencies: - -```bash -mvn clean install -``` - -Run the `batch-sdk` service alongside a Dapr sidecar. - -```bash -dapr run --app-id batch-sdk --app-port 8080 --resources-path ../../../components -- java -jar target/BatchProcessingService-0.0.1-SNAPSHOT.jar -``` - -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 application by the Dapr sidecar. - -```java -@PostMapping(path = cronBindingPath, consumes = MediaType.ALL_VALUE) -public ResponseEntity processBatch() throws IOException, Exception -``` - -The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. - -```java -try (DaprClient client = new DaprClientBuilder().build()) { - - for (Order order : ordList.orders) { - String sqlText = String.format( - "insert into orders (orderid, customer, price) " + - "values (%s, '%s', %s);", - order.orderid, order.customer, order.price); - logger.info(sqlText); - - Map metadata = new HashMap(); - metadata.put("sql", sqlText); - - // Invoke sql output binding using Dapr SDK - client.invokeBinding(sqlBindingName, "exec", null, metadata).block(); - } - - logger.info("Finished processing batch"); - - return ResponseEntity.ok("Finished processing batch"); -} -``` - -### Step 4: View the output of the job - -Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. - -Your output binding's `print` statement output: - -``` -== APP == 2022-06-22 16:39:17.012 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : Processing batch.. -== APP == 2022-06-22 16:39:17.268 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : insert into orders (orderid, customer, price) values (1, 'John Smith', 100.32); -== APP == 2022-06-22 16:39:17.838 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : insert into orders (orderid, customer, price) values (2, 'Jane Bond', 15.4); -== APP == 2022-06-22 16:39:17.844 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : insert into orders (orderid, customer, price) values (3, 'Tony James', 35.56); -== APP == 2022-06-22 16:39:17.848 INFO 35772 --- [nio-8080-exec-4] c.s.c.BatchProcessingServiceController : Finished processing batch -``` - -In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following to start the interactive Postgres CLI: - -```bash -docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password -``` - -At the `admin=#` prompt, change to the `orders` table: - -```bash -\c orders; -``` - -At the `orders=#` prompt, select all rows: - -```bash -select * from orders; -``` - -The output should look like this: - -``` - orderid | customer | price ----------+------------+-------- - 1 | John Smith | 100.32 - 2 | Jane Bond | 15.4 - 3 | Tony James | 35.56 -``` - -#### `components\binding-cron.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the Cron [binding building block]({{< ref bindings >}}) -- Calls the binding endpoint (`batch`) every 10 seconds - -The Cron `binding-cron.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron - namespace: quickstarts -spec: - type: bindings.cron - version: v1 - 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. - -#### `component\binding-postgresql.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) -- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file - -With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. - -The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sqldb - namespace: quickstarts -spec: - type: bindings.postgresql - version: v1 - 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: - -- `spec/type` specifies that PostgreSQL is used for this binding. -- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. - -{{% /codetab %}} - - -{{% codetab %}} - -### Pre-requisites - -For this example, you will need: - -- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started). -- [Latest version of Go](https://go.dev/dl/). - -- [Docker Desktop](https://www.docker.com/products/docker-desktop) - - -### Step 1: Set up the environment - -Clone the [sample provided in the Quickstarts repo](https://github.com/dapr/quickstarts/tree/master/bindings). - -```bash -git clone https://github.com/dapr/quickstarts.git -``` - -### Step 2: Run PostgreSQL Docker container locally - -Run the [PostgreSQL instance](https://www.postgresql.org/) locally in a Docker container on your machine. The Quickstart sample includes a Docker Compose file to locally customize, build, run, and initialize the `postgres` container with a default `orders` table. - -In a terminal window, from the root of the Quickstarts clone directory, navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following command to set up the container: - -```bash -docker compose up -``` - -Verify that the container is running locally. - -```bash -docker ps -``` - -The output should include: - -```bash -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -55305d1d378b postgres "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:5432->5432/tcp sql_db -``` - -### Step 3: Schedule a Cron job and write to the database - -In a new terminal window, navigate to the SDK directory. - -```bash -cd bindings/go/sdk/batch -``` - -Install the dependencies: - -```bash -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 --resources-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 application by the Dapr sidecar. - -```go -// Triggered by Dapr input binding -r.HandleFunc("/"+cronBindingName, processBatch).Methods("POST") -``` - -The `batch-sdk` service uses the PostgreSQL output binding defined in the [`binding-postgresql.yaml`]({{< ref "#componentbinding-postgresyaml-component-file" >}}) component to insert the `OrderId`, `Customer`, and `Price` records into the `orders` table. - -```go -func sqlOutput(order Order) (err error) { - - client, err := dapr.NewClient() - if err != nil { - return err - } - - ctx := context.Background() - - 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 -} -``` - -### Step 4: View the output of the job - -Notice, as specified above, the code invokes the output binding with the `OrderId`, `Customer`, and `Price` as a payload. - -Your output binding's `print` statement output: - -``` -== APP == Processing batch.. -== APP == insert into orders (orderid, customer, price) values(1, 'John Smith', 100.32) -== APP == insert into orders (orderid, customer, price) values(2, 'Jane Bond', 15.4) -== APP == insert into orders (orderid, customer, price) values(3, 'Tony James', 35.56) -``` - -In a new terminal, verify the same data has been inserted into the database. Navigate to the `bindings/db` directory. - -```bash -cd bindings/db -``` - -Run the following to start the interactive Postgres CLI: - -```bash -docker exec -i -t postgres psql --username postgres -p 5432 -h localhost --no-password -``` - -At the `admin=#` prompt, change to the `orders` table: - -```bash -\c orders; -``` - -At the `orders=#` prompt, select all rows: - -```bash -select * from orders; -``` - -The output should look like this: - -``` - orderid | customer | price ----------+------------+-------- - 1 | John Smith | 100.32 - 2 | Jane Bond | 15.4 - 3 | Tony James | 35.56 -``` - -#### `components\binding-cron.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the Cron [binding building block]({{< ref bindings >}}) -- Calls the binding endpoint (`batch`) every 10 seconds - -The Cron `binding-cron.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron - namespace: quickstarts -spec: - type: bindings.cron - version: v1 - 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. - -#### `component\binding-postgresql.yaml` component file - -When you execute the `dapr run` command and specify the component path, the Dapr sidecar: - -- Initiates the PostgreSQL [binding building block]({{< ref postgresql.md >}}) -- Connects to PostgreSQL using the settings specified in the `binding-postgresql.yaml` file - -With the `binding-postgresql.yaml` component, you can easily swap out the backend database [binding]({{< ref supported-bindings.md >}}) without making code changes. - -The PostgreSQL `binding-postgresql.yaml` file included for this Quickstart contains the following: - -```yaml -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sqldb - namespace: quickstarts -spec: - type: bindings.postgresql - version: v1 - 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: - -- `spec/type` specifies that PostgreSQL is used for this binding. -- `spec/metadata` defines the connection to the PostgreSQL instance used by the component. - -{{% /codetab %}} - -{{< /tabs >}} - -## Run one application at a time - Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} diff --git a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md index 3581606d0a4..61306891165 100644 --- a/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/pubsub-quickstart.md @@ -21,10 +21,6 @@ You can try out this pub/sub quickstart by either: ## Run using Multi-App Run -{{% alert title="Note" color="primary" %}} - [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. -{{% /alert %}} - Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} diff --git a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md index 08014b5e10b..c33c529f952 100644 --- a/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/serviceinvocation-quickstart.md @@ -18,10 +18,6 @@ Learn more about Dapr's methods for service invocation in the [overview article] ## Run using Multi-App Run -{{% alert title="Note" color="primary" %}} - [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. -{{% /alert %}} - Select your preferred language before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} diff --git a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md index e360c660076..acf77540798 100644 --- a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md @@ -16,10 +16,6 @@ While this sample uses Redis, you can swap it out for any one of the [supported ## Run using Multi-App Run -{{% alert title="Note" color="primary" %}} - [Multi-App Run]({{< ref multi-app-dapr-run >}}) is currently a preview feature only supported in Linux/MacOS. -{{% /alert %}} - Select your preferred language-specific Dapr SDK before proceeding with the Quickstart. {{< tabs "Python" "JavaScript" ".NET" "Java" "Go" >}} From 467bd9de2512a5fbec2f94fc6ae36b8dc87c5bbe Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 22 Sep 2023 18:57:11 -0400 Subject: [PATCH 5/7] update yaml Signed-off-by: Hannah Hunter --- .../quickstarts/statemanagement-quickstart.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md index acf77540798..7eedac31e12 100644 --- a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md @@ -105,11 +105,11 @@ When you run `dapr init`, Dapr creates a default [Multi-App Run template file]({ ```yml version: 1 common: - resourcesPath: ../../../resources/ + resourcesPath: ../../resources/ apps: - appID: order-processor appDirPath: ./order-processor/ - command: ["dotnet", "run"] + command: ["python3" , "app.py"] ``` ##### `statestore.yaml` component file @@ -242,11 +242,11 @@ When you run `dapr init`, Dapr creates a default Multi-App Run template file nam ```yml version: 1 common: - resourcesPath: ../../../resources/ + resourcesPath: ../../resources/ apps: - appID: order-processor appDirPath: ./order-processor/ - command: ["dotnet", "run"] + command: ["npm", "run", "start"] ``` ##### `statestore.yaml` component file @@ -509,11 +509,11 @@ When you run `dapr init`, Dapr creates a default Multi-App Run template file nam ```yml version: 1 common: - resourcesPath: ../../../resources/ + resourcesPath: ../../resources/ apps: - appID: order-processor appDirPath: ./order-processor/ - command: ["dotnet", "run"] + command: ["java", "-jar", "target/OrderProcessingService-0.0.1-SNAPSHOT.jar"] ``` ##### `statestore.yaml` component file @@ -641,11 +641,11 @@ When you run `dapr init`, Dapr creates a default Multi-App Run template file nam ```yml version: 1 common: - resourcesPath: ../../../resources/ + resourcesPath: ../../resources/ apps: - appID: order-processor appDirPath: ./order-processor/ - command: ["dotnet", "run"] + command: ["go", "run", "."] ``` ##### `statestore.yaml` component file From 8faf24ec9e5a1a120e4e4cd20e77badcec109f8f Mon Sep 17 00:00:00 2001 From: Hannah Hunter Date: Fri, 22 Sep 2023 19:00:23 -0400 Subject: [PATCH 6/7] update Signed-off-by: Hannah Hunter --- .../quickstarts/statemanagement-quickstart.md | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md index 7eedac31e12..4d1224c4eb7 100644 --- a/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/statemanagement-quickstart.md @@ -48,12 +48,6 @@ In a terminal window, navigate to the `order-processor` directory. cd state_management/python/sdk/order-processor ``` -Install the dependencies: - -```bash -pip3 install -r requirements.txt -``` - Run the `order-processor` service alongside a Dapr sidecar using [Multi-App Run]({{< ref multi-app-dapr-run >}}). ```bash @@ -176,17 +170,6 @@ In a terminal window, navigate to the `order-processor` directory. cd state_management/javascript/sdk/order-processor ``` -Install dependencies, which will include the `@dapr/dapr` package from the JavaScript SDK: - -```bash -npm install -``` - -Verify you have the following files included in the service directory: - -- `package.json` -- `package-lock.json` - Run the `order-processor` service alongside a Dapr sidecar. ```bash @@ -313,13 +296,6 @@ In a terminal window, navigate to the `order-processor` directory. cd state_management/csharp/sdk/order-processor ``` -Recall NuGet packages: - -```bash -dotnet restore -dotnet build -``` - Run the `order-processor` service alongside a Dapr sidecar. ```bash @@ -447,12 +423,6 @@ In a terminal window, navigate to the `order-processor` directory. cd state_management/java/sdk/order-processor ``` -Install the dependencies: - -```bash -mvn clean install -``` - Run the `order-processor` service alongside a Dapr sidecar. ```bash @@ -580,12 +550,6 @@ In a terminal window, navigate to the `order-processor` directory. cd state_management/go/sdk/order-processor ``` -Install the dependencies and build the application: - -```bash -go build . -``` - Run the `order-processor` service alongside a Dapr sidecar. ```bash From 9e1e5482828e2a1b6d4fe787b278cbb055b71c1b Mon Sep 17 00:00:00 2001 From: Mark Fussell Date: Sun, 24 Sep 2023 20:22:16 -0700 Subject: [PATCH 7/7] Update daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md Signed-off-by: Mark Fussell --- .../en/getting-started/quickstarts/bindings-quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md index 22c56afe25b..cbfa248c94b 100644 --- a/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md +++ b/daprdocs/content/en/getting-started/quickstarts/bindings-quickstart.md @@ -11,7 +11,7 @@ Let's take a look at Dapr's [Bindings building block]({{< ref bindings >}}). Usi - Trigger your app with events coming in from external systems. - Interface with external systems. -In this Quickstart, you will schedule a batch script to run every 10 seconds using an input [Cron]({{< ref cron.md >}}) binding. The script processes a JSON file and outputs data to a SQL database using the [PostgreSQL]({{< ref postgresql.md >}}) Dapr binding. +In this Quickstart, you schedule a batch script to run every 10 seconds using an input [Cron]({{< ref cron.md >}}) binding. The script processes a JSON file and outputs data to a SQL database using the [PostgreSQL]({{< ref postgresql.md >}}) Dapr binding.