Comet - Streaming AJAX

Module stability: IN PROGRESS

Table of Contents

Akka supports push/streaming REST/AJAX using the Atmosphere framework, which works together with JAX-RSannotations to provide streaming RESTful components.

In order to turn the REST beans into Comet services you have to annotate them with the Atmosphere annotations (along with the JAX-RS annotations):
  • @Suspend
    Annotate an endpoint method with @Suspend, and any incoming requests to this endpoint will be listening for Broadcasted messages on the specified entity.

  • @Broadcast
    Annotate another endpoint method with @Broadcast on the same entity and have the result of the method propagated to all listeners for this entity.

  • @Cluster(Array(classOf[AkkaClusterBroadcastFilter])) { val name = "uniquename" }
    Annotate the same endpoint as @Broadcast and give it a unique name, and now your comet app is cluster aware

If you deploy Akka in another JEE container, don't forget to add Akkas initialization and cleanup hook:

If you deploy Akka in another container and you get a comet support detection problem and you have 'se.scalablesolutions.akka.comet.AkkaServlet' in your 'web.xml' you can simply provide it with an 'init-param' to specify which comet support you want to use:


  • BlockingIOCometSupport
  • GoogleAppEngineCometSupport
  • GrizzlyCometSupport
  • JBossWebCometSupport
  • Jetty7CometSupport
  • JettyCometSupport
  • Servlet30Support
  • TomcatCometSupport
  • WebLogicCometSupport

Here is a little example of creating a comet-based publish/subscribe REST-bean.

class PubSub {
  def subscribe(@PathParam("topic") Broadcaster topic) : Broadcastable = new Broadcastable("", topic)
  @Cluster(Array(classOf[AkkaClusterBroadcastFilter])) { val name = "foo" }
  def say(@PathParam("topic") Broadcaster topic, @PathParam("message") message: String): Broadcastable =
    new Broadcastable(message, topic)
Home Turn Off "Getting Started"