Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Any insight for Spring with Cometd ?

  1. #1
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Default 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. #2
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    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
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  3. #3
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Default

    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.

  4. #4
    Join Date
    Apr 2005
    Location
    San Francisco, CA
    Posts
    1,224

    Default

    Quote 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.

    Quote 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).

    Quote 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.
    Jeremy Grelle

    Staff Engineer, Web Products Team
    SpringSource

  5. #5
    Join Date
    Nov 2010
    Posts
    15

    Wink 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

  6. #6
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Default

    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.

  7. #7
    Join Date
    Nov 2010
    Posts
    15

    Default

    >>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.

  8. #8
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Default

    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...

  9. #9
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Default 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 at 02:55 PM.

  10. #10
    Join Date
    May 2008
    Location
    Silicon Valley, CA
    Posts
    139

    Question 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...]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •