Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal R callback not working #2135

Closed
oghaleetomu opened this issue May 17, 2017 · 11 comments
Closed

Signal R callback not working #2135

oghaleetomu opened this issue May 17, 2017 · 11 comments
Labels

Comments

@oghaleetomu
Copy link

Please I developed an application using a the latest version of abp, did signalr r integrate, but my client method in my JavaScript are not been call nor executed, and no error is been encountered. Any suggestions on how to solve this issue

@hikalkan
Copy link
Member

Hi,

Can you share some code. A general message like "not working" does not help us to understand your special case since for most of us it just works.

Also, please write your help requests to the forum: https://forum.aspnetboilerplate.com/viewforum.php?f=2

@mkgn
Copy link

mkgn commented Jun 6, 2018

Thought to re-open this because I experience a similar problem. This is what I did.

  1. First, went through this, this and this articles to make sure initial SignalR setup is done properly on server/client side.

  2. Running the angular project I see that it properly connects to the SignalR server.

  3. To test the alerting; I raise a global notification at the server using
    await _notificationPublisher.PublishAsync("abp.notifications.received", new MessageNotificationData($"Invitation sent to {recipient}"));

  4. In app.component, I have
    abp.event.on('abp.notifications.received', userNotification => {
    console.log("received");
    .....
    });

Since I use the same notification name (abp.notifications.received) on server and client, I was expecting it to show the console.log message in client side. But it doesn't. No errors on both ends. Am I raising the events correctly on server side?

@acjh
Copy link
Contributor

acjh commented Jun 6, 2018

As per the documentation, you need to subscribe to the notification name or publish to specific users.
The notification name on the server (your choice) is unrelated to the event name on the client (fixed).

@mkgn
Copy link

mkgn commented Jun 6, 2018

After you pointed out about subscribing to my event (raised at the server) I changed the code as below.

  1. In one of my methods in server, I raise a general notification as in this article (under publish notifications)

await _notificationPublisher.PublishAsync("mail.sent", new MessageNotificationData($"Invitation sent to {to}")
As I understand my notification name becomes "mail.sent" which I need to subscribe to from the client.

  1. In my Angular client, I added below code to app.component.ts
    abp.event.on('mail.sent', function (item) {
    console.log(item);
    });

Still it doesn't work :(

I am 100% sure that SignarR libraries are all set and it connects properly to server. Just that it doesn't seem to publish/subscribe.

@acjh
Copy link
Contributor

acjh commented Jun 6, 2018

By subscribe, I mean subscribe to notifications:

//Subscribe to a general notification
public async Task Subscribe_SentFrendshipRequest(int? tenantId, long userId)
{
    await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(tenantId, userId), > "SentFrendshipRequest");    
}

As I understand my notification name becomes "mail.sent" which I need to subscribe to from the client.

  1. In my Angular client, I added below code to app.component.ts
abp.event.on('mail.sent', function (item) {
    console.log(item);
});

Still it doesn't work :(

I am 100% sure that SignarR libraries are all set and it connects properly to server. Just that it doesn't seem to publish/subscribe.

The notification name on the server (your choice — mail.sent) that you subscribe is unrelated to the event name on the client (fixed — abp.notifications.receive) that you listen. You didn't subscribe.

@mkgn
Copy link

mkgn commented Jun 7, 2018

Ok, I think i am not getting the documentation right to my brain. What I am trying to do is to push a message to browser from the server ApplicationService when an email is sent successfully from the server.

So, to get myself clarified, if I can raise the event from the server (from inside a method in an ApplicationService like;
await _notificationPublisher.PublishAsync("event-name", new MessageNotificationData(""));

does the ABP framework publish that to every connected client(unless I specifically mention a tenant/userid)? If so, at the client side it should fire;
abp.event.on('abp.notifications.received') script is it? And then inside that I should parse the received data as mentioned in this client side structure?

What I am wondering is why i should subscribe again on the server as you have mentioned below;
public async Task Subscribe_SentFrendshipRequest(int? tenantId, long userId)
{
await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(tenantId, userId), > "SentFrendshipRequest");
}
I need to subscribe from the client script isn't it?

Do you have a sample that works?

@acjh
Copy link
Contributor

acjh commented Jun 7, 2018

does the ABP framework publish that to every connected client(unless I specifically mention a tenant/userid)?

If you don't specify userIds, ABP publishes to subscribers. If you don't subscribe, you don't receive.

I need to subscribe from the client script isn't it?

I've already made clear the difference between subscribe and listen.
In fact, you don't need to listen on the client side because ABP does.
Can you listen to what I've been saying and subscribe on the server?

@mkgn
Copy link

mkgn commented Jun 8, 2018

I am very sorry If my question(s) annoy you. It's just that my head was used to map with how I got a similar thing done with node + socksjs. In that I simply publish an event at server and any client code subscribe to that event and things simply works.

Anyway let me show my code sample in brief (what I did after your above comment).

I have a service done as AppService. In this I have the publish method

    public async Task Publish_SentMailInvitation(string data)
    {
    var notification= new MessageNotificationData(data");
    await _notificationPublisher.PublishAsync("SentMailInvitation", notification, severity: NotificationSeverity.Info);
    }

I call above method from elsewhere in the code.

In another service, I subscribe as below.

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

This is similar to what the documentation says. But I don't see anything happening. No errors either. A sample code would help me to understand what I am doing wrong.

@acjh
Copy link
Contributor

acjh commented Jun 8, 2018

Did you subscribe before publishing? Is subscription saved in DB?

@mkgn
Copy link

mkgn commented Jun 9, 2018

Ah! Great blunder. No it's not saved in the db. Because I haven't used INotificatioinStore! I was under the impression that there is a default in-memory pub/sub setup!!!!

Ok, so let me see whether I get this right.

  1. I need to implement INotification store first? (since it's not implemented in free version?)

  2. Register the entity in DbContext and then also register for DI?

  3. Then only I can publish events? So at which point should I write the notification data to DB? Does it happen automatically when I call PublishAsync()? (Assuming I have implemented NotificationStore)?

  4. I can only subscribe to those events that's in the Db? (If so why Abp doesn't throw / give a message saying that the event I am trying to subscribe doesn't exist?)

  5. If all goes well and the records exist in the Db, rest of the broadcasting work is handled by Abp automatically? (Do I have to implement anything else?

@ismcagdas
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants