activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dejan Bosanac <de...@nighttale.net>
Subject Re: help with ajax
Date Mon, 12 Jul 2010 05:27:43 GMT
Hi Alex,

glad to hear that and thanks for sharing your findings back.

Cheers
--
Dejan Bosanac - http://twitter.com/dejanb

Open Source Integration - http://fusesource.com/
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net



On Fri, Jul 9, 2010 at 3:58 PM, Alex Dean <adean@meteostar.com> wrote:
> I've discovered my problem stems from Apache's proxy configuration, not from
> ActiveMQ itself.
>
> When I loaded the HTML test page directly from ActiveMQ/Jetty, rather than
> from Apache, the example ajax scripts worked perfectly.  They only failed
> when I loaded the HTML from Apache, and let Apache proxy my ajax requests
> back to ActiveMQ.
>
> I think the problem was that the JSESSIONID cookie was not being modified
> correctly.  ActiveMQ set the cookie for 'path=/demo', while the URL which
> was seen by clients was /amq.  So on subsequent requests, the client would
> not send the cookie back to the server.  I'm not sure what the role of this
> cookie (and session) are inside ActiveMQ, but once I configured Apache to
> rewrite the cookie path correctly, I was able to start receiving messages
> via ajax through the proxy.
>
> This is the Apache configuration which worked for me:
>  ProxyRequests Off
>  ProxyPass /amq http://localhost:8161/demo
>  ProxyPassReverse /amq http://localhost:8161/demo
>  ProxyPassReverseCookiePath /demo /amq
> http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse
>
> My JavaScript uses "amq.uri = '/amq/amq'", so requests for
> 'http://localhost/amq/amq' are proxied back to
> 'http://localhost:8161/demo/amq'.  Cookies returned by ActiveMQ with
> 'path=/demo' are rewritten by Apache, so the client sees 'path=/amq'.
>
> alex
>
> On Jul 8, 2010, at 5:12 AM, Dejan Bosanac wrote:
>
>> Hi,
>>
>> can you test the snapshot. There are some refactoring in those areas
>> lately.
>>
>> Also, try using the modified client side API, like show here
>>
>>
>> http://fisheye6.atlassian.com/browse/activemq/trunk/activemq-web-demo/src/main/webapp/test/subscribe_send.html?r=HEAD
>>
>> BTW. messages sent to the topic before you subscribed will not be
>> received by your subscriber. That's just how topics works.
>>
>> Cheers
>> --
>> Dejan Bosanac - http://twitter.com/dejanb
>>
>> Open Source Integration - http://fusesource.com/
>> ActiveMQ in Action - http://www.manning.com/snyder/
>> Blog - http://www.nighttale.net
>>
>>
>>
>> On Wed, Jul 7, 2010 at 9:24 PM, Alex Dean <adean@meteostar.com> wrote:
>>>
>>> Hello.  I'm trying out the ActiveMQ ajax messaging described at
>>> http://activemq.apache.org/ajax.html.
>>>
>>> I am able to send messages to a topic using this code:
>>>  <script type="text/javascript" src="/amq/amq.js"></script>
>>>  <script>
>>>  amq.uri='/amq';
>>>  amq.sendMessage('topic://MY.DEMO', "<message item='hello again x'/>");
>>>  </script>
>>>
>>> When I run that snippet, I see (in the ActiveMQ admin application) that
>>> the
>>> topic gets created and that the 'Messages Enqueued' value goes to '1'.
>>>
>>> Next, I try to subscribe to the topic using the following Javascript (in
>>> a
>>> separate web page):
>>>  <script type="text/javascript" src="/amq/amq.js"></script>
>>>  <script>
>>>  amq.uri='/amq';
>>>
>>>  myHandler = {
>>>    rcvMessage: function(message) {
>>>      console.log( 'got message' );
>>>    }
>>>  };
>>>  amq.addListener('test_subscriber','topic://MY.DEMO',
>>> myHandler.rcvMessage
>>> );
>>>  </script>
>>>
>>> When I run this, I see the 'Number of Consumers' go to '1' in the admin
>>> application.  Using Firebug, I see amq.js performing a POST like
>>> 'destination=topic://MY.DEMO&message=test_subscriber&type=listen'.  This
>>> seems to be as expected based on the tutorial.  I then see amq.js perform
>>> a
>>> series of GET requests.  The first is
>>> 'https://localhost:7998/amq?timeout=10&_=', and successive GETs are
>>> 'https://localhost:7998/amq'.
>>>
>>> All of these GETs are returned with empty responses, like
>>> '<ajax-response></ajax-response>'.  The first one appears to return
>>> immediately, and the subsequent GETs time out after maybe 20-30 seconds.
>>>
>>> When I next publish a new message to the topic, the 'Number of Consumers'
>>> immediately goes to '0'.  The consumer's current GET request doesn't
>>> appear
>>> to return at this time, rather it seems to time out just like the others.
>>>  (I expected that ActiveMQ would return the message to the consumer as
>>> soon
>>> as it was available, and then close the connection.)
>>>
>>> I noticed the following snippet from the logs from around the time a
>>> message
>>> was published (while the consumer was active):
>>> jvm 1    | DEBUG | Sent <message item='hello again x'/> to
>>> topic://MY.DEMO
>>> jvm 1    | DEBUG | RESPONSE /demo/amq  200
>>> jvm 1    | DEBUG | message for ActiveMQMessageConsumer {
>>> value=ID:rutabaga.local-63558-1278527484508-2:1:1:1, started=true
>>> }continuation=null
>>> jvm 1    | DEBUG | localhost removing consumer:
>>> ID:rutabaga.local-63558-1278527484508-2:1:1:1 for destination:
>>> topic://MY.DEMO
>>>
>>> I have 2 questions at the moment:
>>> 1. Why does my consumer not receive the messages published to the topic?
>>> 2. Why is my consumer unsubscribed when a message is sent?
>>>
>>> Any help is appreciated.
>>>
>>> regards,
>>> alex
>>>
>>> My environment:
>>> Mac OSX 10.5.6
>>> ActiveMQ 5.3.2
>>>
>>> java version "1.5.0_22"
>>> Java(TM) 2 Runtime Environment, Standard Edition (build
>>> 1.5.0_22-b03-333-9M3125)
>>> Java HotSpot(TM) Client VM (build 1.5.0_22-147, mixed mode, sharing)
>>>
>>> Apache is listening on port 7998.
>>> Apache is proxying requests to ActiveMQ using the directive 'ProxyPass
>>> /amq
>>> http://localhost:8161/demo/amq'
>>>
>
>

Mime
View raw message