-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Elena Kolevska <[email protected]>
- Loading branch information
1 parent
2add93f
commit c325a2a
Showing
9 changed files
with
279 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Example - Publish and subscribe to messages | ||
|
||
This example utilizes a publisher and a subscriber to show the bidirectional pubsub pattern. | ||
It creates a publisher and calls the `publish_event` method in the `DaprClient`. | ||
In the s`subscriber.py` file it creates a subscriber object that can call the `next_message` method to get new messages from the stream. After processing the new message, it returns a status to the stream. | ||
|
||
|
||
> **Note:** Make sure to use the latest proto bindings | ||
## Pre-requisites | ||
|
||
- [Dapr CLI and initialized environment](https://docs.dapr.io/getting-started) | ||
- [Install Python 3.8+](https://www.python.org/downloads/) | ||
|
||
## Install Dapr python-SDK | ||
|
||
<!-- Our CI/CD pipeline automatically installs the correct version, so we can skip this step in the automation --> | ||
|
||
```bash | ||
pip3 install dapr | ||
``` | ||
|
||
## Run the example | ||
|
||
Run the following command in a terminal/command prompt: | ||
|
||
<!-- STEP | ||
name: Run subscriber | ||
expected_stdout_lines: | ||
- '== APP == Subscriber received: id=1, message="hello world", content_type="application/json"' | ||
- 'RETRY status returned from app while processing pub/sub event' | ||
- '== APP == Subscriber received: id=2, message="hello world", content_type="application/json"' | ||
- '== APP == Subscriber received: id=3, message="hello world", content_type="application/json"' | ||
- '== APP == Wildcard-Subscriber received: id=4, message="hello world", content_type="application/json"' | ||
- '== APP == Wildcard-Subscriber received: id=5, message="hello world", content_type="application/json"' | ||
- '== APP == Wildcard-Subscriber received: id=6, message="hello world", content_type="application/json"' | ||
- '== APP == Dead-Letter Subscriber received: id=7, message="hello world", content_type="application/json"' | ||
- '== APP == Dead-Letter Subscriber. Received via deadletter topic: TOPIC_D_DEAD' | ||
- '== APP == Dead-Letter Subscriber. Originally intended topic: TOPIC_D' | ||
output_match_mode: substring | ||
background: true | ||
match_order: none | ||
sleep: 3 | ||
--> | ||
|
||
```bash | ||
# 1. Start Subscriber | ||
dapr run --app-id python-subscriber --app-protocol grpc python3 subscriber.py | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
In another terminal/command prompt run: | ||
|
||
<!-- STEP | ||
name: Run publisher | ||
expected_stdout_lines: | ||
- "== APP == {'id': 1, 'message': 'hello world'}" | ||
- "== APP == {'id': 2, 'message': 'hello world'}" | ||
- "== APP == {'id': 3, 'message': 'hello world'}" | ||
- "== APP == {'id': 4, 'message': 'hello world'}" | ||
- "== APP == {'id': 5, 'message': 'hello world'}" | ||
background: true | ||
sleep: 15 | ||
--> | ||
|
||
```bash | ||
# 2. Start Publisher | ||
dapr run --app-id python-publisher --app-protocol grpc --dapr-grpc-port=3500 --enable-app-health-check python3 publisher.py | ||
``` | ||
|
||
<!-- END_STEP --> | ||
|
||
## Cleanup | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.