Reputation: 20045
(env) user@cloudshell:~ (project-id)$ gcloud pubsub topics create Topic
Created topic [projects/project-id/topics/Topic].
(env) user@cloudshell:~ (project-id)$ gcloud pubsub subscriptions create Sub --topic=Topic
Created subscription [projects/project-id/subscriptions/Sub].
(env) user@cloudshell:~ (project-id)$ gcloud pubsub topics publish Topic --message=A
messageIds:
- '1187813469495553'
(env) user@cloudshell:~ (project-id)$ gcloud pubsub subscriptions pull Sub
Listed 0 items.
(env) user@cloudshell:~ (project-id)$ gcloud pubsub subscriptions pull Sub
┌──────┬──────────────────┬────────────┬──────────────────┬────────────────┐
│ DATA │ MESSAGE_ID │ ATTRIBUTES │ DELIVERY_ATTEMPT │ACK_ID │
├──────┼──────────────────┼────────────┼──────────────────┼────────────────┤
│ A │ 1187813469495553 │ │ │ ack-ID-1 │
└──────┴──────────────────┴────────────┴──────────────────┴────────────────┘
(env) user@cloudshell:~ (project-id)$ gcloud pubsub subscriptions ack Sub --ack-ids=ack-ID-1
Acked the messages with the following ackIds: [ack-ID-1]
{}
(env) user@cloudshell:~ (project-id)$ gcloud pubsub subscriptions pull Sub
┌──────┬──────────────────┬────────────┬──────────────────┬────────────────┐
│ DATA │ MESSAGE_ID │ ATTRIBUTES │ DELIVERY_ATTEMPT │ ACK_ID │
├──────┼──────────────────┼────────────┼──────────────────┼────────────────┤
│ A │ 1187813469495553 │ │ │ ack-ID-2 │
└──────┴──────────────────┴────────────┴──────────────────┴────────────────┘
(env) user@cloudshell:~ (project-id)$ gcloud pubsub subscriptions pull Sub
┌──────┬──────────────────┬────────────┬──────────────────┬────────────────┐
│ DATA │ MESSAGE_ID │ ATTRIBUTES │ DELIVERY_ATTEMPT │ ACK_ID │
├──────┼──────────────────┼────────────┼──────────────────┼────────────────┤
│ A │ 1187813469495553 │ │ │ ack-ID-3 │
└──────┴──────────────────┴────────────┴──────────────────┴────────────────┘
Should't the queue be empty after ack'ing the only ever published message?
Upvotes: 0
Views: 472
Reputation: 15276
When one performs a pull on a subscription, the message is not considered retrieved until after it has been acknowledged (acked). One can only acknowledge a message following a pull. When one pulls a message from a subscription, a timer is started (inside Pub/Sub). One must acknowledge the message within this timer interval. If not, the message is considered un-acknowledged.
In our example here, when we perform a gcloud
command to pull the message, if we don't perform the follow-on gcloud
ack command before the interval has expired, then the ack request will have no effect. We have the ability to perform a pull using an auto-ack which means that the pull will also immediately ack the message. If we want to perform an explicit ack, we must perform that within the ack timeout interval.
Upvotes: 3