c# - notificationPublisher.PublishAsync 未向租户发送通知
问题描述
我正在尝试向租户发送通知,但没有任何反应,甚至没有记录输入到“[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;
}
在发布前订阅,代码如下,这次通知没有插入主机数据库,也没有插入租户数据库
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
));
解释
实现细节:如果两者tenantIds
和userIds
都没有设置,则PublishAsync
使用AbpSession.TenantId
.
if (tenantIds.IsNullOrEmpty() && userIds.IsNullOrEmpty())
{
tenantIds = new[] { AbpSession.TenantId };
}
推荐阅读
- angular - 如何获取对角度结构指令容器内元素的引用
- macros - 如何将调试消息传递给 SystemVerilog 中的宏
- android - 离子:在Android中初始加载后未获取数据在浏览器中正常工作
- android-management-api - 当 kioskCustomLauncherEnabled 开启时,清除 FORCE_INSTALLED 应用上的应用数据和缓存
- amazon-web-services - AWS Lambda Container Image for Ruby Code -- 如何使用 docker run 在本地进行测试
- vue.js - VueJS 导入和解析 CSV(仅限前端)
- css - 高度为 100% 的 div 未扩展以匹配父 div
- c# - 有没有更好的方法来用泛型类型实现这个 IEquatable 接口
- tfs - 取消发布并开始新的发布后,无法创建发布工件目录错误
- javascript - ES6 速记会影响抽象吗?