1 Reply Latest reply on Feb 4, 2014 10:37 AM by mbarkley

    Need Help with Broadcast messages

    rathiandi

      Hello,

       

      I have a small requirement and would appreciate if someone can point  me in right direction to solve it using Errai messaging.

       

      Let's assume we have a simple app that two pictures and our users can view these pictures and put comments on it. Now let's assume at a given point of time - we have 100 users logged in and 50 are looking at Pic-1 and other 50 are looking Pic-2. So if one of the user at Pic-1 post a comment - What's the best way to display to all 50 users in that group?

       

      I was thinking to fire CommentAddedEvent from server and  listen to event at client and handle/not handle event based on what user looking at.  This will work file but won't be resource intensive? I mean wouldn't it be nice to send that message to just 50 users who are looking at Pic-1 and not to broadcast it and filtering at client handler?

       

      Please let me know what;s the best practices to handle this kind scenarios?

       

      Thanks,

        • 1. Re: Need Help with Broadcast messages
          mbarkley

          Hi Amit,

           

          If you want to avoid sending extraneous updates over the wire then you should only be using Errai CDI if the images your users can view is known at compile time. In such a case, you could make Errai CDI work by having different event types for each picture, or one event type with difference qualifiers.

           

          More likely, you'll be having a dynamic number of images, which means the Message Bus will be better suited for your needs. The simplest approach I can think of would be to have a broadcast comments on a channel based on an images name. Then a client can subscribe to that channel when they're viewing an image, and unsubscribe when they stop viewing it.

           

          Cheers.