googleapis / googleapis/google-cloud-python

Async Streaming Pull Usage

未关闭
#15,644 2 条评论 1 个 reaction 已指派 1 人 已被 @abbrowne126 认领 在 GitHub 查看
api: pubsub
主要语言
Python
星标
5.4k
派生
1.8k
平均合并
3 天 4 小时
30 天内合并 PR
122

描述

Has someone used this in peoduction scenarios? I am stuck and unable to pull messages using the async streaming client and any help would be benefecial.

Is wrapping the standard streaming pull in an asyncio executor gonna give me the same behaviour as below client?

https://github.com/googleapis/python-pubsub/blob/ff229a5fdd4deaff0ac97c74f313d04b62720ff7/google/pubsub_v1/services/subscriber/async_client.py#L1368

This is my current usage:
```python
from google import pubsub_v1
subscriber = pubsub_v1.SubscriberAsyncClient() #skipping the class code but this is the Subscriber client
async def fetch_and_decode_msgs(self):
try:
print(f"Listening for messages on {self.subscription_path}...")
request = pubsub_v1.StreamingPullRequest(
subscription=self.subscription_path,
)

# Not sure if there is any other way to do this
async def request_generator():
yield request
print(f"stream: {request}"). # Code gets blocked here

stream = await self.subscriber.streaming_pull(requests=request_generator())
print(f"stream: {stream}")
# Handle the response
async for response in stream:
for received_message in response.received_messages:
print("Received message: ", received_message.message.data.decode('utf-8'))
except Exception as e:
raise e
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。