diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs
index 8a7c2c632..440a8de6c 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSender.cs
@@ -17,13 +17,15 @@ namespace LINGYUN.Abp.Notifications
/// 用户列表,为空标识发给所有订阅用户
/// 租户
/// 严重级别
+ /// 使用通知提供程序
/// 通知标识
Task SendNofiterAsync(
string name,
NotificationData data,
IEnumerable users = null,
Guid? tenantId = null,
- NotificationSeverity severity = NotificationSeverity.Info);
+ NotificationSeverity severity = NotificationSeverity.Info,
+ IEnumerable useProviders = null);
///
/// 发送模板通知
///
@@ -32,12 +34,14 @@ namespace LINGYUN.Abp.Notifications
/// 用户列表,为空标识发给所有订阅用户
/// 租户
/// 严重级别
+ /// 使用通知提供程序
///
Task SendNofiterAsync(
string name,
NotificationTemplate template,
IEnumerable users = null,
Guid? tenantId = null,
- NotificationSeverity severity = NotificationSeverity.Info);
+ NotificationSeverity severity = NotificationSeverity.Info,
+ IEnumerable useProviders = null);
}
}
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs
index b4b750853..4219d1508 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSender.cs
@@ -61,9 +61,10 @@ namespace LINGYUN.Abp.Notifications
NotificationData data,
IEnumerable users = null,
Guid? tenantId = null,
- NotificationSeverity severity = NotificationSeverity.Info)
+ NotificationSeverity severity = NotificationSeverity.Info,
+ IEnumerable useProviders = null)
{
- return await PublishNofiterAsync(name, data, users, tenantId, severity);
+ return await PublishNofiterAsync(name, data, users, tenantId, severity, useProviders);
}
public async virtual Task SendNofiterAsync(
@@ -71,9 +72,10 @@ namespace LINGYUN.Abp.Notifications
NotificationTemplate template,
IEnumerable users = null,
Guid? tenantId = null,
- NotificationSeverity severity = NotificationSeverity.Info)
+ NotificationSeverity severity = NotificationSeverity.Info,
+ IEnumerable useProviders = null)
{
- return await PublishNofiterAsync(name, template, users, tenantId, severity);
+ return await PublishNofiterAsync(name, template, users, tenantId, severity, useProviders);
}
protected async virtual Task PublishNofiterAsync(
@@ -81,16 +83,18 @@ namespace LINGYUN.Abp.Notifications
TData data,
IEnumerable users = null,
Guid? tenantId = null,
- NotificationSeverity severity = NotificationSeverity.Info)
+ NotificationSeverity severity = NotificationSeverity.Info,
+ IEnumerable useProviders = null)
{
var eto = new NotificationEto(data)
{
Id = DistributedIdGenerator.Create(),
TenantId = tenantId,
- Users = users?.ToList(),
+ Users = users?.ToList() ?? new List(),
Name = name,
CreationTime = Clock.Now,
- Severity = severity
+ Severity = severity,
+ UseProviders = useProviders?.ToList() ?? new List()
};
if (UnitOfWorkManager.Current != null)
diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs
index fd6bfcb93..b9651002d 100644
--- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs
+++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationEto.cs
@@ -40,6 +40,14 @@ namespace LINGYUN.Abp.Notifications
/// 如果未指定用户列表,应该在事件订阅程序中过滤所有订阅此通知的用户
///
public List Users { get; set; } = new List();
+ ///
+ /// 用户指定通知提供程序列表
+ ///
+ ///
+ /// 注:
+ /// 如果指定了通知提供程序,将只使用特定的提供程序发布通知
+ ///
+ public List UseProviders { get; set; } = new List();
public NotificationEto() : base()
{
}
diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs
index e96f0996b..5df5c58d0 100644
--- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs
+++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs
@@ -159,7 +159,11 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed
var providers = Enumerable.Reverse(NotificationPublishProviderManager.Providers);
// 过滤用户指定提供者
- if (notification.Providers.Any())
+ if (eventData.UseProviders.Any())
+ {
+ providers = providers.Where(p => eventData.UseProviders.Contains(p.Name));
+ }
+ else if (notification.Providers.Any())
{
providers = providers.Where(p => notification.Providers.Contains(p.Name));
}
@@ -203,7 +207,11 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed
var providers = Enumerable.Reverse(NotificationPublishProviderManager.Providers);
// 过滤用户指定提供者
- if (notification.Providers.Any())
+ if (eventData.UseProviders.Any())
+ {
+ providers = providers.Where(p => eventData.UseProviders.Contains(p.Name));
+ }
+ else if (notification.Providers.Any())
{
providers = providers.Where(p => notification.Providers.Contains(p.Name));
}
diff --git a/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/FakeNotificationSender.cs b/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/FakeNotificationSender.cs
index 713e2522d..5175ae528 100644
--- a/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/FakeNotificationSender.cs
+++ b/aspnet-core/tests/LINGYUN.Abp.Notifications.Tests/LINGYUN/Abp/Notifications/FakeNotificationSender.cs
@@ -60,7 +60,8 @@ public class FakeNotificationSender : INotificationSender, ITransientDependency
NotificationData data,
IEnumerable users = null,
Guid? tenantId = null,
- NotificationSeverity severity = NotificationSeverity.Info)
+ NotificationSeverity severity = NotificationSeverity.Info,
+ IEnumerable useProviders = null)
{
var notification = NotificationDefinitionManager.GetOrNull(name);
if (notification == null)
@@ -88,7 +89,11 @@ public class FakeNotificationSender : INotificationSender, ITransientDependency
var providers = Enumerable.Reverse(NotificationPublishProviderManager.Providers);
- if (notification.Providers.Any())
+ if (useProviders?.Any() == true)
+ {
+ providers = providers.Where(p => useProviders.Contains(p.Name));
+ }
+ else if (notification.Providers.Any())
{
providers = providers.Where(p => notification.Providers.Contains(p.Name));
}
@@ -106,7 +111,8 @@ public class FakeNotificationSender : INotificationSender, ITransientDependency
NotificationTemplate template,
IEnumerable users = null,
Guid? tenantId = null,
- NotificationSeverity severity = NotificationSeverity.Info)
+ NotificationSeverity severity = NotificationSeverity.Info,
+ IEnumerable useProviders = null)
{
var notification = NotificationDefinitionManager.GetOrNull(name);
if (notification == null)
@@ -149,7 +155,11 @@ public class FakeNotificationSender : INotificationSender, ITransientDependency
var providers = Enumerable.Reverse(NotificationPublishProviderManager.Providers);
// 过滤用户指定提供者
- if (notification.Providers.Any())
+ if (useProviders?.Any() == true)
+ {
+ providers = providers.Where(p => useProviders.Contains(p.Name));
+ }
+ else if (notification.Providers.Any())
{
providers = providers.Where(p => notification.Providers.Contains(p.Name));
}