简体   繁体   English

Aws sns 不适用于 Laravel 排队通知

[英]Aws sns not working with Laravel queued notifications

I have a Laravel 6.0 project sending emails with ses driver.我有一个 Laravel 6.0 项目使用 ses 驱动程序发送电子邮件。

To track bounces, complaints and so on, I use sns.为了跟踪退回、投诉等,我使用 sns。

All the configurations are in place.所有配置都已到位。 If a mail is sent, sns messages are correctly generated by Amazon and received by Laravel.如果发送邮件,则 Amazon 会正确生成 sns 消息并由 Laravel 接收。 This is because in config/service.php there is the ConfigurationSetName value.这是因为在 config/service.php 中有 ConfigurationSetName 值。

Problems begin when it comes to queued notifications sent by email.当涉及到由 email 发送的排队通知时,问题就开始了。

Only for such generated email, the sns workflow doesn't even starts.仅对于此类生成的 email,sns 工作流甚至都不会启动。 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.为了确定 ConfigurationSetName 已设置,我仔细检查了配置的 sintax,但它看起来不是或者 Laravel 忽略了它。

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.关键是我如何实现 ShouldQueue 合约。

I set the ShouldQueue on the notification class itself, not on the mailable class.我在通知 class 本身上设置了 ShouldQueue,而不是在可邮寄的 class 上。 So Laravel fires a notification that get queued.所以 Laravel 会触发一个排队的通知。 Once the queue worker bring up the elaboration, the notification generate a Mailable.一旦队列工作人员提出详细说明,通知就会生成一个 Mailable。 This doesn't work, no SNS notification at all.这不起作用,根本没有 SNS 通知。

Now I moved the ShouldQueue implementation on the Mailable class and this solve the problem.现在我在 Mailable class 上移动了 ShouldQueue 实现,这解决了问题。

So, now Laravel fires the notification that generate the Mailable that get queued.因此,现在 Laravel 触发生成排队的 Mailable 的通知。 When the queue worker get the elaboration, the email is sent and now SNS is working correctly.当队列工作人员获得详细信息时,将发送 email 并且现在 SNS 工作正常。

No other change in the code, just moving the implementing of ShouldQueue from the Notification to the Mailable do the trick.代码中没有其他更改,只需将 ShouldQueue 的实现从 Notification 移至 Mailable 即可。

I'm wondering why... but now it works and to me the implementation seems good.我想知道为什么......但现在它可以工作了,对我来说实施似乎很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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