0

Google PubSub server not resending messages after acknowledgment deadline, which is 10 seconds

Here I am acknowledging after 50 seconds but have not received any resent messages. But will get after restarts the subscriber.

Subscriber subscriber = null;
    ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectIdArg,
                    subscriptionNameArg);
    try {
    MessageReceiver receiver =
                        (PubsubMessage message, AckReplyConsumer consumer) -> {
        
    int i=0;
            while(i<=50){
    
                try {
                    Thread.sleep(1000);
                    System.out.println(i+" : message id : "+messageId);
                    i++;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
    
            }
    consumer.ack();
    
     };
     ExecutorProvider executorProvider = InstantiatingExecutorProvider
                .newBuilder()
                .setExecutorThreadCount(5)
                .build();
    
     subscriber = Subscriber
                .newBuilder(subscriptionName, receiver)
                .setParallelPullCount(1)
                .setExecutorProvider(executorProvider)
                .build();
    
     subscriber.startAsync().awaitRunning();
                subscriber.awaitTerminated();

 } catch (Exception e) {
            log.error("Error in Subscribing Queue. " + e);
            if (subscriber != null) {
                subscriber.stopAsync().awaitTerminated();
            }
        }
Namjith Aravind
  • 404
  • 6
  • 12
  • Could you indicate how you're verifying that pub/sub is not resending the messages? As per your snippet, you're adding a delay of 50 second before acking the messages, pub/sub has an ack deadline of 10 second, however, it seems that it could be extended [while the message is being processed, to then issue the ack or nack of such message when the processing is done](https://googleapis.dev/java/google-cloud-pubsub/latest/com/google/cloud/pubsub/v1/Subscriber.html). – Noe Romero Jan 23 '21 at 00:49
  • Have you tested your code with a single message? This will give you a clear scenario about if pub/sub is resending the message after the time loop finishes, it’s possible that given the delay you're adding, it could be generate [backlog in your subscription](https://cloud.google.com/pubsub/docs/pull#config). If you want to force pub/sub to resend the message, maybe it's better to send a nack instead of an ack event. – Noe Romero Jan 23 '21 at 00:52
  • In addition, could you elaborate about your case-use?, it's not clear if you are looking to [extend the ack time](https://cloud.google.com/pubsub/docs/pull#dupes) (modifyAckDeadline method) or if you're looking to consume the messages after a time frame (50 sec) they were published, in this second scenario, I recommend you to take a look at [this approach](https://stackoverflow.com/questions/39742091). – Noe Romero Jan 23 '21 at 00:58
  • @NoeRomero As you said since the process is not completed, the subscriber is extending the ack time period from 10 seconds to the time which the process has taken. The max time I configured with maxAckExtensionPeriod , default value is 1 hour, But it will extend if any other process taken more than that, after one retry ateempt. – Namjith Aravind Jan 24 '21 at 04:17

1 Answers1

1

I found what is happening behind. Even if the acknowledgment deadline is 10 seconds and the process taking more than that this time will extend to a subscriber maxAckExtensionPeriod configuration which has a default value of one hour. After one-hour pub-sub server will retry, this retry also will happen one time , because if the process taking more than one hour this value also extends to the previous max processing time.

Namjith Aravind
  • 404
  • 6
  • 12