简体   繁体   中英

Aws sns not working with Laravel queued notifications

I have a Laravel 6.0 project sending emails with ses driver.

To track bounces, complaints and so on, I use sns.

All the configurations are in place. If a mail is sent, sns messages are correctly generated by Amazon and received by Laravel. This is because in config/service.php there is the ConfigurationSetName value.

Problems begin when it comes to queued notifications sent by email.

Only for such generated email, the sns workflow doesn't even starts. No notifications at all. For sure the ConfigurationSetName is set, I double checked the configuration's sintax, but it look like it isn't or like Laravel ignores it.

I repeat, when it comes to simple emails everything works fine. I face the problem only when the emails are generated from queued notifications.

Any help would be very appreciated, I really have no idea where the problem could be.

In the end I found the problem, even if I don't understand the situation.

The point was how I implemented the ShouldQueue contract.

I set the ShouldQueue on the notification class itself, not on the mailable class. So Laravel fires a notification that get queued. Once the queue worker bring up the elaboration, the notification generate a Mailable. This doesn't work, no SNS notification at all.

Now I moved the ShouldQueue implementation on the Mailable class and this solve the problem.

So, now Laravel fires the notification that generate the Mailable that get queued. When the queue worker get the elaboration, the email is sent and now SNS is working correctly.

No other change in the code, just moving the implementing of ShouldQueue from the Notification to the Mailable do the trick.

I'm wondering why... but now it works and to me the implementation seems good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM