Skip to content

Commit

Permalink
Adds docs
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <elena@kolevska.com>
  • Loading branch information
elena-kolevska committed Sep 23, 2024
1 parent 2a4a99b commit ecc8696
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions daprdocs/content/en/python-sdk-docs/python-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,36 @@ def mytopic_important(event: v1.Event) -> None:
- For more information about pub/sub, visit [How-To: Publish & subscribe]({{< ref howto-publish-subscribe.md >}}).
- Visit [Python SDK examples](https://github.com/dapr/python-sdk/tree/master/examples/pubsub-simple) for code samples and instructions to try out pub/sub.

#### Subscribe to messages with streaming
You can subscribe to messages from a PubSub topic with streaming by using the `subscribe` method.
This method will return a `Subscription` object on which you can call the `next_message` method to
yield messages as they arrive.
When done using the subscription, you should call the `close` method to stop the subscription.

```python
with DaprClient() as client:
subscription = client.subscribe(
pubsub_name='pubsub', topic='TOPIC_A', dead_letter_topic='TOPIC_A_DEAD'
)

try:
for i in range(5):
message = subscription.next_message(1)
if message is None:
print('No message received within timeout period.')
continue

# Process the message
# ...

# Return the status based on the processing result
subscription.respond_success(message)
# or subscription.respond_retry(message)
# or subscription.respond_drop(message)

finally:
subscription.close()
```

### Interact with output bindings

Expand Down

0 comments on commit ecc8696

Please sign in to comment.