C
C
Crash2020-06-09 12:16:32
symfony
Crash, 2020-06-09 12:16:32

What am I doing wrong with Symfony Messenger?

So, I solve the problem of sending email messages. In a good way, this should be done asynchronously, which is what I'm trying to set up. But first, I want to test the functionality of the code, so I just write the text to a file.

I did everything according to the documentation: https://symfony.com/doc/current/messenger.html
I tried both Redis and DB as a transport

Message class:

namespace App\Message;

/**
 * Class EmailNotification
 * @package App\Message
 */
final class EmailNotification
{
     private $email;
     private $flightId;

     public function __construct(string $email, int $flightId)
     {
         $this->email       = $email;
         $this->flightId    = $flightId;
     }

    public function getEmail(): string
    {
        return $this->email;
    }

    public function getFlightId(): int
    {
        return $this->flightId;
    }
}


The handler class where I'm trying to get the code to do some useful work:
namespace App\MessageHandler;

use App\Message\EmailNotification;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

final class EmailNotificationHandler implements MessageHandlerInterface
{
    /**
     * @param EmailNotification $message
     */
    public function __invoke(EmailNotification $message)
    {
        $email      = $message->getEmail();
        $flightId   = $message->getFlightId();

        $mes = "Flight $flightId was cancelled - $email";

        $testFile = __DIR__ .'/../../var/log/test.txt';

        file_put_contents($testFile, $mes);
    }
}


The call code itself:
$emails = $this->getEmails($flightId);

foreach ($emails as $email) {
    $bus->dispatch(new EmailNotification($email, $flightId));
}


The problem is that nothing is written to the file mentioned in the handler code. Sending messages by itself works - both in the database table and in Redis, the corresponding records are created.

Help me figure out what I'm doing wrong? I haven't seen any errors yet, the file is writable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Crash, 2020-06-09
@Bandicoot

Workers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question