/**
  * {@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);
     }
 }
 /**
  * {@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);
     } 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);
     }
 }
 /**
  * @param MessageInterface $message
  */
 private function sendEmail(MessageInterface $message)
 {
     $mail = $this->mailer->createMessage()->setSubject($message->getValue('subject'))->setFrom(array($message->getValue(array('from', 'email')) => $message->getValue(array('from', 'name'))))->setTo($message->getValue('to'));
     if ($replyTo = $message->getValue('replyTo')) {
         $mail->setReplyTo($replyTo);
     }
     if ($text = $message->getValue(array('message', 'text'))) {
         $mail->addPart($text, 'text/plain');
     }
     if ($html = $message->getValue(array('message', 'html'))) {
         $mail->addPart($html, 'text/html');
     }
     $this->mailer->send($mail);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(MessageInterface $message, EventDispatcherInterface $dispatcher)
 {
     $event = new ConsumerEvent($message);
     try {
         $message->setStartedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_IN_PROGRESS);
         $dispatcher->dispatch($message->getType(), $event);
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_DONE);
         $this->getTube($this->tube)->delete($message->getValue('Job'));
         return $event->getReturnInfo();
     } catch (\Exception $e) {
         $message->setCompletedAt(new \DateTime());
         $message->setState(MessageInterface::STATE_ERROR);
         $this->getTube($this->tube)->release($message->getValue('Job'));
         throw new HandlingException('Error while handling a message', 0, $e);
     }
 }
Example #5
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);
     }
 }
Example #6
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 restart(MessageInterface $message)
 {
     if ($message->isOpen() || $message->isRunning() || $message->isCancelled()) {
         return;
     }
     $this->cancel($message, true);
     $newMessage = clone $message;
     $newMessage->setRestartCount($message->getRestartCount() + 1);
     $newMessage->setType($message->getType());
     return $newMessage;
 }
 /**
  * {@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);
     }
 }