Jul 28

Flex chat application that uses Apache ActiveMQ and STOMP

Tag: AS3, ActiveMQ, Messaging, STOMP, Server PushDerek Wischusen @ 10:55 pm

To follow on my last post, here is a little Flex chat application that uses Apache ActiveMQ and the ActionScript 3 STOMP library that I have been working on.

You can get the source for the application here.

You will need to download and install ActiveMQ to run this app. Installing ActiveMQ is pretty straight-forward. You can grab one of the latest snapshots here, and then follow the instructions posted here.

Here are some basic instructions to get ActiveMQ up and running:

  1. Download an unzip to the directory of your choice.
  2. Open a command-line and navigate to the bin folder inside activemq
  3. Run the activemq application inside the bin folder. (e.g., $ activemq/bin/activemq).

Once you’ve got ActiveMQ running.  Go ahead a launch a couple instances of the Flex chat app.  Login to each one and start chatting.  For example,

Chat 1

Chat 2_1

You can also see the chat messages that come from the chat demo that comes with ActiveMQ.

In your browser, go to: http://127.0.0.1:8161/demo/chat.html, login and send a chat message.  For example,

AMQ Chat 2

Chat 3

37 Responses to “Flex chat application that uses Apache ActiveMQ and STOMP”

  1. Paul Rangel says:

    Wow, great stuff I’ve been looking for a good messaging server and ActiveMQ looks like it fits the bill. You going to be at Flex360 by chance? I’d like to hear more about what you think Active MQ is capible of and why you are using it vs. Fuse or Red 5.

    Paul

  2. Carlos says:

    Great article!!!

    I have a quick question for you. I am using ActiveMQ and I have a C# program that is using client written with NMS. The client can’t see the messages that are been sent by the flex client. Neither can the flex client received messages been sent by the C# client. Yet they are both subscribing to the same topic. I guess the question is can a message sent from STOMP be received by a subscriber that is not using STOMP?

    Everything that have found soo far says that it should, just wondering if am missing something.

    Thanks,

    Carlos

  3. Carlos says:

    Just figured out that the messages been sent using stomp are been placed in a queue. While the messages been sent using NMS are been put in a topic. :(

  4. Eric Stone says:

    Also check out the ActiveMQ Gateway that ships with Cold Fusion 8 to really turbo on your Flex…

  5. yarek says:

    another Flex chat (with video) avaible on http://www.flexvideochat.com

  6. Marius says:

    Hi,

    This is a great post. I worked out all the details of a chat running on localhost.

    I only had a problem when trying to open an XMLSocket with a domain, which was not localhost. I tried with a crossdomain.xml file, loadPolicyFile, nothing worked. From your experience, what should be done to be able to open an XMLSocket (the policy file is available on http://www.mydomain.com/crossdomain.xml and ActiveMQ is available on http://www.mydomain.com:61613). Thanks.

    PS> The server is my computer, so anything is possible.

  7. ibrahim says:

    Hi,

    Following the last post, I am also trying to get rid of the error “security sandbox violation”, the application is not working when I try to reach over tomcat..

    Nothing worked related to crossdomain.xml file suggestions, I tried so far..

    any help will be great,

    thanks,

    ibrahim

  8. athind says:

    Hi Darren,

    Thanks for the very helpful post.

    Unfortunately I and apparently many others are stuck on where should we put the crossdomain.xml file
    inside activemq for flash.

    I have just created a RoR/ActiveMQ/Stomp/ActiveMessaging/Flex application that uses publish/subscribe
    based on your tutorial and this is the last missing piece that is stopping me from making it live.

    Your help would be greatly appreciated.

    Many Thanks,
    Aman

  9. athind says:

    Finally found the problem. The new Flash 9.0.24 had enforced new socket security policies.

    Once I setup a socket server for serving socket security policy files, everything starting blowing smooth as a whistle!

    Thanks for the great article!
    Aman

  10. mani says:

    Hello
    I have solved the security problem.
    Just goto there to download a security server:http://www.flash-resources.net
    But I encounter some other probelms.
    It works fine when i input english.
    But if i write in chinese, it said Error: Error #2002 which means that socket is invalid.
    If anybody know what’s the reason, please email me: shineandsky@yahoo.cn
    Thanks for your time to read my comment^_^

  11. mani says:

    Thank you , nameless hero! please help me about what’s the reason of the fault.

    My fault details:
    org.apache.activemq.transport.stomp.ProtocolException: content-length bytes were read and there was no trailing null byte

    at org.apache.activemq.transport.stomp.StompWireFormat.unmarshal(StompWireFormat.java:149)

    at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:203)

    at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:195)

    at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:183)

    at java.lang.Thread.run(Thread.java:619)

    [object Object]
    [Event type="ErrorEvent" bubbles=true cancelable=false eventPhase=2]
    Thanks for your time^_^

  12. manoj says:

    Hi this is a great example to implement chat application.
    Can you give more details on back end .i.e., i want to know the language used on server side and some details on the database.

  13. manoj says:

    Is there any possibility to implement this application using cakephp as server side language.

  14. Derek Wischusen says:

    Hi Manoj,

    There really isn’t a server side language involved. ActiveMQ handles all of the messaging.

    Derek

  15. Derek Wischusen says:

    Hi Mani,

    Sorry for the delayed response. Try updating to the latest version of as3-stomp (http://code.google.com/p/as3-stomp) and see if that solve your problem.

    Derek

  16. Ravi says:

    Hi Derek Wischusen ,
    this is a great example to work on flex chat , but can you suggest me, how to configure apache ActiveMQ inside Apache Tomcat ? Please resolve my problem.

  17. Sidd says:

    I cant get ActiveMQ to start on my Apache server in Linux. First I thought that it may be coz my JRE is old. But now as I have upgraded it, it still gives this error when I try bin/ActiveMQ:

    The java class could not be loaded. java.lang.UnsupportedClassVersionError: (org/apache/activemq/console/Main) bad major version at offset=6

    Pls help somebody.

    btw the app works fine in Windows after installing and starting ActiveMQ on localhost. I really like this app :) thanks Derek

  18. Sidd says:

    can somebody pls tell me where are the chat logs stored? I am having a hard time figuring this out. I also tried using JDBC myDQL drive connection using this article. http://note19.com/2007/06/23/configure-activemq-with-mysql/ this makes the database tables but not the data?? pls help

  19. Sidd says:

    Hi Derek,

    Do you how activemq can store the chat logs? anybody?

  20. andy says:

    Hi

    I just tried running the chat example after installing activemq. I also downloaded and ran the policy server that someone mentioned above. So now i got two window command windows open running the activemq and policy servers. I refresh the chat demo page. I still get the Error #2048 security sandbox violation error. what is wrong?

  21. poornimahc says:

    <![CDATA[

    import mx.events.FlexEvent;
    import flex_src.codehaus.stomp.STOMPClient;
    import flex_src.codehaus.stomp.event.MessageEvent;
    import flex_src.codehaus.stomp.headers.*;

    [Bindable]
    private var username : String;

    private var stomp : STOMPClient = new STOMPClient();
    private var topic : String = “/topic/CHAT.DEMO”;
    private var lastSender : String;

    private function init () : void
    {
    stomp.connect( “localhost”,8080 );
    stomp.subscribe( topic );

    stomp.addEventListener(MessageEvent.MESSAGE, handleMessages);
    }

    ********** private function handleMessages(event : MessageEvent):void
    {
    var incomingMsg : XML = XML(event.message.body);
    var from : String = String(incomingMsg.@from);

    switch (String(incomingMsg.@type))
    {
    case “join”:
    conversation.htmlText += “” + from +” has joined the room\n”;
    break;

    case “chat”:
    if (from == lastSender)
    {
    from = “… “;
    }
    else
    {
    lastSender = from;
    from +=”: “;
    }

    conversation.htmlText += from + String(incomingMsg) + “\n”;
    break;

    case “leave”:
    conversation.htmlText += “” + from +” has left the room\n”;
    break;

    default:
    trace(’unknown message type’);
    break;
    }

    }

    private function doLogin () : void
    {
    username = txt1.text;

    var joinMsg : XML =
    stomp.send(topic,joinMsg.toXMLString());

    this.setCurrentState(’Chat’);
    txt1.text=”;
    }

    private function doSend () : void
    {
    var chatMsg : XML = {txt1.text}
    stomp.send(topic,chatMsg.toXMLString());
    txt1.text=”;
    }
    ]]>

    i am getting error in the code which i am stared know there
    like
    type was not found

    what i can do for that

  22. poornimahc says:

    how to run the Activemq
    and what we hav to download for STOMP to use in this chat application

  23. stevie says:

    I get the missing trailing null byte – error when sending a first message too (like Mani). When I try to update the as3stomp-library
    it cant find the messageEvent
    (type not found in
    private function handleMessages(event : MessageEvent) : void
    )

    What to do???

    Any other/better options to get realtime in Flex/PHP?

  24. Derek Wischusen says:

    Hi Stevie,

    The app in this post uses a very old version of the Stomp client. I’ll post an updated version this weekend. You might also want to check out the demo app that is on the project site: http://as3-stomp.googlecode.com/files/StompImageShare.zip

  25. stevie says:

    OK, we have to change the code of the chat appl. according to new conventions of the as3stomp-lib. but the problem of the missing null byte is still in there. I am monitoring the chat with the php stomp client from codehaus. It crashes because of the missing null byte. It echos only the first login message. How could we send a null byte from within AS3? And how could we query against ActiveMQ from within AS3 to write a flex monitor?
    Any suggestions?

  26. Derek Wischusen says:

    Hi Stevie,

    The ActionScript STOMP client terminates every message with a null byte. I thought I remembered reading something about this issue on the RabbitMQ mailing list: http://www.nabble.com/Stomp-frame-not-terminated-with-null-character-td19447635.html. It looks like this issue is specific to the PHP client.

  27. stevie says:

    Hello Derek,

    Thank you for the tip…I will give it a try.
    Do you have any suggestions for querying against ActiveMQ from within AS3 to retreive status informations?

  28. stevie says:

    …or having any alternative ideas to php-stomp for a flex/php solution?

  29. stevie says:

    Hi Derek,

    it seems that your null byte is not there null byte…
    they do something like this which works using only php-clients:
    // ActiveMq
    if($data[$len - 2] == “\x00″ && $data[$len - 1] == “\n”) {
    $continue = false;
    }

    I believe they append a “\n” to the null byte looking to there send method:
    return $data .= “\x00\n”;
    How can I append this “\n” in your as3-lib.? I tried this:
    transmission.writeByte( NULL_BYTE+’\n’ );
    But it did not work.

    Any solutions?

  30. Derek Wischusen says:

    try
    transmission.writeByte(NULL_BYTE);
    transmission.writeUTFBytes(’\n’);

  31. stevie says:

    hm takes no effect, are there other encodings for ‘\n’ in AS3?

  32. stevie says:

    Now I have two stomp-client-implementations running… talking with clients/instances of there own library, build in the same language very well, but not with clients build with another library/language. Actually I would think the stomp-conventions have to be so clear that every instance should be able to talk and listen to any valid external stomp-client, regardless to there implementation.

    Very very strange ;-) .

    My goal is to have realtime/server push without java and write the business logic on server in php. Did someone heard something about a BlazeDS/PHP aproach?

    Are there some benchmarks/experiences about the stomp/php client from codehaus. It seems that this is a critical point and the lib is poorly documentated/maintained.

    I found an alternative php-stomp-client here
    http://github.com/felixjendrusch/stomp/tree/master
    but its not finished jet and there is no manual.

    Any suggestion will be appreciate.

  33. stevie says:

    The hint:
    stomp.sendTextMessage(topic,msg);

  34. Derek Wischusen says:

    That method is for sending a TextMessage (rather than the default BytesMessage) with ActiveMQ. Basically all it does is exclude the content-length header. Perhaps the PHP client does not work with BytesMessags.

  35. stevie says:

    Thx Derek,
    …another question. Can I send file-data using your as3-stomp lib and ActiveMQ?

  36. stevie says:

    Any ideas to implement this:
    http://activemq.apache.org/advisory-message.html
    or how to start using your as3-lib/chat-app?

  37. Stanley says:

    Thanks for the sample!

    same nebie question: I installed my ActiveMQ server on another box with a stactic IP, at the HTTP Server root, I placed the “crossdoain.xml” there – http://12.123.123.12/crossdomain.xml shows:

    When I run the “swf” or “html” locally, it works fine. But when I copy those to my Yahoo hosted WebServer, it did not work – with no error.

    Thanks for your help!

