Exemple #1
0
 /**
  * Flush a queue
  *
  * @param  bool $async
  * @return void
  */
 private function doFlush(bool $async)
 {
     // SQS only supports batch of 10, so we need to splice like that
     while (!empty($this->messages)) {
         $messagesToPush = array_splice($this->messages, 0, 10);
         $parameters = ['QueueUrl' => $this->url, 'Entries' => []];
         foreach ($messagesToPush as $key => $message) {
             $messageParameters = ['Id' => $key, 'MessageBody' => json_encode($message['body'], self::DEFAULT_JSON_FLAGS), 'DelaySeconds' => $message['options']['delay_seconds'] ?? null];
             $parameters['Entries'][] = array_filter($messageParameters, function ($value) {
                 return $value !== null;
             });
         }
         if ($async) {
             $this->sqsClient->sendMessageBatchAsync($parameters);
         } else {
             $this->sqsClient->sendMessageBatch($parameters);
         }
     }
 }