在 MVC 应用程序中排队电子邮件

Queuing Emails in MVC Application

我是为我们的组织构建专有学习管理系统的团队的一员。当用户注册在线课程时,我们会向用户发送一封电子邮件,其中包含有关登录以参加他们的课程的说明。当大量注册用户时,显然这会导致一些性能问题。我正在研究开发一个用于排队电子邮件然后异步发送它们的框架。

我们的平台是通过 Azure 网络应用程序和 Azure SQL 数据库部署的。它是用 .NET MVC 编写的,我们通过 SMTP 发送电子邮件。

有没有人对最佳做法有任何建议,或者最有效的方法是什么?我研究了 Azure 服务总线、第三方开源解决方案(例如 Hangfire),并编写了一个标准控制台应用程序来处理要发送的电子邮件的数据库 table。

你走在正确的道路上。 Azure Service Bus 和 Azure Functions 将满足您的需求。流程将是:

  1. 用户注册
  2. 消息发送到服务总线队列
  3. Azure 函数触发器处理队列消息并发送电子邮件。

Azure Service Bus bindings for Azure Functions

Get started with Service Bus queues

如果您决定使用 Hangfire,最好使用 Hangfire.Azure.ServiceBusQueue 包。

Adds support for using Azure Service Bus Queues with Hangfire's SQL storage provider to reduce latency and remove the need to poll the database for new jobs.

All job data continues to be stored and maintained within SQL storage, but polling is removed in favour of pushing the job ids through the service bus.