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 ]
(he.activemq.broker.region.AbstractRegion)
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: 
http://www.nabble.com/Able-to-send-message-to-ActiveMQ-but-Not-getting-reply-to-Client-tf4400842s2354.html#a12924311
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to