InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Integrating Flex 3.0 and RabbitMQ Using STOMP

Posted by Moxie Zhang on Mar 14, 2008

Sections
Architecture & Design,
Development,
Enterprise Architecture
Topics
Java ,
Messaging ,
Rich Internet Apps
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.

 

or BlazeDS/ActiveMQ by Roger Voss Posted
Re: or BlazeDS/ActiveMQ by alexis richardson Posted
  1. Back to top

    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.

  2. Back to top

    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

Educational Content

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.

Max Protect: Scalability and Caching at ESPN.com

Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.

The Seven Deadly Sins of Enterprise Agile Adoption

Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.

Questions for an Enterprise Architect

Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?