Google Professional Cloud Developer exam dumps

Google Professional Cloud Developer practice question 413 of 481

Professional Cloud Developer. Professional level, Google Cloud. Free question with the correct answer and a full explanation.

Google Professional Cloud Developer Question 413

Single answerGoogle Cloud Platform

You are developing an application that consumes messages from a Google Cloud Pub/Sub subscription. The application processes messages asynchronously, and you want to ensure that each message is successfully acknowledged only after it has been fully processed. How should you implement message acknowledgment to avoid message loss or duplication?

  1. A

    Acknowledge the message as soon as it is received from the subscription.

  2. B

    Acknowledge the message only after the processing logic has successfully completed.

  3. C

    Set the acknowledgment deadline to a very high value to ensure the message doesn't expire during processing.

  4. D

    Use a Pub/Sub dead-letter topic to avoid handling acknowledgments manually.

Show answer and explanation

Correct answer: B

Explanation

In a Pub/Sub consumer application, messages should only be acknowledged after they have been successfully processed. This ensures reliable message delivery and avoids both message loss (due to premature acknowledgment) and duplication (due to failure to acknowledge after successful processing). Acknowledging messages before processing completion can lead to data inconsistencies, while relying solely on acknowledgment deadlines or dead-letter topics does not address the core issue of ensuring successful processing before acknowledgment.

  • A. Incorrect.

    Acknowledging the message as soon as it is received may lead to message loss if the application fails during processing since Pub/Sub assumes the message has been successfully handled.

  • B. Correct.

    Acknowledging the message only after the processing logic has successfully completed ensures that no unprocessed messages are lost or duplicated. This is the correct approach for reliable message handling.

  • C. Incorrect.

    Setting the acknowledgment deadline to a high value is not a reliable solution because it does not address the need to ensure processing is complete before acknowledgment. It also increases the risk of delays in re-delivery if the application fails.

  • D. Incorrect.

    While a dead-letter topic is useful for handling unprocessable messages, it does not replace the need for proper acknowledgment logic. Dead-letter topics handle failed messages, not acknowledgment timing.

Timed practice exam

Take a Google Professional Cloud Developer practice test under exam conditions

60 questions in 120 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam