Base solution for your next web application
Open Closed

Appnotifier : notification sent twice #7052


User avatar
0
Ricavir created

Hi,

I'm using AppNotifier in several ways in my app. I send notifications directly to users and, in other cases, I send notifications to a tenant (then to all subscribed users).

The last case, sending notification to a tenant, is creating notification twice in database... but my code is only run once.

Here is the code in AppNotifier.cs :

public async Task SchedulerNewInvoiceForecastCreatedAsync(int? tenantId, int invoiceForecastCount)
        {
            var notificationData = new LocalizableMessageNotificationData(
                new LocalizableString(
                    "SchedulerNewInvoiceForecastCreatedNotificationMessage",
                    LogisavConsts.LocalizationSourceName
                    )
                );

            notificationData["invoiceForecastCount"] = invoiceForecastCount;

            await _notificationPublisher.PublishAsync(AppNotificationNames.SchedulerNewInvoiceForecastCreated, notificationData, severity: NotificationSeverity.Success, tenantIds: new[] { tenantId });
        }

Notifications that are created twice have just 1 second difference in their CreationTIme property : 2019-05-18 03:57:49.0409870 2019-05-18 03:58:03.4540753

As described in the begining, the same code sent to specific users is creating only one notification as expected.

Using Zero 5.5.1

Tks for your support

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Very strange, have you set a breakpoint to determine that the code has only been called once?

    You can set a random number to see if it is called twice or is inserted twice.

    notificationData["invoiceForecastCount"] = Guid.NewGuid();

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    Ricavir created

    Hi,

    I'm still having the same problem.

    To identify the root cause, I've added a Logger trace on the method that sends notification... and I only got one log.

    The method :

    public async Task SchedulerNewInvoiceForecastCreatedAsync(int? tenantId, int invoiceForecastCount)
            {
                Logger.Warn("SchedulerNewInvoiceForecastCreatedAsync notification at " + DateTime.Now.ToString() + " : tenantId = " + tenantId.ToString());
    
                var notificationData = new LocalizableMessageNotificationData(
                    new LocalizableString(
                        "SchedulerNewInvoiceForecastCreatedNotificationMessage",
                        LogisavConsts.LocalizationSourceName
                        )
                    );
    
                notificationData["invoiceForecastCount"] = invoiceForecastCount;
    
                await _notificationPublisher.PublishAsync(AppNotificationNames.SchedulerNewInvoiceForecastCreated, notificationData, severity: NotificationSeverity.Success, tenantIds: new[] { tenantId });
            }
    

    The log

    INFO  2019-07-26 01:09:06,776 [49   ] soft.AspNetCore.Hosting.Internal.WebHost - Request finished in 10.5639ms 200 text/html
    WARN  2019-07-26 01:09:58,191 [28   ] N_SOFT.Logisav.Notifications.AppNotifier - SchedulerNewInvoiceForecastCreatedAsync notification at 7/26/2019 1:09:58 AM : tenantId = 15
    INFO  2019-07-26 01:11:02,942 [50   ] soft.AspNetCore.Hosting.Internal.WebHost - Request starting HTTP/1.1 GET http://----------------.com/account/login  
    
    

    The database

    As you can see, all tenant users have duplicated entries in AbpUserNotifications.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    ismcagdas created
    Support Team
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)