You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Alex Dean <ad...@meteostar.com> on 2010/07/09 20:50:03 UTC

messages sent via stomp are not received in ajax client

I have a Ruby script which publishes a message to an ActiveMQ topic  
via Stomp.  I'm attempting to send these messages to the topic used by  
the demo chat.html included in ActiveMQ, so I'm using the XML message  
format expected by that page.  chat.html is this one : http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web-demo/src/main/webapp/chat.html?r=HEAD

This is the publisher script:
--- START -------------------------------------
#!/usr/bin/env ruby

require 'rubygems'
require 'stomp'

conn = Stomp::Client.open("", "", "dev-1-dist1", 3037, false)

puts 'join'
conn.send('/topic/CHAT.DEMO', "<message type='join' from='alexbot'/>")
sleep 3

puts 'sent 1'
conn.send('/topic/CHAT.DEMO', "<message type='chat'  
from='alexbot'>test one</message>")
sleep 3

puts 'left'
conn.send('/topic/CHAT.DEMO', "<message type='leave' from='alexbot' />")
--- END -------------------------------------

I have another Ruby script subscribed to this topic as well.
--- START -----------------------------------
#!/usr/bin/env ruby

require 'rubygems'
require 'stomp'
require 'activesupport'
require 'cgi'

conn = Stomp::Client.open("", "", "dev-1-dist1", 3037, false)

conn.subscribe('/topic/CHAT.DEMO') do |msg|
   puts "#{Time.now}: #{msg.body}"
end

conn.join
--- END -------------------------------------

My test is:
1. Browse to http://dev-1-dist1:8161/demo/chat.html
2. Join the chat room.
3. Start my Ruby subscriber
4. Start my Ruby publisher.

Results:
In the Ruby subscriber, I see all my messages.  I see none of them in  
the chat room.

Instead, Firebug shows that empty messages are being received.
 From Firebug:
GET http://dev-1-dist1:8161/demo/amq 200 OK 2.66s
GET http://dev-1-dist1:8161/demo/amq 200 OK 2.9s
GET http://dev-1-dist1:8161/demo/amq 200 OK 2.93s

As I watch Firebug and my Ruby publisher in separate windows, I can  
see that the GET requests are in sync with when the Ruby script is  
sending its messages.  chat.html is receiving the messages.  The  
contents of the messages are empty, however.
Example:
<ajax-response> <response id='chat' destination='topic://CHAT.DEMO' ></ 
response> </ajax-response>

A message that I send from chat.html does have content, and I do  
receive those in both Javascript and in Ruby.
Example:
<ajax-response> <response id='chat' destination='topic://CHAT.DEMO'  
 ><message type='chat' from='alex'>test message</message></response> </ 
ajax-response>

At the same time that I get these empty responses in chat.html, I get  
the following output from my Ruby subscriber (and from my own  
submission via chat.html):
Fri Jul 09 13:35:04 -0500 2010: <message type='join' from='alexbot'/>
Fri Jul 09 13:35:07 -0500 2010: <message type='chat'  
from='alexbot'>test one</message>
Fri Jul 09 13:35:10 -0500 2010: <message type='chat'  
from='alexbot'>test two</message>
Fri Jul 09 13:35:13 -0500 2010: <message type='chat'  
from='alexbot'>test three</message>
Fri Jul 09 13:35:16 -0500 2010: <message type='leave' from='alexbot' />
Fri Jul 09 13:37:28 -0500 2010: <message type='chat' from='alex'>test  
message</message>

Any idea what's going on here?  There are no proxies involved this  
time.  All clients are connecting directly to ActiveMQ/Jetty.

thanks,
alex

Environment:
client:
Mac OSX 10.5.6
Firefox 3.6

server:
Centos 5.4
ActiveMQ 5.3.0
java version "1.5.0_03"
Ruby 1.8.7 with stomp-1.0.4 gem

Re: messages sent via stomp are not received in ajax client

Posted by Alex Dean <ad...@meteostar.com>.
As a followup:  We were looking over the release notes for AMQ 5.4  
today, and a co-worker noticed https://issues.apache.org/activemq/browse/AMQ-2833 
.  This allows Stomp clients to indicate text vs byte messages via a  
new custom Stomp header.  This is perfect for our situation, and we're  
looking forward to a 5.4 upgrade in the near future.

alex

On Jul 12, 2010, at 12:48 AM, Dejan Bosanac wrote:

> Hi Alex,
>
> I think it's a bigger problem to pass and handle byte[] content in
> JavaScript. All patches are welcomed, of course :)
>
> 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 11:55 PM, Alex Dean <ad...@meteostar.com>  
> wrote:
>>
>> On Jul 9, 2010, at 3:44 PM, Alex Dean wrote:
>>
>>>
>>> On Jul 9, 2010, at 1:50 PM, Alex Dean wrote:
>>>
>>>> I have a Ruby script which publishes a message to an ActiveMQ  
>>>> topic via
>>>> Stomp.  I'm attempting to send these messages to the topic used  
>>>> by the demo
>>>> chat.html included in ActiveMQ, so I'm using the XML message  
>>>> format expected
>>>> by that page.  chat.html is this one :
>>>> http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web-demo/src/main/webapp/chat.html?r=HEAD
>>>
>>> My problem appears to be the same one described here :
>>> http://juretta.com/log/2009/05/24/activemq-jms-stomp/
>>>
>>> Stomp messages which include a content-length header are converted  
>>> to
>>> BytesMessages by ActiveMQ.  Messages without a content-length  
>>> header are
>>> converted to TextMessages.  TextMessages are delivered to  
>>> JavaScript OK via
>>> AJAX, but BytesMessages are not.
>>>
>>> If I hack the Ruby stomp code to not send a content-length header,  
>>> my
>>> Ruby-published messages start appearing in chat.html.  Is there a  
>>> better way
>>> to solve this problem?
>>
>> For a little more background, http://activemq.apache.org/stomp.html  
>> says
>> that Stomp messages lacking a content-length header are converted  
>> to JMS
>> TextMessage instances.  Messages containing a content-length header  
>> are
>> converted to BytesMessage instances.  MessageListenerServlet.java  
>> makes no
>> attempt to send a BytesMessage to an ajax client, hence the empty  
>> message
>> when content-length is present.
>>
>> See writeMessageResponse in this class:
>> http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java?r=HEAD
>>
>> I'm trying to determine if it's feasible to try to handle  
>> BytesMessage
>> instances in MessageListenerServlet.  Perhaps via  
>> BytesMessage.readUTF8()?
>>  I'm not very familiar with ActiveMQ or JMS, so I'm not sure what the
>> implications of this might be.
>>
>> thanks,
>> alex
>>


