2 回答

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊
最終,我應(yīng)用了以下解決方案:
<?php
/**
* Author: writ3it
*/
namespace App\Maintenance\Messenger;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\MessageBusInterface;
class FailedMessageListener implements EventSubscriberInterface
{
/**
* @var MessageBusInterface
*/
private MessageBusInterface $bus;
public function __construct(MessageBusInterface $bus)
{
$this->bus = $bus;
}
public function onMessageFailed(WorkerMessageFailedEvent $event)
{
if ($event->willRetry()) {
return;
}
$envelope = $event->getEnvelope();
$message = $envelope->getMessage();
$subject = sprintf("Message added to failed transport. Message: %s", \get_class($message));
$content = serialize($message);
$notification = new FailedMessageNotificationEvent();
$notification->setSubject($subject)
->setContent($content);
$this->bus->dispatch($notification);
}
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
WorkerMessageFailedEvent::class => ['onMessageFailed', -256],
];
}
}
FailedMessageNotificationEvent是一條將被我的郵件處理程序捕獲的消息。該類FailedMessageListener應(yīng)標(biāo)記為kernel.event_subscriber或自動(dòng)配置。
我沒(méi)有使用中間件,因?yàn)?Messenger 直接將消息發(fā)送到失敗的傳輸,沒(méi)有中間件。

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊
我認(rèn)為不可能通過(guò)配置來(lái)完成,但您可以創(chuàng)建自定義中間件并自行發(fā)送電子郵件。
- 2 回答
- 0 關(guān)注
- 183 瀏覽
添加回答
舉報(bào)