Google\Cloud\PubSub\Subscription::acknowledgeBatch PHP Méthode

acknowledgeBatch() public méthode

Use {@see \Google\Cloud\PubSub\Subscription::acknowledge()} to acknowledge a single message. Example: $messages = $subscription->pull(); $messagesArray = iterator_to_array($messages); $subscription->acknowledgeBatch($messagesArray);
See also: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/acknowledge Acknowledge Message
public acknowledgeBatch ( array $messages, array $options = [] ) : void
$messages array An array of messages
$options array Configuration Options
Résultat void
    public function acknowledgeBatch(array $messages, array $options = [])
    {
        $this->validateBatch($messages, Message::class);
        $this->connection->acknowledge($options + ['subscription' => $this->name, 'ackIds' => $this->getMessageAckIds($messages)]);
    }

Usage Example

 public function __construct(Subscription $subscription, $job, LoggerInterface $logger)
 {
     // [START callback]
     $callback = function ($response) use($job, $subscription, $logger) {
         $ackIds = [];
         $messages = json_decode($response->getBody(), true);
         if (isset($messages['receivedMessages'])) {
             foreach ($messages['receivedMessages'] as $message) {
                 $attributes = $message['message']['attributes'];
                 $logger->info(sprintf('Message received for book ID "%s" ', $attributes['id']));
                 // Do the actual work in the LookupBookDetailsJob class
                 $job->work($attributes['id']);
                 $ackIds[] = $message['ackId'];
             }
         }
         // Acknowledge the messsages have been handled
         if (!empty($ackIds)) {
             $subscription->acknowledgeBatch($ackIds);
         }
     };
     // [END callback]
     $this->callback = $callback;
     $this->subscription = $subscription;
     $this->connection = new AsyncConnection();
 }
All Usage Examples Of Google\Cloud\PubSub\Subscription::acknowledgeBatch