5 Replies Latest reply on Sep 12, 2012 11:56 AM by navigateur

    Sending a single message from the server to multiple subjects, once?

    navigateur Newbie

      I want to send a single message from the server to multiple subjects, whereby any client subscribed to any combination of those subjects receives that message once only.

       

      In my scheme, a message's relevant to multiple subjects. A client may be subscribed to one or more of those subjects. Despite this scheme I don't want to burden any client side with any superfluous message.

       

      The obvious way is to send the message again to each subject and filter out any repetitions at the client side, but I just wonder if Errai is (or will ever be) able to do a single message transmission on multiple subjects and have any client subscribed to any combination of those subjects receive that message only once? Maybe via some kind of "regular expression" matching instead of a concrete string? This may be impossible but I've no idea how Errai works underneath so I don't know.

       

      My scheme seems unavoidable as it's based on connecting new single pieces of data each to one or multiple existing pieces of data, depending on whether they exist or not on the client side. Hence the need for a given message to be able to address combinations of subjects (but once to avoid repetition).

        • 1. Re: Sending a single message from the server to multiple subjects, once?
          navigateur Newbie

          Can someone confirm if this can ever be technically possible with Errai or is already currently? Or am I missing a more obvious approach?

          • 2. Re: Sending a single message from the server to multiple subjects, once?
            Jonathan Fuerth Master

            The feature you describe (single message addressed to multiple subjects) is not available in Errai Bus. However, the inverse (single MessageCallback listening on multiple subjects) does work fine:

             

            Say within the client, you have three subscribers on the Errai client message bus. We'll call them S1, S2, and S3.

             

            S1 subscribes to subject A

            S2 subscribes to subjects A and B

            S3 subscribes to subjects A, B and C

             

            When you send a message to subject C (either within the client or from the server), S3 within the client will receive that message (of course).

            When you send a message to subject B, S2 and S3 will receive the message. Note that only one copy of the message went across the wire, even though S1 and S2 both received it.

            Finally, a message to subject A will be delievered to all three subscribers.

             

            So, instead of trying to send a single message to multiple destinations, if you can set up the subscribers to subscribe to the correct combination of subjects, you should be able to achieve the effect you're after.

             

            Hope that helps.

             

            Jonathan

            • 3. Re: Sending a single message from the server to multiple subjects, once?
              navigateur Newbie

              No I don't think it can work using multi-subject subscribe with single-subject publish. Please correct me if I'm wrong:

               

              I've a new message, D, which must be connected to 3 known objects: A, B and C. If any of these exist on the client-side, D must be received and connected to them.

               

              Client 1 has objects A and B. (So I subscribe to "A" and "B").

              Client 2 has objects B and C. (So I subscribe to "B" and "C").

               

              "A", "B" and "C" aren't related nor connected to one another in any way whatsoever, other than through the new message "D". It's impossible to predict the existence of "D", or which combination of objects it'll need to address, before it's created.

               

              I can't think of any way to "invert" this scheme such that I can receive this new "D" message once on each client (which is all that is needed). I can only seem to receive it 3 times on each client, by sending it for each of the 3 objects it needs to address in succession, then filtering out the 2 repetitions in each case.

               

              Am I wrong? If so, what's the answer? If I'm not wrong, then will this ever be technically possible with Errai? (My example is small, the real one may have greater numbers, thus delivering more superfluous messages).

              • 5. Re: Sending a single message from the server to multiple subjects, once?
                navigateur Newbie

                Is this technically impossible? Will I always have to send the same message again for each subject (even though that's burdensome and seemingly unnecessary in clients subscribed to any more than one of them) in the scheme I described, regardless of any web technology?