Search code examples
c#.netnotificationssignalraspnetboilerplate

ABP real-time notification system UserId is null


I am trying to use the real-time notification. I tried all examples but when I SendNotificationsAsync, my client doesn't receive it.

Also, AbpNotifications table is always empty.

Startup:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        GlobalHost.DependencyResolver.UseRedis("redis", 6379, "", "ChecklistCache");
        app.MapSignalR();
    }
}

Sub:

public async Task Subscribe_NewAlert(int? tenantId, long userId)
{
    await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(tenantId, userId), "NewAlert");
}

Pub:

public async Task Publish_NewAlert(string alert)
{
    var msg = new MessageNotificationData($"New alert created! {alert}");
    await _notiticationPublisher.PublishAsync("NewAlert", msg, severity: NotificationSeverity.Info);
}

My job:

[Abp.Domain.Uow.UnitOfWork]
public override void Execute(UserIdentifier args)
{
    var notifications = _userNotificationManager.GetUserNotifications(args);
    Abp.Threading.AsyncHelper.RunSync(() => _realTimeNotifier.SendNotificationsAsync(notifications.ToArray()));
}
  1. I checked _realTimeNotifier and my UserId is null, but the IOnlineClientManager sets an user automatically. Where can I set my user ID?

  2. To use the ABP notification system, must I have all the common tables that ABP creates? (AbpUser, AbpTenant, AbpRoles, permissions, etc.) Can I change those tables' names and column names? If I use external login and I don't have all that info, do I still need those tables?

  3. When I set my ID at execution time, it works. Also, after the notification is shown, it's not deleted from database, so it is showing every time. Must I delete manually?

Let me try to clarify what I need:

  • Every user that logs on to my website will subscribe to "NewAlert".

  • My API receives "NewAlerts" so that API will need to push this alert to all subscribers. But after that, I need to send the real-time notification to users on the website. That I don't know how to do from my Web API.

Now it is working, after I implemented authentication to my site. But my problem now is that my notifications don't expire. Every time I publish a notification, I show to my client all notifications that are on AbpUserNotifications table.

When do notifications expire? My understanding is that when I publish a notification, a record is created on table AbpUserNotifications and then I show to the client. But when I publish another notification, it is showing TWO notifications to my client. Do I need to control my notifications manually?


Solution

  • Real-time notifications

    I checked _realTimeNotifier and my UserId is null, but the IOnlineClientManager sets an user automatically, where can I set my user id?

    It is automatically set from a cookie or a JWT token by the authentication (authorization) system.

    Persistent notifications

    to use the abp notification system I must have all the common tables that abp framework creates? (abpUser, AbpTenant, AbpRoles, permissions, etc) I can change those tables names and columns names too? And if I use external login, I don't have all that info, still need those tables?

    No, you don't need all the tables. You can implement your own INotificationStore and services.

    Module Zero, which implements the store using repositories, creates and uses the common tables.

    External login does create a user in a tenant in your application. That's how most applications work.

    When I set my ID at execution time works, also after the notification is shown, its not deleted from database, so is showing every time, I must delete manually?

    Now is working, after I implemented authentication to my site, but my problem now is that my notifications dont expire, everytime I publish a notifications is show to my Client I notifications that is on AbpUserNotifications table.

    When Notifications expire? My understanding is that when I publish a notification a record is created on Table AbpUserNotifications and them I show to the client, but when I publish another notifications is showing TWO notify to my client. I need to control my notifications manually?

    Notifications don't expire. You should mark it as read (similar to Stack Overflow) or delete it.