notificationPublisher.PublishAsync 没有向租户发送通知

notificationPublisher.PublishAsync is not sending notification to tenant

我正在尝试向租户发送通知,但没有任何反应,甚至没有输入“[AbpNotifications]”的记录 table。不知道哪里出了问题

using (UnitOfWorkManager.Current.SetTenantId(tenantId))
{
    var notificationData = new LocalizableMessageNotificationData(new LocalizableString("OverDueTaskManagementReminderMessage", DConsts.LocalizationSourceName));
    notificationData["a"] = "Accomplish By" + ws.WorkStream.AccomplishOn.ToString("dd/MM/yyyy hh:mm");
    notificationData["pn"] = user.Surname + "" + user.Name;
    notificationData["tmp"] = WorkStreamPriority.Urgent.ToString();

    AsyncHelper.RunSync(() => _notificationPublisher.PublishAsync(AppNotificationNames.OverDueTaskManagementReminder,
        notificationData, severity: NotificationSeverity.Info));

    UnitOfWorkManager.Current.SaveChanges();
    return true;
}

发布前订阅,代码如下,这次通知没有插入主机数据库和租户数据库

await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(tenantId, (long)(AbpSession.UserId??1)), AppNotificationNames.OverDueTaskManagementReminder);

            var result = _notificationPublisher.PublishAsync(AppNotificationNames.OverDueTaskManagementReminder,
                notificationData, severity: NotificationSeverity.Info, tenantIds: new[] { tenantId }.Select(x => (int?)Convert.ToInt32(x)).ToArray()).IsCompleted;
                return result;

tenantIds 显式传递给 PublishAsync 而不是 UnitOfWorkManager.Current.SetTenantId
这会将通知发布给 tenantIds 订阅的 用户,而不是会话的租户。

AsyncHelper.RunSync(() => _notificationPublisher.PublishAsync(
    AppNotificationNames.OverDueTaskManagementReminder,
    notificationData,
    severity: NotificationSeverity.Info,
    tenantIds: new[] { tenantId } // Add this
));

说明

实现细节:如果tenantIdsuserIds都没有设置,那么PublishAsync使用AbpSession.TenantId

if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty())
{
    tenantIds = new[] { AbpSession.TenantId };
}