Skip to content

[Mailer] remove QueuingMessageEvent #17730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 8 additions & 43 deletions mailer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,16 @@ the email is sent::
if (!$message instanceof Email) {
return;
}
// do something with the message
// do something with the message (logging, ...)

// and/or add some Messenger stamps
$event->addStamp(new SomeMessengerStamp());
}

.. versionadded:: 6.2

Methods ``addStamp()`` and ``getStamps()`` were introduced in Symfony 6.2.

.. tip::

When using a ``MessageEvent`` listener to
Expand All @@ -1497,48 +1504,6 @@ and their priorities:

$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\MessageEvent"

QueuingMessageEvent
~~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\Mailer\\Event\\QueuingMessageEvent`

.. versionadded:: 6.2

The ``QueuingMessageEvent`` class was introduced in Symfony 6.2.

``QueuingMessageEvent`` allows to add some logic before the email is sent to
the Messenger bus (this event is not dispatched when no bus is configured); it
extends ``MessageEvent`` to allow adding Messenger stamps to the Messenger
message sent to the bus::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Mailer\Event\QueuingMessageEvent;
use Symfony\Component\Mime\Email;

public function onMessage(QueuingMessageEvent $event): void
{
$message = $event->getMessage();
if (!$message instanceof Email) {
return;
}
// do something with the message (logging, ...)

// and/or add some Messenger stamps
$event->addStamp(new SomeMessengerStamp());
}

This event lets listeners do something before a message is sent to the queue
(like adding stamps or logging) but any changes to the message or the envelope
are discarded. To change the message or the envelope, listen to
``MessageEvent`` instead.

Execute this command to find out which listeners are registered for this event
and their priorities:

.. code-block:: terminal

$ php bin/console debug:event-dispatcher "Symfony\Component\Mailer\Event\QueuingMessageEvent"

SentMessageEvent
~~~~~~~~~~~~~~~~

Expand Down