Leave a Reply

Cheapest online cialis
Dosage of xanax
Viagra super active
Valium cheapest
Discount viagra pills
Tramadol dosage
Viagra canada mastercard
Viagra professional online
Viagra canada prices
Purchase phentermine online
Viagra lowest prices
Where to buy viagra in england
Valium from india
Viagra 50mg side effects
Where can i buy viagra without prescription
Valium online fast delivery
Propecia generic canada
Prescriptions for phentermine
Cheap xanax bars
Phentermine online free shipping
Cialis purchase online
Buy cialis online from canada
Levitra purchase
Xanax overnight cod
Generic xanax xr
Generic levitra uk
Xanax 1 mg dose
Buy xanax overnight
Viagra online cheap
Levitra online cheap
Cialis cialis
How to buy phentermine online
Real phentermine without prescription
Prednisone 40 mg
Cialis for sale
Free cialis online
Cialis prescription cost
Free cialis samples
Buy generic valium
Best price on phentermine
Buy viagra online in australia
Buy propecia online without a prescription
Propecia generic online
Cheap generic viagra
Brand name cialis
Viagra 50 mg online without prescription
10mg valium effects
Propecia 1mg generic
Overnight delivery viagra
Ordering cialis online
Xanax bars side effects
Viagra prescription
Viagra for sale online
Levitra online
Generic cialis uk
Cialis 20mg side effects
Xanax with no prescription
Viagra discount coupons
Genuine viagra online
Buy levitra
Buy pfizer viagra without prescription
Buy phentermine online no prescription
Cialis price
Prescription free viagra
Order phentermine online no prescription
Buy cialis uk
Online prescriptions xanax
Drug phentermine
Viagra canadian online pharmacy
Xanax 1mg side effects
Phentermine purchase online
Tramadol no prescription required
Generic cialis overnight
Prescription valium
Purchase tramadol online
Where to buy propecia in canada
Phentermine buy australia
Buying cialis online without a prescription
Australia viagra prescription
Generic tramadol
Viagra cheap no prescription
Purchase levitra online
Canada viagra no prescription
Buy viagra online uk no prescription
Viagra prescription cost
Buy cheap valium online
Where to buy phentermine cheap
Buy phentermine no rx
Propecia ireland
Cheap viagra online without prescription
Phentermine 37.5 buy online
Order viagra without prescription
Valium drug side effects
Levitra price
Viagra pills for sale
Buy viagra uk no prescription
Discount viagra usa
Buy xanax canada
Xanax price per pill
Valium 10 mg
Low price cialis
Cheap xanax for sale
Xanax online cheap
Generic viagra 100mg
Tramadol medication
Valium online pharmacy
Buy brand name viagra
Tramadol for sale
Order cheap phentermine
Buy propecia cheap
Valium online uk
Purchase tramadol without prescription
Get tramadol prescription
Xanax for sale without prescription
Cialis uk sales
100mg tramadol online
Viagra without prescription uk
Buy generic cialis online
Order tramadol online cod
Buy generic xanax no prescription
Phentermine 37.5 pills
Cialis 20 mg dosage
Best viagra alternative
Cialis 20mg
Viagra sale uk
Cheapest cialis price
Phentermine canadian pharmacy
Generic viagra for sale
Levitra 20mg
Cheap cialis
Viagra buy online no prescription
Levitra online buy
Order tramadol cod
Buy viagra online in ireland
Cialis samples canada
Viagra shop online
Buy valium without prescription uk
Prednisone dosages
Viagra in france
Prednisone online
Mail order phentermine
Phentermine 37.5mg
Xanax bars dosage
Buy generic cialis
Valium pill 10mg
Viagra dosage information
Buying valium in spain
Levitra samples
Cheap levitra uk
Buy tramadol cod
Phentermine without a prescription
Generic viagra sales
Phentermine canada no prescription
Buy phentermine no script
Viagra canada online
Buy valium cheap online
Buying viagra in new zealand
Buying viagra in london
Prescription phentermine online
Where can i buy viagra in the uk
Authentic phentermine 37.5
Best levitra prices
Viagra online uk
Prednisone tablets
Propecia cheap
Buy phentermine online without prescription
Order xanax cod
Propecia generic cost
Levitra canada
Buy valium no rx
Best prices for cialis
Buy generic valium online
Generic propecia
Viagra online purchase in india
Buy levitra online canada
Tramadol cod delivery
Buy cialis in the uk
Online valium without prescription
Buy propecia
Generic viagra super active
Phentermine diet pills without prescription
Valium without prescription uk
Buying viagra online
Low cost levitra
Cheapest place to buy viagra online
Where to buy viagra online
Best price tramadol
Online prescription tramadol
Pfizer viagra price
Viagra generic cheap
Cialis ordering
100mg tramadol effects
Viagra fast delivery
Cialis online canadian pharmacy
No prescription cialis online
Tramadol online no prescription overnight
Tramadol free shipping
Propecia uk pharmacy
Generic xanax no prescription
Viagra to buy
Cheapest cialis professional
Buying xanax online without prescription
Buy xanax cheap online
Best viagra dose
Where to buy cialis safely
Purchase phentermine
Overnight tramadol no prescription
Xanax no prescription required
Buy tramadol overnight
Cheap cialis pills
Viagra ordering
Buy generic cialis uk
Buy phentermine 37.5mg online
Cheap tramadol cod
Buying prednisone online
2mg xanax no prescription
Cialis canada no prescription
Propecia cost
Where to buy cialis online
Viagra generic
Viagra indian pharmacy
Propecia online uk
Levitra on sale
Ordering propecia from canada
Cheapest levitra
Viagra online without prescription reviews
Buying tramadol in uk
Cheap cialis india
Generic cialis tadalafil
Tramadol prescription online
Buy viagra uk online
Buy viagra online cheap
Cheap generic valium
Tramadol without prescription overnight delivery
Buy cialis viagra
Generic viagra online without prescription
Buy cheap viagra online uk
Cialis order online
Get viagra
Cheap cialis viagra
Prescription viagra uk
Cheapest generic viagra online
2.5mg cialis
Buy viagra 100mg
Get viagra prescription
Buying levitra without prescription
Best way to take tramadol
Buy viagra australia
Buy female viagra without prescription
Side effects of viagra