You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Interition <pa...@interition.net> on 2006/06/22 13:37:07 UTC

AJAX

I am trying to familiarise myself with
org.apache.activemq.web.MessageListenerServlet to publish and subscribe to
ActiveMQ topics.

The servlet is working and logging so I can monitor it.  I have a simple
publisher that appears to be able to post to a specified topic but my simple
subscriber just never seems to receive anything.  Help appreciated big time. 
Snippets below...

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

<html>
    <head>
        <title>Message Publishing</title>
        <script type="text/javascript" src="js/prototype.js"></script>
        <script type="text/javascript" src="js/behaviour.js"></script>
        <script type="text/javascript" src="js/_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="js/prototype.js"></script>
        <script type="text/javascript" src="js/behaviour.js"></script>
        <script type="text/javascript" src="js/_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>
--
View this message in context: http://www.nabble.com/AJAX-t1829608.html#a4991458
Sent from the ActiveMQ - User forum at Nabble.com.


Re: AJAX

Posted by Interition <pa...@interition.net>.
Currently we are simply using the activemq-web-demo with our simple
MessagePublisher.html and MessageListener.html.  Both of these include the
same javascript declerations as the Portfolio demo.  However, the Portfolio
demo uses a servlet to generate stock data on to the JMS topics.  Therefore
my MessagePublisher.html just follows the instructions in the documentation
on how to publish data to topics.

eg.
<script type="text/javascript">
                function publishMessage() {
		
amq.sendMessage("topic://MY.TEST","<data><item>HelloWorld</item></data>");
                 }
        </script>
    </head>
    <body>
        <form action="#">
            <input type="button" value="Publish Message" 
onclick="publishMessage();"/>
        </form>
    </body>

However, it appears that only every second publish action results in the
MessageListener.html receiving the object.  There must be a clue to the
problem in that?

Thanks
-- 
View this message in context: http://www.nabble.com/AJAX-tf1829608.html#a5182950
Sent from the ActiveMQ - User forum at Nabble.com.


Re: AJAX

Posted by Pradeepp <v....@live.com>.
Hi 

 This is pradeep form b'lore i had written a codings to store a message in
the 
ActiveMQ, While executing the codins every thing is working properly, but
not storing 
into the queue.

Along with this mail i attaching my codings for ur reference 
If u find any changes please inform me as soon as possible.



Regards
Pradeep Nair http://www.nabble.com/file/p19738603/amq.js amq.js 
http://www.nabble.com/file/p19738603/Src.asp Src.asp 





-- 
View this message in context: http://www.nabble.com/AJAX-tp4991458p19738603.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: AJAX

Posted by Interition <pa...@interition.net>.
Hi,

Yes, when I first looked at the code I thought AjaxServlet was specific to
the stock quote example so I assumed I had to work with the
MessageListenerService directly.  It was very early on in looking at the
sample  and playing with AJAX so maybe I've taken the wrong path and need to
go back.

I'll take a look again when I'm back from Apache Europe :-)

Ta
-- 
View this message in context: http://www.nabble.com/AJAX-tf1829608.html#a5063501
Sent from the ActiveMQ - User forum at Nabble.com.


Re: AJAX

Posted by James Strachan <ja...@gmail.com>.
Just out of interest; whats wrong with using the same Ajax client and
servlet that the web-demo uses?

On 6/26/06, Interition <pa...@interition.net> wrote:
>
> Thanks Patrick.
>
> I am now getting the same. Message listener picks up what seems to be every
> second post to the topic.  Has anyone built anything using
> org.apache.activemq.web.AjaxServlet, or MessageListenerServlet directly,
> that is usable ?
>
> Should I persist in trying to get it to work.  Digging through its code or
> implement my own Servlet to send/receive web posts to topics?
> --
> View this message in context: http://www.nabble.com/AJAX-t1829608.html#a5047234
> Sent from the ActiveMQ - User forum at Nabble.com.
>
>


-- 

James
-------
http://radio.weblogs.com/0112098/

Re: AJAX

Posted by Interition <pa...@interition.net>.
Thanks Patrick.

