@sl1m_dogg

Выдает 500 ошибку когда создаю RabbitMQ sender(symfony 2), что может быть не так?

Собственно нужно из формы создать объект notification, закинуть его в очередь, потом получить сообщение и отправить через swiftmailer.
EmailController:sendAction
<?php

namespace MailerBundle\Controller;

use MailerBundle\Entity\EmailHandler\EmailReceiver;
use MailerBundle\Entity\EmailHandler\EmailSender;
use MailerBundle\Sender\AbstractSender;
use MailerBundle\Entity\Notification;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;

class EmailController extends Controller
{
    /**
     * @var AbstractSender
     */
    private $sender;

    /**
     * EmailController constructor.
     * @param AbstractSender $sender
     * @param ContainerInterface $container
     */
    public function __construct
    (
        AbstractSender $sender,
        ContainerInterface $container
    )
    {
        $this->sender = $sender;
        $this->container = $container;
    }

    /**
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function indexAction()
    {
        return $this->render('MailerBundle:Email:index.html.twig');
    }

    /**
     * @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);
        $notification->setSubject($request->request->get('body'));
        $notification->setTo($request->request->get('to'));

        $data = $notification->toJson($this->sender->getMail());

        $amqpSender = new EmailSender();
        $message = $amqpSender->send($data);

        $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->redirectToRoute('email_success');
    }

    public function successAction()
    {
        return $this->render('MailerBundle:Email:success.html.twig');
    }
}


AMQPHandler:
<?php

namespace MailerBundle\Entity\EmailHandler;

use PhpAmqpLib\Connection\AMQPStreamConnection;

class AMQPHandler
{
    protected function getConnection()
    {
        $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
        $channel = $connection->channel();

        $channel->queue_declare('email_queue', false, false, false, false);

        return $channel;
    }
}


EmailSender:
<?php

namespace MailerBundle\Entity\EmailHandler;

use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

class EmailSender extends AMQPHandler
{
    /**
     * @var AMQPStreamConnection
     */
    private $connection;

    /**
     * EmailSender constructor.
     */
    public function __construct()
    {
        $this->connection = $this->getConnection();
    }

    /**
     * @param $message (json)
     */
    public function send($message)
    {
        $message = new AMQPMessage($message, ['delivery_mode' => 2]);
        $this->connection->basic_publish($message, '', 'email_queue');
    }
}


Собственно в сендере даже до конструктора не доходит, xdebug никак не могу запустить, весь код: https://github.com/artemzakholodilo/murka
  • Вопрос задан
  • 470 просмотров
Пригласить эксперта
Ответы на вопрос 1
skobkin
@skobkin
Гентушник, разработчик на PHP и Symfony.
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы