BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Integrating Flex 3.0 and RabbitMQ Using STOMP

Integrating Flex 3.0 and RabbitMQ Using STOMP

This item in japanese

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.

 

Rate this Article

Adoption
Style

BT