c# - 如何并行执行 ABP 通知?
问题描述
我目前正在使用 ASP.NET 样板模式,效果很好。我可以毫无问题地发送通知。
我现在遇到的问题是发送大量通知。有什么方法可以并行执行 ABP 通知,或者有什么建议可以让它更快执行吗?
任何帮助将不胜感激。
// AppNotifier.cs
public void ContactTransferred(long userId)
{
var notificationData = new Abp.Notifications.NotificationData();
_notificationPublisher.Publish(
AppNotificationNames.ContactTransferredAlert,
notificationData,
severity: NotificationSeverity.Info,
userIds: new long[] { userId }
);
}
// Usage
private readonly IAppNotifier _appNotifier;
foreach (Contact c in cList) // cList has 2000+ count
{
_appNotifier.ContactTransferred(c.Id);
}
解决方案
你为什么不这样做
// AppNotifier.cs
public void ContactTransferred(long[] userIdList)
{
var notificationData = new Abp.Notifications.NotificationData();
_notificationPublisher.Publish(
AppNotificationNames.ContactTransferredAlert,
notificationData,
severity: NotificationSeverity.Info,
userIds: userIdList
);
}
// Usage
private readonly IAppNotifier _appNotifier;
var contactIdList = cList.Select(c=>c.Id).ToArray();
_appNotifier.ContactTransferred(contactIdList );
推荐阅读
- java - JUnit 测试 SpringJUnit4ClassRunner
- javascript - Node.js如何从异步回调中返回一个数组以在另一个文件中使用
- csv - 按列值拆分 CSV,并保留标题
- python - 在熊猫的其他列中以百分比迭代地增加列
- pivot - PIVOT 函数在 SQLCMD 中不起作用
- vba - 如果查询已经存在,则删除整个查询
- .net - 令人困惑的“找不到服务器或无法访问服务器。” 错误,但仅适用于某些用户
- sql - 行级安全性:相同的查询在测试环境中运行的时间更短,并且在 PROD 中执行的时间很长
- angular - 为 Cloud Functions 执行函数部署时出错
- python-3.x - 使用熊猫不改变格式的平均时间