activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hackingbear <hackingb...@gmail.com>
Subject Prefetch=0 how to?
Date Sun, 15 Feb 2009 00:10:13 GMT

Hi,

I have two server components in my system. A gateway server and multiple
application server.

The gateway server communicates with external system and does the following:
1. receive tokens from the external system and place them in a queue (the
token queue.)
2. receive business requests from application servers and send them to the
external system

My application servers essentially do the following:

1. receive some user messages from somewhere
2. get a token from the token queue (by calling consumer.receive())
3. create and send a business request message from the token (and other
data)

The problem is that the tokens are expensive, costing money literally, and
so there are maybe only a few available at a time.

Now, for example, the gateway sends out two (and only two) tokens A and B;
there are two application servers running, each having a consumer on the
token queue. Server 2 is idle while Server 1 receives two user messages.

- Server 1 receives user message 1, and so try to get a token, get token A
and send out the business request. Everything is fine so far.
- Server 1 receives user message 2, and so try to get a token, get token B,
but get stuck.

What happen? Token B gets pre-fetched to Server 2's consumer even though
that server never actually need it. I have set the prefetch to 1.

Following http://activemq.apache.org/what-is-the-prefetch-limit-for.html, I
then attempt to create the consumer with prefetch=0

  queue = new ActiveMQQueue("TOKEN.QUEUE?consumer.prefetchSize=0");
  consumer = session.createConsumer(queue);

However, the effect is identical to prefetch=1: token B still get
pre-fetched to Server 2.

now, my solution is to write an async consumer which will, upon receiving a
token, check if there is any local request pending, if not, send it back to
the queue. the downside is, of course, the consumer would loop and resending
the tokens forever even if the servers are idle.

Any better solution?

Thanks

-- 
View this message in context: http://www.nabble.com/Prefetch%3D0-how-to--tp22018602p22018602.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message