I'm testing Cloud Pub/Sub. According to google documentation, ack_deadline of a pull substription can be set between 10s-600s ie. msg will be redelivered by Pubsub if ack_deadline is passed.
I'm processing the pubsub message in subscriber client before ack-ing the msg. This processing time can take ~ 700s which exceeds the max limit of 600s.
reproduction:
- create a topic and subscription (by default Acknowledgement deadline is set to 10s)
- run subscriber code (which ack the messages) see below
- publish some msg on the topic from Web UI
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. According to my understanding, pubsub should redeliver the message again and eventually go this code will go into an infinite loop.
am I missing something here?