activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Villacorta <pvillaco...@exist.com>
Subject Re: AJAX
Date Fri, 23 Jun 2006 09:43:11 GMT
I did the same as you and ran loaded the pages from activemq-web-demo. I 
was able to get the message listener to receive messages but it doesn't 
seem to work consistently. I sometimes refresh the pages for a message 
to be received. Soemetimes a message is received after every other 
publish click. Strange...


These are the files I used. Though I think they're pretty much the same 
as your files now. Watch out for possible line breaks in the javascript:

===================================
MessagePublisher.html
===================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <title>Message Publishing</title>
    <!--script type="text/javascript" src="amq/prototype.js"></script>
    <script type="text/javascript" src="amq/behaviour.js"></script>
        <script type="text/javascript" src="amq/_amq.js"></script-->
    <script type="text/javascript" src="amq/amq.js"></script>
        <script type="text/javascript">amq.uri='amq';</script>
        <script type="text/javascript">
                function publishMessage() {
                  amq.sendMessage("topic://MY.TEST","<data><item>Hello 
World</item></data>");
                 }
        </script>
    </head>
    <body>
        <form action="#">
            <input type="button" value="Publish Message"
    onclick="publishMessage();"/>
        </form>
    </body>
</html>


==========================================
MessageListener.html
==========================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <title>MessageListener Test</title>
    <!--script type="text/javascript" src="amq/prototype.js"></script>
    <script type="text/javascript" src="amq/behaviour.js"></script>
        <script type="text/javascript" src="amq/_amq.js"></script-->
    <script type="text/javascript" src="amq/amq.js"></script>
        <script type="text/javascript">amq.uri='amq';</script>
        <script type="text/javascript">
                var feedHandler =
                {
                  _feed: function(message)
                  {
                        alert("received: " +message);
                        document.getElementById("result").innerHTML = 
message;
                    }
                };

                function chartPoll(first)
                {
                   if (first)
                   {
                   
amq.addListener('charts','topic://MY.TEST',feedHandler._feed);
                   }
                }

                amq.addPollHandler(chartPoll);
        </script>
    </head>
    <body>
        <h1>Message Listener</h1>
        <hr/>
        <div id="result"></div>
    </body>
</html>

Mime
View raw message