Пример #1
0
 /**
  * @param AMQPMessage $message
  */
 public function __invoke(AMQPMessage $message)
 {
     // Unserialize content
     $message->body = $this->queueTemplate->getSerializer()->unserialize($message->body);
     // Intercept incoming message and dispatch receive event.
     $this->queueTemplate->dispatchEvent(RabbitMQ::ON_RECEIVE, new ReceiveEvent($this, $message));
     try {
         // Delegate message to handle method.
         // If the handle method returns false or throws an exception than
         $result = $this->handle($message);
     } catch (\Exception $e) {
         // Failed with errors
         $result = false;
     }
     // Handle result
     $result ? $this->success($message) : $this->failure($message);
 }
 /**
  * @param QueueTemplate $queueTemplate
  * @param array $data
  *
  * @return AMQPMessage
  */
 public function createMessage(QueueTemplate $queueTemplate, array $data)
 {
     return new AMQPMessage($queueTemplate->getSerializer()->serialize($data), ['delivery_mode' => RabbitMQ::DELIVERY_MODE_PERSISTENT]);
 }
Пример #3
0
 /**
  * @param QueueTemplate $queueTemplate
  * @param array $data
  *
  * @return AMQPMessage
  */
 public function createMessage(QueueTemplate $queueTemplate, array $data)
 {
     return new AMQPMessage($queueTemplate->getSerializer()->serialize($data));
 }