I am now getting the same. Message listener picks up what seems to be every
second post to the topic.  Has anyone built anything using
org.apache.activemq.web.AjaxServlet, or MessageListenerServlet directly,
that is usable ?

Should I persist in trying to get it to work.  Digging through its code or
implement my own Servlet to send/receive web posts to topics?
--
View this message in context: http://www.nabble.com/AJAX-t1829608.html#a5047234
Sent from the ActiveMQ - User forum at Nabble.com.


Re: AJAX

Posted by Patrick Villacorta <pv...@exist.com>.
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>

Re: AJAX

Posted by Interition <pa...@interition.net>.
Whoops! The x } must have snuck in.  I've made the changes as suggested and I
have tried to remove all externalities by putting the two .html files in to
the activem-web-demo source and running mvn jetty6:run.  I am also running
greasemonkey with the XMLHttpRequest debugging script.

MessageListener.html
=============
<html>
    <head>
        <title>MessageListener Test</title>
        <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>

XMLHttpRequest Output
===============

All reports produce:

GET amq
X-Requested-With:XMLHttpRequest
X-Prototype-Version:1.4.0

null

200 (OK)

Content-Type: text/xml; charset=ISO-8859-1
Cache-Control: no-cache
Content-Length: 35
Connection: keep-alive
Server: Jetty(6.0.x)

<ajax-response>
</ajax-response>

MessagePublisher.html
==============
<html>
    <head>
        <title>Message Publishing</title>
        <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","sadfasdfasdfasdf");
                 }
        </script>
    </head>
    <body>
        <form action="#">
            <input type="button" value="Publish Message"
onclick="publishMessage();"/>
        </form>
    </body>
</html>

XMLHttpRequest Output
===============

Two reports occur, first:

POST amq
X-Requested-With:XMLHttpRequest
X-Prototype-Version:1.4.0
Content-type:application/x-www-form-urlencoded
Connection:close

destination=topic://MY.TEST&message=sadfasdfasdfasdf&type=send

200 (OK)

Content-Type: text/plain; charset=ISO-8859-1
Cache-Control: no-cache
Connection: close
Server: Jetty(6.0.x)

ID:RACETEXT01-1931-1151048582000-3:0:1:1:1


second report:

GET amq
X-Requested-With:XMLHttpRequest
X-Prototype-Version:1.4.0

null

200 (OK)

Content-Type: text/xml; charset=ISO-8859-1
Cache-Control: no-cache
Content-Length: 35
Connection: keep-alive
Server: Jetty(6.0.x)

<ajax-response>
</ajax-response>




--
View this message in context: http://www.nabble.com/AJAX-t1829608.html#a5007683
Sent from the ActiveMQ - User forum at Nabble.com.


Re: AJAX

Posted by Patrick Villacorta <pv...@exist.com>.
Hi,

You have an extra "}" after the _feed function

I also did the following in case the above doesn't fix it:

change your script includes to:
<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>

- or just -

<script type="text/javascript" src="amq/amq.js"></script>

These jars are served from activemq-web.jar so you don't have to copy 
all the js files

If it still doesn't work, please also send your web.xml.

Regards,
Patrick



Interition wrote:
> I am trying to familiarise myself with
> org.apache.activemq.web.MessageListenerServlet to publish and subscribe to
> ActiveMQ topics.
>
> The servlet is working and logging so I can monitor it.  I have a simple
> publisher that appears to be able to post to a specified topic but my simple
> subscriber just never seems to receive anything.  Help appreciated big time. 
> Snippets below...
>
> MessagePublisher.html
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
>
> <html>
>     <head>
>         <title>Message Publishing</title>
>         <script type="text/javascript" src="js/prototype.js"></script>
>         <script type="text/javascript" src="js/behaviour.js"></script>
>         <script type="text/javascript" src="js/_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="js/prototype.js"></script>
>         <script type="text/javascript" src="js/behaviour.js"></script>
>         <script type="text/javascript" src="js/_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>
> --
> View this message in context: http://www.nabble.com/AJAX-t1829608.html#a4991458
> Sent from the ActiveMQ - User forum at Nabble.com.
>
>