Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Subscribing to and Pushing Messages

    I have a sample piece of code that I'm using to exercise the Realtime Messaging Module.

    Everything seems to be fine on the server side. I see log messages that the message is being sent on the assigned channel when the messaging api is used there.

    Here is the server code that appears to be working (I see the following log entry: === 2011-12-01 14:21:32,391 [d-37] DEBUG ISCMessageDispatcher - sending message to channel: logTypeChannel)


    public DSResponse startLogThread()
    {
    //create an empty DSResponse to send back to the client
    DSResponse dsResponse = new DSResponse();

    try
    {

    dsResponse.setSuccess();
    //spawn the new thread and have it pump messages to a queue or subscription
    new Thread(new Runnable()
    {
    @Override
    public void run()
    {

    while(true)
    {
    try
    {
    Thread.sleep(1000);
    ISCMessageDispatcher iscMD = ISCMessageDispatcher.instance();
    iscMD.send(new ISCMessage("logTypeChannel","test message"));
    }
    catch(InterruptedException ie)
    {
    System.out.println("thread interrupted");
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }
    }
    }).start();
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    return dsResponse;
    }


    On the client I have a subscription to the same channel that the server is pushing to, but it doesn't seem to be working (the handler never gets invoked):

    //subscribe to the message the the server will send to us
    Messaging.subscribe("logTypeChannel",new MessagingCallback()
    {
    @Override
    public void execute(Object o)
    {
    SC.say("I got a message");
    }
    });

    I am pretty sure the subscription code performs the subscription, because the browser refreshes at regular intervals after the call is made.

    Can someone point me in the right direction?

    Thanks

    #2
    One other question in this thread:

    In the Realtime Messaging guide the following text about ISCMessageDispatcher appears:

    "instance()
    returns a concrete ISCMessageDispatcher class capable of delivering responses within the JVM

    instance(RequestContext context)
    returns a concrete ISCMessageDispatcher class capable of delivering responses to web browsers"

    In the web example for stock quotes, the instance() signature is used and the messages are delivered to the browser. Is the proper way to deliver messages to the browser to use the instance(RequestContext context) signature

    Additionally, when using the second signature where is the RequestContext obtained?

    Thanks again

    Comment


      #3
      Please ignore the second signature, you don't need to use it.

      As far as troubleshooting what's going wrong for you - your code is now nearly identical to the StockQuotes example so it's time for really basic sanity check stuff.

      For example, is the browser connecting to the same server where you're publishing messages to the ISCMessageDispatcher? If so, then you should be seeing logs for clients connecting to the MessagingServlet interleaved with the logs you're already seeing for the messages you're sending.

      Comment


        #4
        Everything is local, so the browser is connecting to localhost.

        The only log I see that might be related is this:
        INFO RequestContext - URL: '/gsui/gsui/sc/messaging', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1': Moz (Gecko) with Accept-Encoding header

        The message is being started in a DMI in the code snippet in the first post. That should be okay yeah?

        Comment


          #5
          Yes, initiating messages from a DMI is normal. Have you tried sending something other than a plain string as the message data, for example, a Java Map?

          Comment


            #6
            Why would it matter what's in the message? I don't see the subscribe you mentioned anywhere?

            Comment


              #7
              When I subscribe this is definitely the result on the server:

              INFO RequestContext - URL: '/gsui/gsui/sc/messaging', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1': Moz (Gecko) with Accept-Encoding header.

              I also changed the server code to include almost the exact same list logic as the stock quote example. I included a string in the object however, because the point of this exercise is to stream textual information to clients.

              I still can't get the message handler to pick up on anything, however, is there something I have to configure in the web.xml or something?

              Thanks again,
              Last edited by ls3674; 1 Dec 2011, 16:40.

              Comment


                #8
                That URL looks odd ("gsui" twice). If you put that URL directly into your browser, do you get a 404 (would indicate that the MessagingServlet is not subscribed to the right URL in web.xml) or some kind of stack trace (would indicate the MessagingServlet is at least in the right place)?

                In the Developer Console, use the Logging Preferences menu to enable "Messaging" at DEBUG level. What do you see in the logs after reloading the app?

                Have you tried sending a Java Map yet?

                Comment


                  #9
                  Here is the web.xml:

                  <?xml version="1.0" encoding="UTF-8"?>

                  <web-app xmlns="http://java.sun.com/xml/ns/javaee"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
                  version="3.0">
                  <filter>
                  <filter-name>CompressionFilter</filter-name>
                  <filter-class>com.isomorphic.servlet.CompressionFilter</filter-class>
                  </filter>
                  <filter-mapping>
                  <filter-name>CompressionFilter</filter-name>
                  <url-pattern>/*</url-pattern>
                  </filter-mapping>
                  <servlet>
                  <servlet-name>Init</servlet-name>
                  <servlet-class>com.isomorphic.base.Init</servlet-class>
                  <load-on-startup>1</load-on-startup>
                  </servlet>
                  <servlet>
                  <servlet-name>PreCache</servlet-name>
                  <servlet-class>com.isomorphic.servlet.PreCache</servlet-class>
                  <load-on-startup>2</load-on-startup>
                  </servlet>
                  <servlet>
                  <servlet-name>IDACall</servlet-name>
                  <servlet-class>com.isomorphic.servlet.IDACall</servlet-class>
                  </servlet>
                  <servlet-mapping>
                  <servlet-name>IDACall</servlet-name>
                  <url-pattern>/gsui/sc/IDACall</url-pattern>
                  </servlet-mapping>
                  <servlet-mapping>
                  <servlet-name>IDACall</servlet-name>
                  <url-pattern>/gsui/sc/IDACall/*</url-pattern>
                  </servlet-mapping>
                  <servlet>
                  <servlet-name>DataSourceLoader</servlet-name>
                  <servlet-class>com.isomorphic.servlet.DataSourceLoader</servlet-class>
                  </servlet>
                  <servlet-mapping>
                  <servlet-name>DataSourceLoader</servlet-name>
                  <url-pattern>/gsui/sc/DataSourceLoader</url-pattern>
                  </servlet-mapping>
                  <servlet>
                  <servlet-name>FileDownload</servlet-name>
                  <servlet-class>com.isomorphic.servlet.FileDownload</servlet-class>
                  </servlet>
                  <servlet-mapping>
                  <servlet-name>FileDownload</servlet-name>
                  <url-pattern>/gsui/sc/skins/*</url-pattern>
                  </servlet-mapping>
                  <servlet-mapping>
                  <servlet-name>FileDownload</servlet-name>
                  <url-pattern>/gsui/sc/system/modules/*</url-pattern>
                  </servlet-mapping>
                  <servlet-mapping>
                  <servlet-name>FileDownload</servlet-name>
                  <url-pattern>/gsui/sc/system/development/*</url-pattern>
                  </servlet-mapping>
                  <servlet-mapping>
                  <servlet-name>FileDownload</servlet-name>
                  <url-pattern>/gsui/sc/system/reference/skin/*</url-pattern>
                  </servlet-mapping>
                  <mime-mapping>
                  <extension>csv</extension>
                  <mime-type>text/csv</mime-type>
                  </mime-mapping>
                  <mime-mapping>
                  <extension>manifest</extension>
                  <mime-type>text/cache-manifest</mime-type>
                  </mime-mapping>
                  <welcome-file-list>
                  <welcome-file>index.html</welcome-file>
                  </welcome-file-list>
                  <jsp-config>
                  <!-- Isomorphic JSP tags -->
                  <taglib>
                  <taglib-uri>isomorphic</taglib-uri>
                  <taglib-location>/WEB-INF/iscTaglib.xml</taglib-location>
                  </taglib>
                  </jsp-config>
                  <persistence-context-ref>
                  <persistence-context-ref-name>persistence/em</persistence-context-ref-name>
                  <persistence-unit-name>ds</persistence-unit-name>
                  </persistence-context-ref>
                  <persistence-unit-ref>
                  <persistence-unit-ref-name>persistence/emf</persistence-unit-ref-name>
                  <persistence-unit-name>ds</persistence-unit-name>
                  </persistence-unit-ref>
                  </web-app>

                  There is no stack trace.

                  The following addresses end up at 404 pages:
                  http://localhost:8080/gsui/gsui/sc/messaging
                  http://localhost:8080/gsui/sc/messaging

                  Where is the "Messaging" menu option in the developer console?

                  Comment


                    #10
                    After inspecting my web.xml compared to the StockQuote sample I noticed that the messaging entries were missing. I have updated the file and I am testing it again.

                    I added the following entries:

                    <!-- //>RealtimeMessaging -->
                    <!-- The MessagingServlet is used by realtime messaging -->
                    <servlet>
                    <servlet-name>MessagingServlet</servlet-name>
                    <servlet-class>com.isomorphic.messaging.MessagingServlet</servlet-class>
                    </servlet>
                    <!-- //<RealtimeMessaging -->
                    <!-- //>RealtimeMessaging -->
                    <!-- Messaging uses this URL by default -->
                    <servlet-mapping>
                    <servlet-name>MessagingServlet</servlet-name>
                    <url-pattern>/gsui/sc/messaging/*</url-pattern>
                    </servlet-mapping>
                    <!-- //<RealtimeMessaging -->

                    Comment


                      #11
                      That was it. Somehow I overlooked setting up the web.xml properly.

                      Thanks for the help.

                      Comment


                        #12
                        I had a similar problem, although it resulted in a different error. In my case it complained about a missing license

                        I didn't see anything in the docs to remind you to add the servlet to your web.xml

                        Comment

                        Working...
                        X