pubsub/subscriptions: Ack all 10 messages
Fixes
@@ -111,16 +111,14 @@ func pullMsgs(client *pubsub.Client, name string, topic *pubsub.Topic) error {
sub := client.Subscription(name)
cctx, cancel := context.WithCancel(ctx)
err := sub.Receive(cctx, func(ctx context.Context, msg *pubsub.Message) {
+ msg.Ack()
+ fmt.Printf("Got message: %q\n", string(msg.Data))
mu.Lock()
defer mu.Unlock()
received++
- if received >= 10 {
+ if received == 10 {
cancel()
- msg.Nack()
- return
}
- fmt.Printf("Got message: %q\n", string(msg.Data))
- msg.Ack()
})
if err != nil {
return err
