/** * {@inheritdoc} */ public function ack(Message $message) { $this->channel->deleteMessage(['QueueUrl' => $this->getQueueName(), 'ReceiptHandle' => $message->getId()]); }
/** * @param \Exception|\Throwable $exception * @param Message $message * @param array $options */ private function handleException($exception, Message $message, array $options) { $this->logger and $this->logger->warning(sprintf('[InstantRetry] An exception occurred. Message #%d will be processed again in %d ms', $message->getId(), $options['instant_retry_delay'] / 1000), ['swarrot_processor' => 'instant_retry', 'exception' => $exception]); usleep($options['instant_retry_delay']); }
/** * {@inheritDoc} */ public function nack(Message $message, $requeue = false) { $this->channel->basic_nack($message->getId(), false, $requeue); }
/** * {@inheritDoc} */ public function nack(Message $message, $requeue = false) { $this->queue->nack($message->getId(), $requeue ? AMQP_REQUEUE : null); }
public function process(Message $message, array $options) { printf("Consume message #%d\n", $message->getId()); }
public function process(Message $message, array $options) { $properties = $message->getProperties(); $body = json_decode($message->getBody(), true); if (!isset($properties['wisembly_attempts'])) { $properties['wisembly_attempts'] = 0; } if (!isset($body['arguments'])) { $body['arguments'] = []; } // add environment $body['arguments'][] = '--env'; $body['arguments'][] = $this->environment; // add verbosity switch ($this->verbosity) { case OutputInterface::VERBOSITY_DEBUG: $body['arguments'][] = '-vvv'; break; case OutputInterface::VERBOSITY_VERY_VERBOSE: $body['arguments'][] = '-vv'; break; case OutputInterface::VERBOSITY_VERBOSE: $body['arguments'][] = '--verbose'; break; case OutputInterface::VERBOSITY_QUIET: $body['arguments'][] = '--quiet'; break; case OutputInterface::VERBOSITY_NORMAL: break; } ++$properties['wisembly_attempts']; $this->logger->info('Dispatching command', $body); // if no proper command given, log it and nack if (!isset($body['command'])) { $this->logger->critical('No proper command found in message', ['body' => $body]); $this->provider->nack($message, false); return; } $this->builder->setPrefix([PHP_BINARY, $this->commandPath, $body['command']]); $this->builder->setArguments($body['arguments']); $process = $this->builder->getProcess(); $process->run(function ($type, $data) { switch ($type) { case Process::OUT: $this->logger->info($data); break; case Process::ERR: $this->logger->error($data); break; } }); // reset the builder $this->builder->setArguments([]); $this->builder->setPrefix([]); if ($process->isSuccessful()) { $this->logger->info('The process was successful', $body); $this->provider->ack($message); return; } $code = $process->getExitCode(); $this->logger->error('The command failed ; aborting', ['body' => $body, 'code' => $code]); $this->provider->nack($message, false); // should we requeue it ? if (static::REQUEUE === $code && $properties['wisembly_attempts'] < static::MAX_ATTEMPTS) { $this->logger->notice('Retrying...', $body); $message = new Message($message->getBody(), $properties, $message->getId()); $this->publisher->publish($message); } }