Hello, I configure my app to run with HangFire. I can see a job being enqueued. The job is making use of the NotificationPublisher to send a notification to a specific user (testing purpose). The user is never receiving those notifications.
I debugged the code and it works fine.
I also checked the AbpTenantNotifications, it seems those notifications used are not added to the DB.
public class TestingHangFireDomainService : DrcAppDomainServiceBase, ITestingHangFireDomainService
{
private readonly IAppNotifier _appNotifier;
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly UserManager _userManager;
public TestingHangFireDomainService(IAppNotifier appNotifier, UserManager userManager, IUnitOfWorkManager unitOfWorkManager)
{
_appNotifier = appNotifier;
_unitOfWorkManager = unitOfWorkManager;
_userManager = userManager;
}
public async Task NotifyUser()
{
using (_unitOfWorkManager.Begin())
{
var user = _userManager.Users.Where(u => u.Id == 2).FirstOrDefault();
await _appNotifier.SendMessageAsync(user.ToUserIdentifier(), "Testing HangFire", Abp.Notifications.NotificationSeverity.Info);
}
}
}
7 Answer(s)
-
0
Actually I noticed that the notifications are being received. But since I am running in Chrome, Chrome asked me to Allow/Block notifications. So now notifications are appearing as a desktop-popup rather than they appear in the header top-bar notification area. Even if I go to /app/notifications page, they are not stored there at all.
any idea?
-
0
Hi @bilalhaidar,
If you are sending notifications to specific users, they must be saved to AbpUserNotifications table, can you check that ? Also, can you get a result on this code ?
var user = _userManager.Users.Where(u => u.Id == 2).FirstOrDefault();
Thanks.
-
0
Hello @ismcagdas,
The notifications are sent down to the user correctly using both toastr and Desktop notification. The only problem is that they don't appear in the header notification bar as new notifications because it seems they are not being stored in the DB.
Is there any configuration needed to allow notifications to be stored in the DB?
The code below to retrieve user works fine and I am able to get the user object and also showing the Full Name and it works.
await _appNotifier.SendMessageAsync(user.ToUserIdentifier(), $"Testing HangFire {user.FullName}", Abp.Notifications.NotificationSeverity.Success);
The AbpUserNotifications is always not showing those notifications as they are not stored.
(I hard coded the value here because I couldn't get the user object from the AbpSession, it is always null for some reason)
-
0
Hi,
Can you try wrapping your notification sent code in _session.Use statement ? <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Abp-Session#overriding-current-session-values">https://aspnetboilerplate.com/Pages/Doc ... ion-values</a>
Thanks.
-
0
Hello, I tried both codes below. Still nothing is saved in the AbpUserNotifications :(
I am also attaching to you a snapshot from the SQL Profiler. It shows no commands to SQL to actually insert a new record into the AbpUserNotifications.
Can I debug the Notification engine from my machine and see whats happening?
public async Task NotifyUser() { using (_unitOfWorkManager.Begin()) { using (_session.Use(1, null)) { var user = _userManager.Users.Where(u => u.Id == 2).FirstOrDefault(); await _appNotifier.SendMessageAsync(user.ToUserIdentifier(), $"Testing HangFire {user.FullName}", Abp.Notifications.NotificationSeverity.Success); } } }
And
public async Task NotifyUser() { using (_unitOfWorkManager.Begin()) { using (_session.Use(1, 2)) { var user = _userManager.Users.Where(u => u.Id == 2).FirstOrDefault(); await _appNotifier.SendMessageAsync(user.ToUserIdentifier(), $"Testing HangFire {user.FullName}", Abp.Notifications.NotificationSeverity.Success); } } }
-
0
Hi @bilalhaidar,
Can you share your project with us via email ? It will be easier to identify problem on your project.
Thanks.
-
0
Sure. I'll send you the project via email.
Thanks for your assistance.