InfoQ

News

Integrating Flex 3.0 and RabbitMQ Using STOMP

Posted by Moxie Zhang on Mar 14, 2008 09:53 AM

Community
Java
Topics
Rich Internet Apps,
Messaging
Tags
Flex

In a post at Flex on Rails Derek Wischusen shared his experiment that integrating RabbitMQ with a Flex 3 application using the ActionScript 3 STOMP client.

RabitMQ is an open source enterprise messaging system:

RabitMQ a complete and highly reliable Enterprise Messaging system. The RabbitMQ client libraries and broker daemon can be used together to create an AMQP network, or used individually to bring the benefits of RabbitMQ to established networks.

RabitMQ is an implementation of AMQP protocol, which is an open standard for messaging middleware. STOMP is a streaming text orientated messaging protocol. What Wischusen tried was the utilization of a STOMP adapter for RabbitMQ.

To allow readers understand how this experiment works, Wischusen shared the resource and source code:

Then, Wischusen explained what the Flex project is:

This project consists of two separate Applications: the ImageSender and the ImageReceiver. The project file also contains the compiled as3-stomp library, so you do not need to download it separately.

The ImageSender and ImageReceiver applications will communicate by exchanging messaging using RabbitMQ through STOMP protocol. To demonstrate how the Flex code from both applications work with STOMP client, Wischusen shared the code snipes.

At ImageSender:

    "stomp"  />
...

private function init () : void
{
var ch: ConnectHeaders = new ConnectHeaders();
ch.login = "guest";
ch.passcode = "guest"
stomp.connect("localhost", 61613, ch);
}
...
private function sendImage():void
{
var image: ByteArray = ImageSnapshot.captureImage(canvas).data;
stomp.send(destination, image);
}

At ImageReceiver:

"stomp" message="handleMessages(event)"  />
...
private var destination: String = "/queue/images";

private function init () : void
{
var ch: ConnectHeaders = new ConnectHeaders();
ch.login = "guest";
ch.passcode = "guest"
stomp.connect("localhost", 61613, ch);
stomp.subscribe( destination );
}
...

private function handleMessages(event : MessageEvent) : void
{
var bd: BitmapData = new BitmapData(canvas.width, canvas.height);
var loader : flash.display.Loader = new flash.display.Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBytesLoaded);
loader.loadBytes(event.message.body);
function onBytesLoaded (event : Event) : void
{
var content : DisplayObject = LoaderInfo( event.target ).content;
bd.draw( content );
canvas.graphics.beginBitmapFill(bd);
canvas.graphics.drawRect(0,0, canvas.width, canvas.height);
canvas.graphics.endFill();
}
}

The experiment demonstrates how a image is captured from a Flex application (ImageSender), the image is send to RabbitMQ server, a message is send to messaging consumer application (ImageReceiver) and the message triggers an event to load the image from the RabbitMQ server. It's an interesting demo of messaging oriented RIA application concept.

 

2 comments

Reply

or BlazeDS/ActiveMQ by Roger Voss Posted Mar 17, 2008 4:32 PM
Re: or BlazeDS/ActiveMQ by alexis richardson Posted Mar 18, 2008 9:28 AM
  1. Back to top

    or BlazeDS/ActiveMQ

    Mar 17, 2008 4:32 PM by Roger Voss

    The way we enabled our Flex RIA applications for messaging was by integrating BazeDS into our Tomcat middle-tier stack. All Flex clients connect over port 80 and/or 443 to Tomcat listener and have BlazeDS connections handled by a special BlazeDS servlet. This servlet uses the Comet pattern via which to support server-side push to clients. BlazeDS will in upcoming releases support the Tomcat 6 Comet Events (as well as other Comet pattern enhancements, such as Jetty continuations). It didn't do so in initial release as Adobe wants to take the time to do a architecture enhancement that accommodates all the significant Comet Pattern efficient i/o enhancements. Supporting, say, Tomcat 6 Comet Events, will require using the Java NIO listener when configuring Tomcat. However, by using that listener, a single physical Tomcat server (of current hardware vintage) can expect to be able to scale to around 20,000 concurrent connections - and do so using a very modest number of threads (a native thread consumes significant OS resources, such as pages of memory, so this can be a most significant scaling efficiency win). Additionally we use the BlazeDS JMS adapter support to wire BlazeDS to ActiveMQ. So AMQ is our JMS messaging broker backbone for the datacenter, while BlazeDS handles RIA web client integration into that messaging backbone over traditional web client ports 80/443. Lots of distributed software in the datacenter back-end can communicate via JMS, and even .NET stuff can integrate easily to AMQ via its NMS .NET client bindings. Of course AMQ supports STOMP as well so that scripting languages can easily play (which might be handy for testing). RabbitMQ is interesting as it's written in Erlang. Something to keep an eye on for sure. I checked out their web page and JMS support is something being contemplated but is not there yet. Lots of datacenter software has been written to JMS. So what I've outlined above is an effective means for existing Java-centric shops to get their Flex/AIR RIA web clients to support messaging in production situations today and integrate via JMS in the datacenter.

  2. Back to top

    Re: or BlazeDS/ActiveMQ

    Mar 18, 2008 9:28 AM by alexis richardson

    RabbitMQ has a great Java client, a C# client that integrates with .NET WCF, an AJAX/Comet style HTTP bridge, a STOMP adapter as shown above, and much more besides. People have integrated RabbitMQ with Spring using a JMS client. For Ruby users, here is a great video on using RabbitMQ with STOMP and Ruby: http://www.jaikoo.com/2008/3/14/oh-hai-rabbitmq The whole point about AMQP is that it is a completely language and platform neutral messaging protocol that works over *any* network and delivers real interoperability - just like TCP and HTTP, interop. actually works. If you want to access it through JMS that is possible, but many people don't use Java / Java EE. Cheers alexis

Exclusive Content

Measuring Agile in the Enterprise: 5 Success Factors for Large-Scale Agile Adoption

Michael Mah analyzes the development process in 5 companies: 2 Agile (one of them BMC) and 3 classic. He presents the factors which contributed to the success of BMC's Agile adoption.

Tom Preston-Werner on Powerset, GitHub, Ruby and Erlang

In this interview filmed at RubyFringe 2008, Tom Preston-Werner talks about how both Powerset and GitHub use Ruby and Erlang, as well as tools like Fuzed, god, and more.

David Laribee on Alt.NET and its Mission

David Laribee discusses the purpose of ALT.NET, its mission and future.

Discover RailsKits and Stop Writing Redundant Code

Ruby on Rails has become a popular Ruby framework for creating web applications in recent years. An aspect of creating a web application is the need to repeatedly create the same base functionality.

A Formal Performance Tuning Methodology: Wait-Based Tuning

Steven Haines talks about tackling web application performance tuning by proposing a method called wait-based tuning.

Shaw and Fowler About Forging a New Alliance

Shaw and Fowler talk about the need for a new relationship between the business department and the IT department. Studies have shown that projects mostly fail due to miscommunication between the two.

How to GET a Cup of Coffee

In this article, Jim Webber, Savas Parastatidis and Ian Robinson show how to drive an application's flow through the use of hypermedia in a RESTful application.

Archaeopteryx: A Ruby MIDI Generator

Eccentric artist turned overnight anti-celebrity, Giles Bowkett captures the heart and soul of RubyFringe as he demonstrates his revolutionary Archaeopteryx MIDI drum pattern generator.