I am trying to display realtime notification in ASP.NET Boilerplate, but it is not sent.
public override async Task<MessagesDto> Create(MessagesCreateDto input)
{
var MessagesCore = ObjectMapper.Map<MessagesCore>(input);
MessagesCore.UserId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.CreationId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.FromUserId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.CreationTime = DateTime.Now;
MessagesCore.LastModificationId = Convert.ToInt32(AbpSession.UserId);
MessagesCore.LastModificationTime = DateTime.Now;
_stateRepository.Insert(MessagesCore);
CurrentUnitOfWork.SaveChanges();
UserIdentifier identifier = new UserIdentifier(1,input.ToUserId);
await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(1, input.ToUserId), "NewMessage");
await _notificationPublisher.PublishAsync("NewMessage", new SentMessageNotificationData("Test", "New Message"), userIds: new[] { identifier });
return MapToEntityDto(MessagesCore);
}
SentMessage
notification data class:
[Serializable]
public class SentMessageNotificationData : NotificationData
{
public string SenderUserName { get; set; }
public string FriendshipMessage { get; set; }
public SentMessageNotificationData(string senderUserName, string friendshipMessage)
{
SenderUserName = senderUserName;
FriendshipMessage = friendshipMessage;
}
}
Data is stored in notification table, but no notification message is displaying in client side.
SignalR code in app.component.ts:
ngOnInit(): void {
if (this.appSession.application.features['SignalR']) {
SignalRHelper.initSignalR();
}
abp.event.on('abp.notifications.received', userNotification => {
abp.notifications.showUiNotifyForUserNotification(userNotification);
if (userNotification.notification.data.type === 'Abp.Notifications.LocalizableMessageNotificationData') {
var localizedText = abp.localization.localize(
userNotification.notification.data.message.name,
userNotification.notification.data.message.sourceName
);
$.each(userNotification.notification.data.properties, function (key, value) {
localizedText = localizedText.replace('{' + key + '}', value);
});
alert('New localized notification: ' + localizedText);
} else if (userNotification.notification.data.type === 'Abp.Notifications.MessageNotificationData') {
alert('New simple notification: ' + userNotification.notification.data.message);
}
//Desktop notification
Push.create("AbpZeroTemplate", {
body: userNotification.notification.data.message,
icon: abp.appPath + 'assets/app-logo-small.png',
timeout: 6000,
onClick: function () {
window.focus();
this.close();
}
});
});
}
Have you added the
Hub Class
in your Project? You need to add a method there. SignalR Communicate mainly throughHub
and send the realtime updates fromClient
Via Hub (Server) and from there to the destination i.e. where the realtime update is to be shown according to your Code.1.0.0-alpha2-final
for .NET Core.2.x
will only be stable in Q1/Q2 2018.Update 1
Abp.AspNetCore.SignalR NuGet package has been published.
Read the documentation for SignalR AspNetCore Integration.
You can try it and make the necessary changes to your files.
Or just wait for it to be released.Update 2
You can now download
v3.4.1
of the template with the AspNetCore.SignalR preview.Did you create an event in client side to handle notification messages. You should set
abp.notifications.received
event like this;You can find the more detailed explanation here.
[Update]
You need to integrate SignalR to get realtime notification works. Following the document here
Your code seems to be correct. If you see the record in database, then BackgroundJob might not be running to process the record. Put a debugger on background job to see if it traverses the record.
By the way, I see that you are passing 1 as tenant Id. So if you expect to get the notification from a tenant rather than default tenant, it'll never be delivered.