首页 > 解决方案 > 如何并行执行 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);
}

标签: c#notificationssignalraspnetboilerplate

解决方案


你为什么不这样做

// 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 );

推荐阅读