Your subscription does not belong to a given ack ID

Problem

When a Cloud Pub/Sub message is delivered, an ack ID is embeded into the message that is later used to confirm delivery. However, if the Ack ID doesn't match the subscription where the messages are consumed, you get the following error:
You have passed a subscription that does not belong to the given ack ID.

Environment

  • Pub/Sub acknowledging message IDs

Solution

  1. Make sure the subscription name is not taken already.
  2. Create your subscription and use it to Ack messages from the previous subscription.

Cause

This error may happen under the following scenarios:

  • Running multiple client application instances (for example, applications running in Google Kubernetes Engine) which create or delete subscriptions programmatically.
  • When a subscription is created, the Pub/Sub API will return a 200 before the actual delete is finished. If a new subscription with the same name is created and to be used to ACK messages from the previous subscription, this error message will be returned.