1

How can I get Online users at server side, to send notifications only to Online users, using a background job?

Background job:

public async Task SendNotifications()
{
    await _backgroundJobManager.EnqueueAsync<NotificationJob,
        UserIdentifier>(new UserIdentifier(_session.TenantId, _session.UserId.Value), delay: TimeSpan.FromSeconds(3));
}

public override void Execute(UserIdentifier args)
{
    var notifications = _userNotificationManager.GetUserNotifications(args);    
    Abp.Threading.AsyncHelper.RunSync(() => _realTimeNotifier.SendNotificationsAsync(notifications.ToArray()));
}

My Job is on a API where I don't have my session with user info, so I want to get all Online users to publish notifications only to them and after that call my job to notify them.

  1. Does Module Zero by default uses Redis ? As Alper said "No".
  2. I need to connect to SignalR on my API too ? Adding app.MapSignalR(); to my WebApi startupseems to work, but sometimes doesn't, I am missing something
  3. How can I get Online users at web api (server side) ? An alternative I found was to get all subscriptions (GetSubscriptionsAsync) and there I have my userId to send the notifications. var onlineClients = _onlineClients.GetAllClients(); is returning null

Thanks

Bruno
  • 135
  • 3
  • 10
  • 1
    for online users inject `IOnlineClientManager`. https://aspnetboilerplate.com/Pages/Documents/SignalR-Integration#online-clients – Alper Ebicoglu Dec 12 '18 at 06:35
  • 1.Does Module Zero by default uses Redis ? (NO) – Alper Ebicoglu Dec 12 '18 at 06:36
  • https://stackoverflow.com/questions/48980615/calling-signalr-service-from-a-backgroundworker-in-abp – Alper Ebicoglu Dec 12 '18 at 06:38
  • Sorrry, What a mean by server side is from an API. Doing from my website server side is working, but when I move my code to a web api doesn’t work, 2 reasons: No session info(user and tenant) and i cant get online clients when I call my notifier (IOnlineClientManager). – Bruno Dec 12 '18 at 11:23
  • so create a new API method in your abp project that gives you online users. – Alper Ebicoglu Dec 13 '18 at 06:48
  • @AlperEbicoglu but How I get those online users that are connected to signalr hub? – Bruno Dec 13 '18 at 12:02
  • IOnlineClientManager https://aspnetboilerplate.com/Pages/Documents/SignalR-Integration#online-clients – Alper Ebicoglu Dec 13 '18 at 12:08
  • Sometimes the background job runs and sometimes not, using Hangfire or not. And sometimes `IOnlineClientManager` has users and sometimes not. I am missing some configuration ? Do I need `app.MapSignalR();`at both WebSite and WebApi ? – Bruno Dec 13 '18 at 15:32
  • Noting yet, my signalr and background job is intermittent, – Bruno Dec 17 '18 at 19:09
  • Yes, we took a different approach, not using jobs anymore . thanks – Bruno Mar 18 '19 at 14:55

0 Answers0