[英]Pub/Sub testing: message received by client even when ack_deadline is passed
I'm testing Cloud Pub/Sub.我正在测试 Cloud Pub/Sub。 According to google documentation, ack_deadline
of a pull substription can be set between 10s-600s ie.根据 google 文档,拉取子条的ack_deadline
可以设置在 10s-600s 之间,即。 msg will be redelivered by Pubsub if ack_deadline
is passed.如果通过了 ack_deadline,则消息将由ack_deadline
重新传递。
I'm processing the pubsub message in subscriber client before ack-ing the msg.在确认消息之前,我正在订阅者客户端中处理 pubsub 消息。 This processing time can take ~ 700s which exceeds the max limit of 600s.此处理时间可能需要约 700 秒,超过了 600 秒的最大限制。
reproduction:再生产:
subscriber code:订阅者代码:
import time
import datetime
from concurrent.futures import TimeoutError
from google.cloud import pubsub_v1
project_id = "my-project"
subscription_id = "test-sub"
def sub():
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(project_id, subscription_id)
def callback(message: pubsub_v1.subscriber.message.Message) -> None:
# My processing code, which takes 700s
time.sleep(700) # sleep function to demonstrate processing
print(f"Received {message}."+ str(datetime.datetime.now()) )
message.ack()
print("msg acked")
streaming_pull_future = subscriber.subscribe(subscription_path, callback=callback)
print(f"Listening for messages on {subscription_path}..\n")
try:
streaming_pull_future.result()
except:
streaming_pull_future.cancel() # Trigger the shutdown.
streaming_pull_future.result() # Block until the shutdown is complete.
subscriber.close()
if __name__ == "__main__":
sub()
Even if the ack_deadline
is reached, the message is getting acked which is weird.即使到达ack_deadline
,消息也会被确认,这很奇怪。 According to my understanding, pubsub should redeliver the message again and eventually go this code will go into an infinite loop.根据我的理解,pubsub 应该再次重新传递消息,最终 go 这段代码将 go 进入无限循环。
am I missing something here?我在这里错过了什么吗?
That's correct.这是正确的。 There are several solutions with their tradeoff有几种解决方案与它们的权衡
You can also imagine other pattern.您还可以想象其他模式。 nothing is real perfect, depends on your needs.没有什么是真正完美的,取决于您的需求。
The reason that the message is getting acked and not getting redelivered even after the ack deadline specified in the subscription is reached is that the Pub/Sub client libraries internally extend ack deadlines up to a time specified when instantiating the subscriber client.即使在达到订阅中指定的确认截止日期之后,消息也得到确认并且没有重新传递的原因是 Pub/Sub 客户端库在内部将确认截止日期延长到实例化订阅者客户端时指定的时间。 By default, the time is 1 hour.默认情况下,时间为 1 小时。 You can change this amount of time by changing the max_lease_duration
parameter in the FlowControl
object (search for "FlowControl" in the Types page ) passed into the subscribe
method .您可以通过更改传入subscribe
方法的FlowControl
object(在“ 类型”页面中搜索“FlowControl”)中的max_lease_duration
参数来更改此时间量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.