Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update state management Readme with multi app run #904

Merged
merged 12 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# General
.venv
.env
*.exe
*.suo
*.user
_ReSharper.*
Expand Down
48 changes: 39 additions & 9 deletions state_management/csharp/http/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# Dapr state management (HTTP Client)

In this quickstart, you'll create a microservice to demonstrate Dapr's state management API. The service generates messages to store in a state store. See [Why state management](#why-state-management) to understand when to use this API.
In this quickstart, you'll create a microservice to demonstrate Dapr's state management API. The service generates messages to store in a state store. See [Why state management](https://docs.dapr.io/developing-applications/building-blocks/state-management/) to understand when to use this API.

Visit [this](https://docs.dapr.io/developing-applications/building-blocks/state-management/) link for more information about Dapr and State Management.

> **Note:** This example leverages HTTP `requests` only. If you are looking for the example using the Dapr Client SDK (recommended) [click here](../sdk/).

This quickstart includes one service:

- Dotnet client service `order-processor`
- Dotnet client service `order-processor`

### Run Dotnet service with Dapr
## Run all apps with multi-app run template file

1. Open a new terminal window and navigate to `order-processor` directory:
This section shows how to run applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications.

1. Open a new terminal window and run `order-processor` using the multi app run template defined in [dapr.yaml](./dapr.yaml):

<!-- STEP
name: Install Dotnet dependencies
Expand All @@ -22,10 +24,39 @@ name: Install Dotnet dependencies
cd ./order-processor
dotnet restore
dotnet build
cd ..
```

<!-- END_STEP -->
2. Run the Dotnet service app with Dapr:

2. Run the Dotnet service app with Dapr:

<!-- STEP
name: Run order-processor service
expected_stdout_lines:
- '== APP - order-processor == Getting Order: {"orderId":1}'
- '== APP - order-processor == Getting Order: {"orderId":2}'
- "Exited App successfully"
expected_stderr_lines:
output_match_mode: substring
background: true
sleep: 15
rabollin marked this conversation as resolved.
Show resolved Hide resolved
-->

```bash
dapr run -f .
```
<!-- END_STEP -->

```bash
dapr stop -f .
```

## Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this.

1. Run the Dotnet service app with Dapr:

<!-- STEP
name: Run order-processor service
Expand All @@ -38,14 +69,13 @@ output_match_mode: substring
background: true
sleep: 15
-->

```bash
cd ./order-processor
dapr run --app-id order-processor --resources-path ../../../resources/ -- dotnet run
```

<!-- END_STEP -->
2. Stop and clean up application processes

```bash
dapr stop --app-id order-processor
```
<!-- END_STEP -->
9 changes: 9 additions & 0 deletions state_management/csharp/http/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

version: 1
common:
resourcesPath: ../../resources/
apps:
- appID: order-processor
appDirPath: ./order-processor/
command: ["dotnet", "run"]

2 changes: 1 addition & 1 deletion state_management/csharp/http/order-processor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

for (int i = 1; i <= 10; i++) {
for (int i = 1; i <= 100; i++) {
var orderId = i;
var order = new Order(orderId);
var orderJson = JsonSerializer.Serialize(
Expand Down
71 changes: 57 additions & 14 deletions state_management/csharp/sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
# Dapr state management

In this quickstart, you'll create a microservice to demonstrate Dapr's state management API. The service generates messages to store data in a state store. See [Why state management](#why-state-management) to understand when this pattern might be a good choice for your software architecture.
In this quickstart, you'll create a microservice to demonstrate Dapr's state management API. The service generates messages to store data in a state store. See [Why state management](https://docs.dapr.io/developing-applications/building-blocks/state-management/) to understand when this pattern might be a good choice for your software architecture.

Visit [this](https://docs.dapr.io/developing-applications/building-blocks/state-management/) link for more information about Dapr and State Management.

> **Note:** This example leverages the Dapr client SDK. If you are looking for the example using only HTTP [click here](../http).

This quickstart includes one service:
This quickstart includes one service: Dotnet client service `order-processor`

- Dotnet client service `order-processor`
## Run all apps with multi-app run template file

### Run Dotnet service with Dapr
This section shows how to run applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications.

1. Open a new terminal window and navigate to `order-processor` directory:
1. Open a new terminal window and run `order-processor` using the multi app run template defined in [dapr.yaml](./dapr.yaml):

<!-- STEP
name: Install Dotnet dependencies
-->

```bash
dotnet restore
dotnet build
```

<!-- END_STEP -->

2. Run the Dotnet service app with Dapr:

<!-- STEP
name: Run order-processor service
expected_stdout_lines:
- '== APP - order-processor == Getting Order: Order { orderId = 1 }'
- '== APP - order-processor == Getting Order: Order { orderId = 2 }'
expected_stderr_lines:
output_match_mode: substring
background: true
sleep: 100
-->

```bash
dapr run -f .
```

3. Stop and clean up application processes

```bash
cd ./order-processor
dotnet restore
dotnet build
dapr stop -f .
```

<!-- END_STEP -->
2. Run the Dotnet service app with Dapr:

## Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this.

1. Run the Dotnet service app with Dapr:

<!-- STEP
name: Run order-processor service
Expand All @@ -38,14 +66,29 @@ output_match_mode: substring
background: true
sleep: 15
-->

```bash
cd ./order-processor
dapr run --app-id order-processor --resources-path ../../../resources/ -- dotnet run
```

<!-- END_STEP -->
The Terminal console output should look similar to this:

```bash
dapr stop --app-id order-processor
```text
You're up and running! Both Dapr and your app logs will appear here.

== 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 }
```

2. Stop and clean up application processes

dapr stop --app-id order-processor
<!-- END_STEP -->
9 changes: 9 additions & 0 deletions state_management/csharp/sdk/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

version: 1
common:
resourcesPath: ../../resources/
apps:
- appID: order-processor
appDirPath: ./order-processor/
command: ["dotnet", "run"]

68 changes: 61 additions & 7 deletions state_management/go/http/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
# Dapr state management (HTTP Client)

In this quickstart, you'll create a microservice to demonstrate Dapr's state management API. The service generates messages to store data in a state store.
In this quickstart, you'll create a microservice to demonstrate Dapr's state management API. The service generates messages to store in a state store. See [Why state management](https://docs.dapr.io/developing-applications/building-blocks/state-management/) to understand when to use this API.

Visit the Dapr documentation on [State Management](https://docs.dapr.io/developing-applications/building-blocks/state-management/) for more information.
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/state-management/) link for more information about Dapr and State Management.

> **Note:** This example leverages plain HTTP. You can find an example using the Dapr Client SDK (recommended) in the [`sdk` folder](../sdk/).
> **Note:** This example leverages HTTP `requests` only. If you are looking for the example using the Dapr Client SDK (recommended) [click here](../sdk/).

This quickstart includes one service: Go client service `order-processor`
This quickstart includes one service: Go client service `order-processor`

### Run Go service with Dapr
## Run all apps with multi-app run template file

1. Run the Go service app with Dapr in the `order-processor` folder:
This section shows how to run applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications.

Open a new terminal window and run `order-processor` using the multi app run template defined in [dapr.yaml](./dapr.yaml):

1. Run the Go service app with Dapr:

<!-- STEP
name: Run order-processor service
expected_stdout_lines:
- '== APP - order-processor == Retrieved Order: "{\"orderId\":1}"'
rabollin marked this conversation as resolved.
Show resolved Hide resolved
- '== APP - order-processor == Retrieved Order: "{\"orderId\":2}"'
- "Exited App successfully"
expected_stderr_lines:
output_match_mode: substring
match_order: none
background: true
sleep: 15
-->

```bash
dapr run -f .
```

2. Stop and cleanup application process

```bash
dapr stop -f .
```
<!-- END_STEP -->

## Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- go run` commands. This next section covers how to do this.

1. Run the Go service app with Dapr:

<!-- STEP
name: Run order-processor service
Expand All @@ -20,13 +54,33 @@ expected_stdout_lines:
- "Exited App successfully"
expected_stderr_lines:
output_match_mode: substring
match_order: none
background: true
sleep: 15
-->

```bash
cd ./order-processor
dapr run --app-id order-processor --resources-path ../../../resources -- go run .
dapr run --app-id order-processor --resources-path ../../../resources/ -- go run .
```

The Terminal console output should look similar to this:

```text
You're up and running! Both Dapr and your app logs will appear here.

== APP == Saved Order: {"orderId":1}
== APP == Retrieved Order: "{\"orderId\":1}"
== APP == 2023/09/24 23:31:27 Deleted Order: {"orderId":1}
== APP == Saved Order: {"orderId":2}
== APP == Retrieved Order: "{\"orderId\":2}"
== APP == 2023/09/24 23:31:27 Deleted Order: {"orderId":2}
== APP == Saved Order: {"orderId":3}
== APP == Retrieved Order: "{\"orderId\":3}"
== APP == 2023/09/24 23:31:27 Deleted Order: {"orderId":3}
```

2. Stop and clean up application processes
dapr stop --app-id order-processor

<!-- END_STEP -->
9 changes: 9 additions & 0 deletions state_management/go/http/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

version: 1
common:
resourcesPath: ../../resources/
apps:
- appID: order-processor
appDirPath: ./order-processor/
command: ["go", "run", "."]

Binary file not shown.
Loading
Loading