locked
How do I differentiate between different message types? RRS feed

  • Question

  • User-1158769213 posted

    I'm just looking at SignalR for ASP.NET Core, and have the following scenario. The site will be used for various sales campaigns, and each campaign will need messages of different types, eg sale made, campaign target reached, etc.

    I've looked at the tutorials and getting started guides, but they all seem to focus on simple applications (how many chat clients do they think we need?), and so don't seem to address questions like this.

    Anyone able to advise. To be specific:

    1. a campaign page should only receive messages relevant to that campaign
    2. it should be able to distinguish between different types of messages, as mentioned above

    Thanks for any help you can give.

    Tuesday, May 14, 2019 5:34 PM

Answers

  • User475983607 posted

    Any reason to choose one over the other? The first option is much simpler, but I suspect will result in more messages being sent out. I'm not if this is actually an issue.

    The number of message does not change. Broadcast messages are sent over every connection.  Grouping allows for sending messages to a specific group of connections.   

    It is up to you to find a determine what's best for your application.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 15, 2019 12:44 PM

All replies

  • User475983607 posted

    Yossu

    a campaign page should only receive messages relevant to that campaign

    Why can't you use a specific Hub method for the campaign?  Or pass a campaign type parameter to the Hub method?  

    Yossu

    it should be able to distinguish between different types of messages, as mentioned above

    Similar to 1, either use specific methods or pass state to the method like the message type.

    The SignalR docs cover a wide range of topic including group and user management which might be helpful.

    https://docs.microsoft.com/en-us/aspnet/core/signalr/groups?view=aspnetcore-2.2

    Tuesday, May 14, 2019 5:46 PM
  • User61956409 posted

    Hi Yossu,

    If you want that users on different campaign pages could receive messages relevant to that campaign, you can map connectionId to each user, and then you can push specific messages to specific connected clients based on connectionIds, like below.

    await Clients.Clients(connectionIds).SendAsync("ReceiveMessage", message);

    Besides, as mgebhard mentioned, you can create group for each campaign, and then you can add user(s) who connected from a specific campaign page to a specific group, so that you can send messages to all users in that group.

    await Clients.Group("group_name_here").SendAsync("ReceiveMessage", message);

    With Regards,

    Fei Han

    Wednesday, May 15, 2019 2:28 AM
  • User-1158769213 posted

    Hello,

    Thanks for the reply. Please can you clarify something for me.

    I'm trying to work out if there is any difference between sending the message to everyone, and including the campaign ID, and having the client code check if the ID matches their current campaign (and ignoring the message if not) against creating a group for each campaign, and sending messages for each campaign to its own group.

    Any reason to choose one over the other? The first option is much simpler, but I suspect will result in more messages being sent out. I'm not if this is actually an issue.

    Thanks again, please let me know what you think.

    Wednesday, May 15, 2019 12:34 PM
  • User475983607 posted

    Any reason to choose one over the other? The first option is much simpler, but I suspect will result in more messages being sent out. I'm not if this is actually an issue.

    The number of message does not change. Broadcast messages are sent over every connection.  Grouping allows for sending messages to a specific group of connections.   

    It is up to you to find a determine what's best for your application.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 15, 2019 12:44 PM
  • User-1158769213 posted

    OK, thanks. In that case, I may as well go for the simpler approach. Simple = less bugs :)

    Wednesday, May 15, 2019 12:58 PM