dapr / python-sdk

Dapr SDK for Python
Apache License 2.0
232 stars 127 forks source link

Bidirectional streaming for pubsub (async client) #742

Closed elena-kolevska closed 1 month ago

elena-kolevska commented 1 month ago

Description

Adds pubsub bidirectional streaming support for the async client, extending the API with the subscribe and subscribe_handler methods.

The subscribe method returns a Subscription object, which allows users to pull messages from the stream by calling the next_message method. When done, the close method should be called to terminate the subscription and stop receiving messages.

The subscribe_with_handler method accepts a user callback function that is executed for each message received from the stream. The callback function should return a TopicEventResponseStatus, indicating whether the message was processed successfully, should be retried, or discarded. Users can return these statuses using the Subscription.SUCCESS, Subscription.RETRY, and Subscription.DROP class properties. The method will automatically manage message acknowledgements based on the returned status. The call to subscribe_with_handler method returns a close function, which should be called to terminate the subscription when done.

Issue reference

https://github.com/dapr/python-sdk/issues/730

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 79.27632% with 63 lines in your changes missing coverage. Please review.

Project coverage is 86.08%. Comparing base (bffb749) to head (8ba8b41). Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
dapr/aio/clients/grpc/subscription.py 79.26% 17 Missing :warning:
dapr/aio/clients/grpc/client.py 33.33% 16 Missing :warning:
dapr/clients/grpc/subscription.py 83.50% 16 Missing :warning:
dapr/common/pubsub/subscription.py 83.07% 11 Missing :warning:
dapr/clients/grpc/interceptors.py 50.00% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #742 +/- ## ========================================== - Coverage 86.63% 86.08% -0.55% ========================================== Files 84 87 +3 Lines 4473 4772 +299 ========================================== + Hits 3875 4108 +233 - Misses 598 664 +66 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.