Base solution for your next web application
Open Closed

Publish Notification from Tenant to Host #9383


User avatar
0
BigCDogCrew created

What is the proper way to publish a notification from a tenant user event to the host? Any host user that subscribes to the notification should receive it.

Using a null in the tenantIds array causes AbpBackgroundJobs to fail when attempting to process the AbpNotifications table.

await _notificationPublisher.PublishAsync(
    notificationName,
    notification,
    severity: NotificationSeverity.Info,
    tenantIds: new int?[] { null }
);

While we are at it...can someone explain the logic to me for use of the EntityId, EntityTypeAssemblyQualifiedName, & EntityTypeName fields in the AbpNotificationSubscription table? It seems as though an exact match between these fields and the notification EntittyIdentifier parameter will allow the notification to occur. But if the notification EntityIdentifier parameter is specified and the subscription specifies nulls across those fields, then the match does not happen and no notification is distributed.

From my perspective, the logic should be this...(but please correct me where I'm wrong).

The publisher provides as much information as is available and allows the subscriber to decide what information is desired. If the notification is unrelated to a specific object, then those Entity-related fields do not get populated.  But if the notification is related to a specific object, then those fields will be populated.  The subscriber (with the help of UI controls) uses the chart below to decide the level of information used to filter the notifications. <br> | No. | EntityId | EntityTypeAssemblyQualifiedName | EntityTypeName | NotificationName | Result | | --- | -------- | ------------------------------- | -------------- | ---------------- | ------ | | 1 | null | null | null | set | Receive any notification of the specified name, even if EntityIdentifier parameter has been specified. | | 2 | null | null | set | set | Receive any notification of the specified name, but only when EntityTypeName matches the EntityIdentifier parameter of the notification. Theoretically, the same class name could be loaded from different assemblies and all would apply.   For example: System.Reports and Custom.Reports assemblies could each have implementations of CommonReportNotifier.  Perhaps not likely...but possible. | | 3 | set | null | set | set | Same as #2 above, but in this case, the entityId must match the specific record. This is the best scenario to use for placing a "watch" on an object to monitor changes. | | 4 | null | set | set/null | set | Same as #2, but in this case, notifications would be distributed only for a specific assembly. | | 5 | set | set | set/null | set | Fully-qualified match.  The user would receive notifications only for a very specific object instance of a specific type in a specific assembly. |


1 Answer(s)