activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JigarP <>
Subject Re: Able to send message to ActiveMQ but Not getting reply to Client
Date Fri, 28 Sep 2007 02:58:06 GMT

Hi Chago,

     you have explain each scenario clearly. just want to know that at
server side/client side what sort of confuguration should i do so that
atleast it will not destroy my consumer. i am attaching my client side code
let me know if you get some clue.

Below three methods i am calling in below sequence.

1) When page is loaded register listener topic using onStartListen() method.
2) When user enter message and click on send message then it will call
onSendMessage() method.
3) call handleNewMessage() if we get any message.

below are the topic which we are using to send chat to server and get reply
from server.
function setTopicName(){
	sendTopicName = 'topic://doChat' ;
	receiveTopicName = '/topic/ChatTopic';
This method register topic to MQ.
function onStartListen(){
    amq.addListener('chat', receiveTopicName, handleNewMessage);


This method will chat message to MQ 
function onSendMessage(msgStr){
    amq.sendMessage(sendTopicName, msgStr);
function handleNewMessage(){
//process the received message.

I have found that if i click on send button continuosly then messages are
coming to servr as well as it also resides at activemq but i am not able to
get messages at client side back.

I hope u are able to understand this.

chago wrote:
> When amq.addListener(id, destination, handler) is invoked for the first
> time, the javascript class creates a POST request to the AjaxServlet. The
> AjaxServlet is really just a facade to the MessageListenerServlet which in
> turn extends MessageServletSupport. The POST request takes the Javascript
> parameters and turns them into:
>     - destination = destination
>     - message = id
>     - type = 'listen'
> The servlet then performs the following functions:
> 1. A Destination is created based on the POST parameter 'destination'. I
> haven't traced this very far into ActiveMQ, but it seems to create a new
> Topic/Queue each time it is called, even if that destiantion already
> existed. Perhaps the newly created destination is just a proxy to a
> permanent destination? I was surprised that the code doesn't check for the
> existence of the detination before creating a new one. Can anyone
> elaborate?
> 2. The MessageListenerServlet will create a Listener and store it in the
> client's HTTP Session under the parameter name 'mls.listener'.  The
> Listener class is notified when a message is available via its
> onMessageAvailable(MessageConsumer) method.
> 3. The MLS will create a HashMap of consumer IDs. The key to this map is a
> MessageAvailableConsumer and the value is a String that holds the 'id'
> value passed to the javascript function. This map is also stored in the
> client's HTTP Session under the parameter name of 'mls.consumerIdMap'. The
> map is empty at this time.
> 4. The MLS will also create an empty HashMap that allows lookup of a
> destination name based on an instance of MessageAvailableConsumer. This
> map is stored in the session under 'mls.consumerDestinationNameMap'.
> 5. If any consumers had been previously created for the given destination,
> they are closed.
> 6. If a MessageConsumer already exists for the given destination it is
> used, otherwise a new MessageConsumer is created. A MessageConsumer is a
> JMS construct that receives messages from the JMS broker. The
> MessageConsumer that is created is instanced in the WebClient class which
> is also stored in the HTTP session.
> 7. The Listener created earlier is associated with the consumer to allow
> for asynchronous receipt of messages.
> 8. The MessageConsumer is related to the id parameter and the destination
> name using the prior two maps. 
> That's how a consumer is created. The only ways a consumer is destroyed in
> the normal course of operation are:
> 1. amq.removeListener(id, destination) is invoked causing the server to
> process an 'unlisten' message.
> 2. amq.addListener(id, destination, callback) is invoked causing the
> server to process a 'listen' message. If a prior consumer was created
> using this destination, it is closed. (See #5 above.)
> 3. If the Listener class receives an onMessageAvailable call, and the
> Listener hasn't been called for 50 secs, the consumer is closed. This
> appears to me to be an attempt to close those consumers who have not
> polled for two cycles. I am asuming that this is the server cleaning up
> consumers that are no longer needed because the browser has closed. Adding
> a debug message to this section of code would be useful.
> 4. When the HTTP session passivates or is closed, the WebClient is closed
> along with all the consumers.
> Things to look for in your debug log are messages relating to the closing
> of consumers. Mine looks like this:
> 2007-09-24 20:07:19,968 DEBUG [VMTransport ]
> (
> Removing consumer: ID:zd7000-2475-1190676467171-2:0:1:1
> I'd like to see your client-side code. Are you doing anything server-side?
> -- jim
> JigarP wrote:
>> Hi Chago,
>>    Ya, you are right. when _amq.js is loaded polling will start. i agree
>> that that time listener will not be there but when i register my listener
>> using amq.aadListener then after it should get data,rgt. so even if i
>> have registered my listener i was not able to get any messages. so i
>> think ajaxservlet will be removing listener at server side on the basis
>> of the condition. i dont know when they remove consumer for specifit
>> topic/channel from server.
>> which side of code u want to check. server side or javascript?

View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message