public function receive($message)
 {
     $callback = function () use($message) {
         $data = json_decode($message->body, true);
         $this->sender->send($data);
         $message->delivery_info('channel')->basic_ack($message->delivery_info('delivery_tag'));
     };
     $this->connection->basic_qos(null, 1, null);
     $this->connection->basic_consume('email_queue', '', false, false, false, false, $callback);
     while (count($this->connection->callbacks)) {
         $this->connection->wait();
     }
     return $message;
 }
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function sendAction(Request $request)
 {
     $notification = new Notification();
     $user = $this->get('security.token_storage')->getToken()->getUser();
     $notification->setBody($request->request->get('subject'), $user->getUsername());
     $notification->setSubject($request->request->get('body'));
     $amqpSender = new EmailSender();
     $message = $amqpSender->send($notification->toJson());
     $receiver = new EmailReceiver($this->sender);
     $receiver->receive($message);
     try {
         $this->sender->send($notification);
     } catch (\Exception $ex) {
         $this->render('MailerBundle:Email:error.html.twig', ['message' => $ex->getMessage()]);
     }
     $this->render('MailerBundle:Email:success.html.twig');
 }