2 Replies Latest reply: Jun 3, 2011 2:16 PM by pottingshed RSS

    Sending message from server to client

    Maik Schreiber Newbie

      Hi all,

       

      I'm currently trying to use ErraiBus in a GWT application. What I'm trying to do is to send a message from the server to the client without the client requesting anything. I couldn't find out how to do that, though. In the examples in the user guide it looks like the server always reacts to some client message, which is not what I need.

       

      On second note, to send an unsolicited message, I think I need a reference to some ErraiBus component. I understand that ErraiBus uses Guice to wire its components, but how to get some object or service that I can use to send my message to the client?

       

      Any help is greatly appreciated. Perhaps the user guide could be modified to include a similar example.

       

      Greetings,

       

      Maik

        • 1. Re: Sending message from server to client
          Heiko Braun Master

          Just send it using a bus reference:

           

           

           MessageBuilder.createMessage()
                              .toSubject("HelloWorldClient")             
                              .signalling()                               
                              .with("text", "Hi There")                  
                              .noErrorHandling()                         
                              .sendNowWith(bus);
          

           

           

          You can do that in any business method of your service implementation,

          The bus reference get's injected:

           

           

          @Inject                                         
          public HelloWorldService(MessageBus bus) {
                  this.bus = bus;
          }
          
          • 2. Re: Sending message from server to client
            pottingshed Newbie

            Hi,

            I'm trying to do the same thing - notify client of successful authentication, without an initial client request. However, when I issue the following after authentication, I get the following exception:

            Exception in thread "Dispatch Worker Thread" java.lang.RuntimeException: cannot have a conversation.  the incoming message has not session data associated with it.

            Presumably this is because there is no associated session. This is what I use to make the call:

                    RequestDispatcher erraiDispatcher = GneLifecycleListener.getSpringContext().getBean("erraiRequestDispatcher",

                            RequestDispatcher.class);

                   

                    MessageBuilder.createMessage()

                    .toSubject("CommandFacadeMsg")

                    .signalling()

                    .with("gneCommand", GneCommand.SUCCESSFUL_AUTHENTICATION.toString()) // Use string, not enum

                    .with("gneUserVo", gneUserVo)

                    .noErrorHandling()

                    .sendNowWith(erraiDispatcher); 

             

            Where am I going wrong?

             

            Thanks,

            Errai Newbie.