process() public method

Return false to stop processing messages.
public process ( Swarrot\Broker\Message $message, array $options ) : boolean | null
$message Swarrot\Broker\Message The message given by a MessageProvider
$options array An array containing all parameters
return boolean | null
 /**
  * {@inheritDoc}
  */
 public function process(Message $message, array $options)
 {
     if (true === $this->isTimeExceeded($options)) {
         return false;
     }
     return $this->processor->process($message, $options);
 }
Beispiel #2
0
 /**
  * consume.
  *
  * @param array $options Parameters sent to the processor
  */
 public function consume(array $options = array())
 {
     if (null !== $this->logger) {
         $this->logger->debug(sprintf('Start consuming queue %s.', $this->messageProvider->getQueueName()));
     }
     $this->optionsResolver->setDefaults(array('poll_interval' => 50000));
     if ($this->processor instanceof ConfigurableInterface) {
         $this->processor->setDefaultOptions($this->optionsResolver);
     }
     $options = $this->optionsResolver->resolve($options);
     if ($this->processor instanceof InitializableInterface) {
         $this->processor->initialize($options);
     }
     while (true) {
         while (null !== ($message = $this->messageProvider->get())) {
             if (false === $this->processor->process($message, $options)) {
                 break 2;
             }
         }
         if ($this->processor instanceof SleepyInterface) {
             if (false === $this->processor->sleep($options)) {
                 break;
             }
         }
         usleep($options['poll_interval']);
     }
     if ($this->processor instanceof TerminableInterface) {
         $this->processor->terminate($options);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     $return = $this->processor->process($message, $options);
     if (extension_loaded('pcntl') && $this->shouldStop()) {
         return false;
     }
     return $return;
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     $return = $this->processor->process($message, $options);
     if (null !== $options['memory_limit'] && memory_get_usage() >= $options['memory_limit'] * 1024 * 1024) {
         $this->logger and $this->logger->info(sprintf('[MemoryLimit] Memory limit has been reached (%d MB)', $options['memory_limit']), ['swarrot_processor' => 'memory_limit']);
         return false;
     }
     return $return;
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     $return = $this->processor->process($message, $options);
     if (++$this->messagesProcessed >= $options['max_messages']) {
         $this->logger and $this->logger->info(sprintf('[MaxMessages] Max messages have been reached (%d)', $options['max_messages']), ['swarrot_processor' => 'max_messages']);
         return false;
     }
     return $return;
 }
 /**
  * {@inheritDoc}
  */
 public function process(Message $message, array $options)
 {
     try {
         return $this->processor->process($message, $options);
     } catch (\Exception $e) {
         $this->logger and $this->logger->error('[ExceptionCatcher] An exception occurred. This exception have been catch.', array('swarrot_processor' => 'exception', 'exception' => $e));
     }
     return;
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     $result = $this->processor->process($message, $options);
     foreach ($this->managerRegistry->getManagers() as $managerName => $manager) {
         if (method_exists($manager, 'isOpen') && !$manager->isOpen()) {
             $this->managerRegistry->resetManager($managerName);
             continue;
         }
         $manager->clear();
     }
     return $result;
 }
Beispiel #8
0
 /** {@inheritDoc} */
 public function process(Message $message, array $options)
 {
     $result = $this->processor->process($message, $options);
     $properties = $message->getProperties();
     if (!isset($properties['reply_to'], $properties['correlation_id']) || empty($properties['reply_to']) || empty($properties['correlation_id'])) {
         return $result;
     }
     $this->logger and $this->logger->info(sprintf('sending a new message to the "%s" queue with the id "%s"', $properties['reply_to'], $properties['correlation_id']), ['swarrot_processor' => 'rpc']);
     $message = new Message((string) $result, ['correlation_id' => $properties['correlation_id']]);
     $this->publisher->publish($message, $properties['reply_to']);
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function process(Message $message, array $options)
 {
     $retry = 0;
     while ($retry++ < $options['instant_retry_attempts']) {
         try {
             return $this->processor->process($message, $options);
         } catch (\Exception $e) {
             $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), array('swarrot_processor' => 'instant_retry', 'exception' => $e));
             usleep($options['instant_retry_delay']);
         }
     }
     throw $e;
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     try {
         $return = $this->processor->process($message, $options);
         $this->messageProvider->ack($message);
         $this->logger and $this->logger->info('[Ack] Message #' . $message->getId() . ' has been correctly ack\'ed', ['swarrot_processor' => 'ack']);
         return $return;
     } catch (\Throwable $e) {
         $this->handleException($e, $message, $options);
     } catch (\Exception $e) {
         $this->handleException($e, $message, $options);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     $retry = 0;
     while ($retry++ < $options['instant_retry_attempts']) {
         try {
             return $this->processor->process($message, $options);
         } catch (\Throwable $e) {
             $this->handleException($e, $message, $options);
         } catch (\Exception $e) {
             $this->handleException($e, $message, $options);
         }
     }
     throw $e;
 }
Beispiel #12
0
 /**
  * {@inheritDoc}
  */
 public function process(Message $message, array $options)
 {
     try {
         $return = $this->processor->process($message, $options);
         $this->messageProvider->ack($message);
         $this->logger and $this->logger->info('[Ack] Message #' . $message->getId() . ' have been correctly ack\'ed', array('swarrot_processor' => 'ack'));
         return $return;
     } catch (\Exception $e) {
         $requeue = isset($options['requeue_on_error']) ? (bool) $options['requeue_on_error'] : false;
         $this->messageProvider->nack($message, $requeue);
         $this->logger and $this->logger->warning(sprintf('[Ack] An exception occurred. Message #%d have been %s.', $message->getId(), $requeue ? 'requeued' : 'nack\'ed'), array('swarrot_processor' => 'ack', 'exception' => $e));
         throw $e;
     }
 }
Beispiel #13
0
 /**
  * {@inheritDoc}
  */
 public function process(Message $message, array $options)
 {
     if (!extension_loaded('pcntl')) {
         $this->logger and $this->logger->warning('[SignalHandler] The SignalHandlerProcessor needs the pcntl extension to work', ['swarrot_processor' => 'signal_handler']);
         return $this->processor->process($message, $options);
     }
     $signals = isset($options['signal_handler_signals']) ? $options['signal_handler_signals'] : array();
     foreach ($signals as $signal) {
         pcntl_signal($signal, function () {
             SignalHandlerProcessor::$shouldExit = true;
         });
     }
     $return = $this->processor->process($message, $options);
     if ($this->shouldStop()) {
         return false;
     }
     return $return;
 }
Beispiel #14
0
 /** {@inheritDoc} */
 public function process(Message $message, array $options)
 {
     $properties = $message->getProperties();
     // check for invalid correlation_id properties (not set, or invalid)
     if (!isset($properties['correlation_id'])) {
         return;
     }
     if ($properties['correlation_id'] !== $options['rpc_client_correlation_id']) {
         return;
     }
     $result = null;
     $this->logger and $this->logger->info('Message received from the RPC Server ; terminating consumer', array('correlation_id' => $properties['correlation_id']));
     $this->awoken = true;
     if (null !== $this->processor) {
         $this->logger and $this->logger->info('Sending message to sub-processor');
         $result = $this->processor->process($message, $options);
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     if ($this->extensionLoaded) {
         newrelic_start_transaction($options['new_relic_app_name'], $options['new_relic_license']);
         newrelic_name_transaction($options['new_relic_transaction_name']);
         newrelic_background_job(true);
     }
     try {
         $result = $this->processor->process($message, $options);
     } catch (\Exception $e) {
         if ($this->extensionLoaded) {
             newrelic_notice_error(null, $e);
             newrelic_end_transaction();
         }
         throw $e;
     }
     if ($this->extensionLoaded) {
         newrelic_end_transaction();
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     if ($options['doctrine_ping']) {
         foreach ($this->connections as $connection) {
             if ($connection->isConnected()) {
                 try {
                     $connection->query($connection->getDatabasePlatform()->getDummySelectSQL());
                 } catch (DBALException $e) {
                     $connection->close();
                     // close timed out connections so that using them connects again
                 }
             }
         }
     }
     $result = $this->processor->process($message, $options);
     if ($options['doctrine_close_master']) {
         foreach ($this->connections as $connection) {
             if ($connection instanceof MasterSlaveConnection && $connection->isConnectedToMaster()) {
                 $connection->close();
             }
         }
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function process(Message $message, array $options)
 {
     return $this->decoratedProcessor->process($message, $options);
 }