【问题标题】:notificationPublisher.PublishAsync is not sending notification to tenantnotificationPublisher.PublishAsync 未向租户发送通知
【发布时间】:2020-08-02 20:26:33
【问题描述】:

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

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;
}

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

等待_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;

【问题讨论】:

    标签: c# multi-tenant asp.net-boilerplate


    【解决方案1】:

    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 };
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多