Announcement Announcement Module
Collapse
No announcement yet.
Any insight for Spring with Cometd ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Any insight for Spring with Cometd ?

    Flex is great, but I wonder if anyone has knowledge or experience connecting Spring with Cometd?
    Especially now that Servlet 3.0 is out and HTML5 is coming.

    It seems that Flex integration and Cometd integration would share similar problems/solutions.

    Has anyone looked at running comet on Spring?

  • #2
    Yes, I've been working on support for Atmosphere (http://atmosphere.java.net/) in the form of some adapters for Spring Integration. I will be pushing this into the Spring Integration sandbox repository soon, but for now the work-in-progress code can be found in the demo I put together for JavaOne / SpringOne here: http://git.springsource.org/greenhouse/html5-showcase

    Comment


    • #3
      Jeremy,
      Thanks for the info.
      Atmosphere looks very promising; is it all it claims to be?

      I've found your integration code (in your petclinic, as well as in greenhouse)
      can you say a few words about the theory of operation?
      Having no experience with Spring Integration, I'm not sure where to start.

      Looks like AsyncHttpRequestHandlingMessageAdapter is the main bit for 'integration',
      and it appears that it forwards messages to an Atmosphere Broadcaster.
      I suppose there is also a reverse channel?

      Does HttpMessageMapper require any configuration? or does this just do all it's own magic?

      I'll continue to rev eng from the code, but any guidance would be appreciated.

      Comment


      • #4
        Originally posted by Jack Punt View Post
        Jeremy,
        Thanks for the info.
        Atmosphere looks very promising; is it all it claims to be?
        In general yes, but not without caveats. Keep in mind that the project is not yet 1.0, though I would say it is reasonably mature.

        Originally posted by Jack Punt View Post
        Looks like AsyncHttpRequestHandlingMessageAdapter is the main bit for 'integration',
        and it appears that it forwards messages to an Atmosphere Broadcaster.
        I suppose there is also a reverse channel?
        Yes, the adapter handles both incoming (both "subscription" messages and actual messages) and outgoing traffic. It is meant to hook up to a PublishSubscribeChannel in Spring Integration, which you can think of as something like a JMS Topic (in fact, I believe you could back it directly with a JMS Topic if you wanted).

        Originally posted by Jack Punt View Post
        Does HttpMessageMapper require any configuration? or does this just do all it's own magic?
        In general, no, it should provide good support as-is, and right now you can't really configure it anyway. (I'm sure we'll allow providing a custom HttpMessageConverter setup in the final version, but the need for that should be rare.) Basically this is just using the Spring MVC REST infrastructure to do content negotiation and generate appropriate responses. Of course, so far, I've only really been testing with JSON.

        Comment


        • #5
          Spring + JMS + Cometd very doable

          I haven't checked out the Spring+comtd (Atmosphere) integration project yet, but we have gotten Spring + JMS + Cometd working interenally.

          Before we started looking at the spring + flex integration, we were using HTML 5 canvas + cometd + spring.

          The basic idea is similar to what Jeremy had mentioned.

          Spring Roo Entity (JMS Publisher using JMS template) -> Produced serialized JSON (default serailization produced by roo json all) -> published on JMS Topic -> Cometd AtmosphereHandler (JMS Subscriber) took the message and pushed it out using Cometd to any clients connected. A quick javascript eval() on the pushed JSON data now exposed all our roo based object model to the client's javascript interface.

          The down side of this was that we didn't have the convenience of a direct Client and server object binding and remote data services that you get with AMF + Flex Builder 4. With the spring + flex integration you have the option of switching up to LCSD if you need to make your AMF more scalable.

          -rOck

          Comment


          • #6
            Can you say what you use for the browser/client side?

            I can see that Atmosphere will (hopefully) handle the comet sequence, but do you have a toolset for the javascript?

            I see references to PrimeFaces, but I'm unclear how that will mesh with the JSP/Tiles that i get from Roo.

            Will Atmosphere allow push from the STS's tc-server (tomcat 6), or do I need to add Jetty or TC7 to the mix?

            There are so many pieces... any guidance would be appreciated.

            Comment


            • #7
              >>Can you say what you use for the browser/client side?

              Our client of choice has been chrome.

              >>I can see that Atmosphere will (hopefully) handle the comet sequence, but do you have a toolset for the javascript?

              We were using the atmosphere jquery plugin, it was able to keep the connection to the server so that the JSON Comet messages were able to be processed in javascript. Check the Atmosphere docs on how to use the jquery plugin.

              >>I see references to PrimeFaces, but I'm unclear how that will mesh with the JSP/Tiles that i get from Roo.

              We are doing a completely customized interface using HTML 5 canvas so I am unsure how PrimeFaces, Spring MVC or any other presentation tier would hook into it. Really the benefit you get from using Atmosphere is that the server can push data to your client "real time" and you can then do whatever you want with it using javascript (dynamic updates, page modifications using jquery/moo tools etc.).

              >>Will Atmosphere allow push from the STS's tc-server (tomcat 6), or do I need to add Jetty or TC7 to the mix?

              By default (no configuration necessary) it works with Tomcat 6 (tested on tcServer 2.1 included in STS 2.5.1) and doesn't rely on Servlet 3.0 async connections =) This is one of the reasons why using Atmosphere vs Servlet 3.0 async is attractive. However we were able to test it using Tomcat 7 + Servlet 3.0 and NIO, but it required changing the configuration. See the Atmosphere docs on how to use NIO.

              >>There are so many pieces... any guidance would be appreciated.

              My suggestion to you would be to download the Atmosphere project and play around with their examples. (Chat is pretty simple). The really key part for us was taking the Atmosphere Handler and setting it up as a JMS listener so it could pipe the serialized JSON out to the web browser.

              Comment


              • #8
                rockhowse,
                Again, thank you for responding.

                I had been stymied because the 'source' from Atmosphere was just the java side,
                now I have the .war, and that does include an index.html and the referenced javascript.
                So that makes a better starting point.

                I was hoping there was a documented API or Component that would handle the client-side of comet;
                analogous to the flex producer/consumer and an associated template or framework for the callbacks and error processing.
                Is that in Atmosphere's "jQuery Plug In" ?
                I expect I'll be digging deeper into that; the examples/blog is somewhat helpful,
                but i'm still looking for the api/spec/rulebook...

                Comment


                • #9
                  Using Atmosphere with Spring

                  Can you say how you use Atmosphere along side Spring on tomcat?

                  Atmosphere has many install/deploy/usage modes, so I wonder which model you settled on.
                  Do we need the jersey stuff? or Meteor?
                  Does atmosphere require its own servlet? (or can it be used behind Spring DispatcherServlet?)
                  (Jeremy, i see servlet named 'comettests', is that just for test, or the actual running of the comet?)

                  My assumption is that there's an Atmosphere servlet that 'suspends' the comet requests, and resumes/replies when the JMS delivers message. But my brain is blocking on what components to comprise and configure the Atmosphere bit.

                  I'm not an expert with web.xml, and so wonder what is the easiest way to get this configured.
                  Last edited by Jack Punt; Nov 24th, 2010, 03:55 PM.

                  Comment


                  • #10
                    Share ApplicationContext in another Servlet?

                    I've made some progress:
                    in web.xml we have Spring DispatcherServlet for the Spring/Roo/WebMvc/Tiles pages,
                    a second DispatcherSevlet for Flex/BlazeDS messagebroker for the Flex clients,
                    and now AtmosphereServlet for the async events.
                    Note: I did not have success with MeteorServlet delegating to DispatcherServlet; login failed

                    The AtmosphereServlet scans classpath to find MyAtmosphereHandler, which creates MyJMSBroadcaster
                    which will listen for JMS messages on the users' queue/topic and forward them to the http client.
                    [until I get more jQuery/moo or whatever, it is sufficient for the client to reload to see the new content]

                    The problem now is to get the Spring beans for the jmsTemplate, connectionFactory, etc
                    into MyAtmoshpereHandler or MyJMSBroadcaster;

                    Q: Is there some easy way for the AtmosphereServlet to find and share the existing Spring ApplicationContext?
                    [That would be better than passing beans through the shared HttpSession...]

                    Comment


                    • #11
                      Curious if you've found any more answers to this. I've been exploring using comet in my Spring MVC project and have really been looking at Atmosphere. Seems to be a pretty slick solution, but I'm still fuzzy on how to integrate Atmosphere into Spring MVC. Any help is appreciated.

                      Comment


                      • #12
                        neo,
                        I just saw your post in the 'integration' forum.
                        I have not tried to use Spring Integration for this,
                        but went straight to JMS (planning for horizontal scaling)
                        you can see the result in http://atmosphere-users-mailling-lis...5p5721315.html

                        Atmosphere is a good start, but it is a bit confusing and over-engineered as it is not simply a client/server comet adapter.
                        As often happens, its primary demo/use-case has caused Atmosphere to expand into being its own messaging service.

                        I took the approach to use as little of Atmosphere as possible, and use ApacheMQ/JMS for messaging.
                        So my client opens one long-polling comet request to get events,
                        and continues to use normal HTTP through Spring Controllers for everything else,
                        when server wants to pass a message/event to the client, it just sends a JMS message (using jmsTemplate)
                        The JMS message is received in MyJMSBroadcaster which pushes it to the client.
                        [the client can do DOM surgery or reload to get a new view]
                        Next step is to configure the listener in MyJMSBroadcaster to list to both the per-user queue and other topics.
                        But in all cases, the JMS message will simply use Atmosphere to push back to the client.

                        Note: my AtmosphereServlet is configured independently in web.xml, and it not using any of the spring features.
                        The Client makes first contact via Spring/roo, and that may return a page and javascript for the comet connection.
                        The comet connect arrives to the AtmosphereHandler with the same JSESSIONID set, so we can:
                        Code:
                             SecurityContext context = (SecurityContext)session.getAttribute("SPRING_SECURITY_CONTEXT");
                        and check for an authenticated Principal from there.
                        Other than that, the AtmosphereHandler just sets up the JMSBroadcasters (which are configured through spring)

                        And alas, I'm using a Roo-based server-side, so it is tomcat-6 and dojo,
                        which is not perfectly aligned with atmosphere's target of jquery and web-socket;
                        but jfarcand indicates that eventually the javascript will be more generic.
                        (and eventually tomcat may get other transport support, or we can insert jetty or something,
                        but long-polling is good enough for the eventing that I currently need)

                        Comment

                        Working...
                        X