Re: messages sent via stomp are not received in ajax client

Posted by Dejan Bosanac <de...@nighttale.net>.
Hi Alex,

I think it's a bigger problem to pass and handle byte[] content in
JavaScript. All patches are welcomed, of course :)

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 11:55 PM, Alex Dean <ad...@meteostar.com> wrote:
>
> On Jul 9, 2010, at 3:44 PM, Alex Dean wrote:
>
>>
>> On Jul 9, 2010, at 1:50 PM, Alex Dean wrote:
>>
>>> I have a Ruby script which publishes a message to an ActiveMQ topic via
>>> Stomp.  I'm attempting to send these messages to the topic used by the demo
>>> chat.html included in ActiveMQ, so I'm using the XML message format expected
>>> by that page.  chat.html is this one :
>>> http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web-demo/src/main/webapp/chat.html?r=HEAD
>>
>> My problem appears to be the same one described here :
>> http://juretta.com/log/2009/05/24/activemq-jms-stomp/
>>
>> Stomp messages which include a content-length header are converted to
>> BytesMessages by ActiveMQ.  Messages without a content-length header are
>> converted to TextMessages.  TextMessages are delivered to JavaScript OK via
>> AJAX, but BytesMessages are not.
>>
>> If I hack the Ruby stomp code to not send a content-length header, my
>> Ruby-published messages start appearing in chat.html.  Is there a better way
>> to solve this problem?
>
> For a little more background, http://activemq.apache.org/stomp.html says
> that Stomp messages lacking a content-length header are converted to JMS
> TextMessage instances.  Messages containing a content-length header are
> converted to BytesMessage instances.  MessageListenerServlet.java makes no
> attempt to send a BytesMessage to an ajax client, hence the empty message
> when content-length is present.
>
> See writeMessageResponse in this class:
> http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java?r=HEAD
>
> I'm trying to determine if it's feasible to try to handle BytesMessage
> instances in MessageListenerServlet.  Perhaps via BytesMessage.readUTF8()?
>  I'm not very familiar with ActiveMQ or JMS, so I'm not sure what the
> implications of this might be.
>
> thanks,
> alex
>

Re: messages sent via stomp are not received in ajax client

Posted by Alex Dean <ad...@meteostar.com>.
On Jul 9, 2010, at 3:44 PM, Alex Dean wrote:

>
> On Jul 9, 2010, at 1:50 PM, Alex Dean wrote:
>
>> I have a Ruby script which publishes a message to an ActiveMQ topic  
>> via Stomp.  I'm attempting to send these messages to the topic used  
>> by the demo chat.html included in ActiveMQ, so I'm using the XML  
>> message format expected by that page.  chat.html is this one : http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web-demo/src/main/webapp/chat.html?r=HEAD
>
> My problem appears to be the same one described here : http://juretta.com/log/2009/05/24/activemq-jms-stomp/
>
> Stomp messages which include a content-length header are converted  
> to BytesMessages by ActiveMQ.  Messages without a content-length  
> header are converted to TextMessages.  TextMessages are delivered to  
> JavaScript OK via AJAX, but BytesMessages are not.
>
> If I hack the Ruby stomp code to not send a content-length header,  
> my Ruby-published messages start appearing in chat.html.  Is there a  
> better way to solve this problem?

For a little more background, http://activemq.apache.org/stomp.html  
says that Stomp messages lacking a content-length header are converted  
to JMS TextMessage instances.  Messages containing a content-length  
header are converted to BytesMessage instances.   
MessageListenerServlet.java makes no attempt to send a BytesMessage to  
an ajax client, hence the empty message when content-length is present.

See writeMessageResponse in this class:
http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web/src/main/java/org/apache/activemq/web/MessageListenerServlet.java?r=HEAD

I'm trying to determine if it's feasible to try to handle BytesMessage  
instances in MessageListenerServlet.  Perhaps via  
BytesMessage.readUTF8()?  I'm not very familiar with ActiveMQ or JMS,  
so I'm not sure what the implications of this might be.

thanks,
alex

Re: messages sent via stomp are not received in ajax client

Posted by Alex Dean <ad...@meteostar.com>.
On Jul 9, 2010, at 1:50 PM, Alex Dean wrote:

> I have a Ruby script which publishes a message to an ActiveMQ topic  
> via Stomp.  I'm attempting to send these messages to the topic used  
> by the demo chat.html included in ActiveMQ, so I'm using the XML  
> message format expected by that page.  chat.html is this one : http://fisheye6.atlassian.com/browse/activemq/branches/activemq-5.3/activemq-web-demo/src/main/webapp/chat.html?r=HEAD

My problem appears to be the same one described here : http://juretta.com/log/2009/05/24/activemq-jms-stomp/

Stomp messages which include a content-length header are converted to  
BytesMessages by ActiveMQ.  Messages without a content-length header  
are converted to TextMessages.  TextMessages are delivered to  
JavaScript OK via AJAX, but BytesMessages are not.

If I hack the Ruby stomp code to not send a content-length header, my  
Ruby-published messages start appearing in chat.html.  Is there a  
better way to solve this problem?

thanks,
alex