BT

Integrating Flex 3.0 and RabbitMQ Using STOMP

by Moxie Zhang on Mar 14, 2008 |

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.

 

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

or BlazeDS/ActiveMQ 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.

Re: or BlazeDS/ActiveMQ 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: 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

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT