Skip to content

Commit c8fc93d

Browse files
Merge pull request #1297 from AdepuSriCharan/feature/python-multiapp-bindings
feat(python): Enable Multi-App Run for Python HTTP and SDK bindings q…
2 parents a5e384a + 665e714 commit c8fc93d

File tree

6 files changed

+103
-25
lines changed

6 files changed

+103
-25
lines changed

bindings/python/http/README.md

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
# Dapr Bindings (HTTP)
22

3-
In this quickstart, you'll create a microservice to demonstrate Dapr's bindings API to work with external systems as inputs and outputs. The service listens to input binding events from a system CRON and then outputs the contents of local data to a PostreSql output binding.
3+
In this quickstart, you'll create a microservice to demonstrate Dapr's bindings API to work with external systems as inputs and outputs. The service listens to input binding events from a system CRON and then outputs the contents of local data to a PostgreSQL output binding.
44

55
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/bindings/) link for more information about Dapr and Bindings.
66

7-
> **Note:** This example leverages only HTTP REST. If you are looking for the example using the Dapr SDK [click here](../sdk).
7+
> **Note:** This example leverages only HTTP REST. If you are looking for the example using the Dapr SDK [click here](../sdk).
88
99
This quickstart includes one service:
10-
11-
- Python service `batch`
1210

13-
### Run and initialize PostgreSQL container
11+
- Python service `batch-http`
1412

