/**
  * {@inheritdoc}
  */
 public function handle(MessageInterface $message, EventDispatcherInterface $dispatcher)
 {
     $event = new ConsumerEvent($message);
     try {
         $dispatcher->dispatch($message->getType(), $event);
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_DONE);
     } catch (\Exception $e) {
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_ERROR);
         throw new HandlingException("Error while handling a message: " . $e->getMessage(), 0, $e);
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function handle(MessageInterface $message, EventDispatcherInterface $dispatcher)
 {
     $event = new ConsumerEvent($message);
     try {
         $dispatcher->dispatch($message->getType(), $event);
         $message->getValue('AMQMessage')->delivery_info['channel']->basic_ack($message->getValue('AMQMessage')->delivery_info['delivery_tag']);
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_DONE);
     } catch (HandlingException $e) {
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_ERROR);
         $message->getValue('AMQMessage')->delivery_info['channel']->basic_ack($message->getValue('AMQMessage')->delivery_info['delivery_tag']);
         throw new HandlingException('Error while handling a message', 0, $e);
     } catch (\Exception $e) {
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_ERROR);
         if ($this->recover === true) {
             $message->getValue('AMQMessage')->delivery_info['channel']->basic_recover($message->getValue('AMQMessage')->delivery_info['delivery_tag']);
         } elseif ($this->deadLetterExchange !== null) {
             $message->getValue('AMQMessage')->delivery_info['channel']->basic_reject($message->getValue('AMQMessage')->delivery_info['delivery_tag'], false);
         }
         throw new HandlingException('Error while handling a message', 0, $e);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function handle(MessageInterface $message, EventDispatcherInterface $dispatcher)
 {
     $event = new ConsumerEvent($message);
     try {
         $message->setStartedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_IN_PROGRESS);
         $this->messageManager->save($message);
         $dispatcher->dispatch($message->getType(), $event);
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_DONE);
         $this->messageManager->save($message);
         return $event->getReturnInfo();
     } catch (\Exception $e) {
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_ERROR);
         $this->messageManager->save($message);
         throw new HandlingException('Error while handling a message', 0, $e);
     }
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function restart(MessageInterface $message)
 {
     if ($message->isOpen() || $message->isRunning() || $message->isCancelled()) {
         return;
     }
     $message->setState(MessageInterface::STATE_CANCELLED);
     $this->save($message);
     $newMessage = clone $message;
     $newMessage->setRestartCount($message->getRestartCount() + 1);
     return $newMessage;
 }
 /**
  * {@inheritdoc}
  */
 public function cancel(MessageInterface $message, $force = false)
 {
     if (($message->isRunning() || $message->isError()) && !$force) {
         return;
     }
     $message->setState(MessageInterface::STATE_CANCELLED);
     $this->save($message);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(MessageInterface $message, EventDispatcherInterface $dispatcher)
 {
     $event = new ConsumerEvent($message);
     try {
         $dispatcher->dispatch($message->getType(), $event);
         $message->getValue('AMQMessage')->delivery_info['channel']->basic_ack($message->getValue('AMQMessage')->delivery_info['delivery_tag']);
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_DONE);
     } catch (HandlingException $e) {
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_ERROR);
         $message->getValue('AMQMessage')->delivery_info['channel']->basic_ack($message->getValue('AMQMessage')->delivery_info['delivery_tag']);
         throw new HandlingException("Error while handling a message", 0, $e);
     } catch (\Exception $e) {
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_ERROR);
         throw new HandlingException("Error while handling a message", 0, $e);
     }
 }