/**
  * @param callable $callback
  *
  * @return void
  */
 protected function consumeMessage(callable $callback)
 {
     $this->channelFactory->fanout($this->exchange, $this->channel)->then(function ($r) use($callback) {
         /** @var Channel $channel */
         $channel = $r[0];
         return $channel->consume(function (Message $message) use($callback) {
             $data = json_decode($message->content, true);
             $callback($this->serializer->deserialize(null, $data));
         }, $this->channel, '', false, true);
     }, function (Exception $exception) {
         $this->loop->stop();
         throw new AsyncMessagingException(sprintf('Could not consume message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()), 0, $exception);
     });
 }
 /**
  * @param QueueMessage $message
  *
  * @return void
  */
 protected function publishMessage(QueueMessage $message)
 {
     $this->channelFactory->fanout($this->exchange, $this->channel)->then(function ($r) use($message) {
         /** @var Channel $channel */
         $channel = $r[0];
         return \React\Promise\all([$channel->publish(json_encode($this->serializer->serialize($message)), [], $this->exchange)]);
     }, function (Exception $exception) {
         $this->loop->stop();
         throw new AsyncMessagingException(sprintf('Could not publish message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()), 0, $exception);
     })->then(function () {
         $this->loop->stop();
     }, function (Exception $exception) {
         $this->loop->stop();
         var_dump(sprintf('Could not publish message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()));
     });
     $this->loop->run();
 }
 /**
  * @param object $object
  * @return array
  */
 public function serialize($object)
 {
     return array('class' => get_class($object), 'payload' => $this->serializer->serialize($object));
 }