15-
1. Open a new terminal, change directories to `../../db`, and run the container with [Docker Compose](https://docs.docker.com/compose/):
13+
## Prerequisites
14+
15+
- [Docker](https://docs.docker.com/get-docker/)
16+
- [Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)
17+
- Python 3.x
18+
- Initialize Dapr: `dapr init`
19+
20+
---
21+
22+
## Run and initialize PostgreSQL container
23+
24+
1. Open a new terminal, change directories to `../../db`, and run the container with [Docker Compose](https://docs.docker.com/compose/):
1625

1726
<!-- STEP
1827
name: Run and initialize PostgreSQL container
@@ -28,9 +37,11 @@ docker compose up -d
2837

2938
<!-- END_STEP -->
3039

31-
### Run Python service with Dapr
40+
---
41+
42+
## Run Python service with Dapr
3243

33-
2. Open a new terminal window, change directories to `./batch` in the quickstart directory and run:
44+
2. Open a new terminal window, change directories to `./batch` in the quickstart directory and run:
3445

3546
<!-- STEP
3647
name: Install python dependencies
@@ -44,7 +55,9 @@ cd ..
4455

4556
<!-- END_STEP -->
4657

47-
3. Run the Python service app with Dapr:
58+
---
59+
60+
3. From the quickstart directory `bindings/python/http`, run the Python service app with Dapr:
4861

4962
<!-- STEP
5063
name: Run batch-http service
@@ -64,3 +77,28 @@ dapr run -f .
6477
```
6578

6679
<!-- END_STEP -->
80+
81+
The `-f` flag runs the application using the **Multi-App Run configuration** defined in `dapr.yaml`, automatically starting both the application and its Dapr sidecar.
82+
83+
The cron input binding triggers the service every 10 seconds, and the service writes records to PostgreSQL using the output binding.
84+
85+
---
86+
87+
## Verify Data Persistence
88+
89+
4. Open a new terminal window and run the following command to check the rows in the database:
90+
91+
<!-- STEP
92+
name: Verify Data Persistence
93+
expected_stdout_lines:
94+
- 'orderid | customer | price'
95+
- '---------+------------+--------'
96+
expected_stderr_lines:
97+
output_match_mode: substring
98+
-->
99+
100+
```bash
101+
docker exec postgres psql -U postgres -d orders -c "SELECT * FROM orders;"
102+
```
103+
104+
<!-- END_STEP -->

bindings/python/http/batch/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212
#
13-
# dapr run --app-id batch-http --app-port 50051
14-
# --resources-path ../../../components -- python3 app.py
13+
#
14+
# From the quickstart directory `bindings/python/http`, run the Python service app with Dapr:
15+
# dapr run -f .
1516

1617
import json
1718
from flask import Flask
@@ -21,7 +22,7 @@
2122
app = Flask(__name__)
2223

2324
app_port = os.getenv('APP_PORT', '5001')
24-
dapr_port = os.getenv('DAPR_HTTP_PORT', '4001')
25+
dapr_port = os.getenv('DAPR_HTTP_PORT', '3500')
2526
base_url = os.getenv('BASE_URL', 'http://localhost')
2627
cron_binding_name = 'cron'
2728
sql_binding_name = 'sqldb'

bindings/python/http/dapr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ version: 1
22
apps:
33
- appID: batch-http
44
appDirPath: ./batch
5-
appPort: 50051
5+
appPort: 5001
66
command: ["python3", "app.py"]
77
resourcesPath: ../../../components

bindings/python/sdk/README.md

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
# Dapr Bindings (Dapr SDK)
22

3-
In this quickstart, you'll create a microservice to demonstrate Dapr's bindings API to work with external systems as inputs and outputs. The service listens to input binding events from a system CRON and then outputs the contents of local data to a PostreSql output binding.
3+
In this quickstart, you'll create a microservice to demonstrate Dapr's bindings API to work with external systems as inputs and outputs. The service listens to input binding events from a system CRON and then outputs the contents of local data to a PostgreSQL output binding.
44

55
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/bindings/) link for more information about Dapr and Bindings.
66

7-
> **Note:** This example leverages the Dapr SDK. If you are looking for the example using HTTP REST only [click here](../http).
7+
> **Note:** This example leverages the Dapr SDK. If you are looking for the example using HTTP REST only [click here](../http).
88
99
This quickstart includes one service:
10-
11-
- Python service `batch`
1210

13-
### Run and initialize PostgreSQL container
11+
- Python service `batch-sdk`
1412

15-
1. Open a new terminal, change directories to `../../db`, and run the container with [Docker Compose](https://docs.docker.com/compose/):
13+
## Prerequisites
14+
15+
- [Docker](https://docs.docker.com/get-docker/)
16+
- [Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)
17+
- Python 3.x
18+
- Initialize Dapr: `dapr init`
19+
20+
---
21+
22+
## Run and initialize PostgreSQL container
23+
24+
1. Open a new terminal, change directories to `../../db`, and run the container with [Docker Compose](https://docs.docker.com/compose/):
1625

1726
<!-- STEP
1827
name: Run and initialize PostgreSQL container
@@ -28,9 +37,11 @@ docker compose up -d
2837

2938
<!-- END_STEP -->
3039

31-
### Run Python service with Dapr
40+
---
41+
42+
## Run Python service with Dapr
3243

33-
2. Open a new terminal window, change directories to `./batch` in the quickstart directory and run:
44+
2. Open a new terminal window, change directories to `./batch` in the quickstart directory and run:
3445

3546
<!-- STEP
3647
name: Install python dependencies
@@ -44,7 +55,9 @@ cd ..
4455

4556
<!-- END_STEP -->
4657

47-
3. Run the Python service app with Dapr:
58+
---
59+
60+
3. From the quickstart directory `bindings/python/sdk`, run the Python service app with Dapr:
4861

4962
<!-- STEP
5063
name: Run batch-sdk service
@@ -64,3 +77,28 @@ dapr run -f .
6477
```
6578

6679
<!-- END_STEP -->
80+
81+
The `-f` flag runs the application using the **Multi-App Run configuration** defined in `dapr.yaml`, automatically starting both the application and its Dapr sidecar.
82+
83+
The cron input binding triggers the service every 10 seconds, and the service writes records to PostgreSQL using the output binding.
84+
85+
---
86+
87+
## Verify Data Persistence
88+
89+
4. Open a new terminal window and run the following command to check the rows in the database:
90+
91+
<!-- STEP
92+
name: Verify Data Persistence
93+
expected_stdout_lines:
94+
- 'orderid | customer | price'
95+
- '---------+------------+--------'
96+
expected_stderr_lines:
97+
output_match_mode: substring
98+
-->
99+
100+
```bash
101+
docker exec postgres psql -U postgres -d orders -c "SELECT * FROM orders;"
102+
```
103+
104+
<!-- END_STEP -->

bindings/python/sdk/batch/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
1212
#
13-
# dapr run --app-id batch-sdk --app-port 50051
14-
# --resources-path ../../../components -- python3 app.py
13+
#
14+
# From the quickstart directory `bindings/python/sdk`, run the Python service app with Dapr:
15+
# dapr run -f .
1516

1617
import json
1718
from flask import Flask

bindings/python/sdk/dapr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ version: 1
22
apps:
33
- appID: batch-sdk
44
appDirPath: ./batch
5-
appPort: 50051
5+
appPort: 5001
66
command: ["python3", "app.py"]
77
resourcesPath: ../../../components

0 commit comments

Comments
 (0)