Skip to content

Latest commit

 

History

History
86 lines (66 loc) · 3.05 KB

README.md

File metadata and controls

86 lines (66 loc) · 3.05 KB

Example - Publish and subscribe to messages

This example utilizes a publisher and a subscriber to show the pubsub pattern, it also shows PublishEvent, OnTopicEvent, GetTopicSubscriptions, and TopicEventResponse functionality. It creates a publisher and calls the publish_event method in the DaprClient. It will create a gRPC subscriber and bind the OnTopicEvent method, which gets triggered after a message is published to the subscribed topic. The subscriber will tell dapr to retry delivery of the first message it receives, logging that the message will be retried, and printing it at least once to standard output.

Note: Make sure to use the latest proto bindings

Pre-requisites

Install Dapr python-SDK

pip3 install dapr dapr-ext-grpc

Run the example

Run the following command in a terminal/command prompt:

# 1. Start Subscriber (expose gRPC server receiver on port 50051)
dapr run --app-id python-subscriber --app-protocol grpc --app-port 50051 python3 subscriber.py

In another terminal/command prompt run:

# 2. Start Publisher
dapr run --app-id python-publisher --app-protocol grpc --dapr-grpc-port=3500 python3 publisher.py

Cleanup

dapr stop --app-id python-subscriber