You can configure the destination prefetch on the broker configuration via a
DestinationPolicy rather than on the destination in JNDI. Or on the
connection factory. See:
http://activemq.apache.org/what-is-the-prefetch-limit-for.html

Prefetch 0 is useful for a polling consumer, a message is dispatched on
request. With a listener there needs to be some preemptive dispatching,
hence a prefetch > 0.

Dispatching to a new consumer in activemq is by default asynchronous. For
that reason, for synchronous consumers we would recommend looping a timed
receive while null is returned.

while ((msg = receive(timeout)) == null) { // do something else for a bit}


Using dispatchAsync=false is an alternative option for ensuring that
available messages are immediately dispatched to a new synchronous consumer.

But in essence, that root cause is not a bug, it is by design. hope this
helps.

On 8 February 2010 09:58, colincrist <colincr...@hermesjms.com> wrote:

>
>
>
> Hi Gary,
>
> Thanks for the workaround but this only works with synchronous consumers -
> when I use the same topic (obtained from JNDI in reality - unlike the code
> I
> shared) with an async consumer I get:
>
> javax.jms.JMSException: Illegal prefetch size of zero. This setting is not
> supported for asynchronous consumers please set a value of at least 1
>        at
>
> org.apache.activemq.ActiveMQMessageConsumer.setMessageListener(ActiveMQMessageConsumer.java:377)
>
> This means I would need to have different topics in JNDI for different
> styles of consumer. Ugly.
>
> The root cause is clearly a bug that needs fixing - is there a way to raise
> it somewhere?
>
> Colin.
>
>
>
>
> Gary Tully wrote:
> >
> > with prefetch=0 it should work ok as this will force a receive() to poke
> > the
> > broker rather than depending on async delivery.
> >
> > change:
> >
> > queue = session.createQueue("TEST");
> >
> > to
> >
> > queue = session.createQueue("TEST?consumer.prefetchSize=0");
> >
> >
> > On 4 February 2010 11:33, colincrist <colincr...@hermesjms.com> wrote:
> >
> >>
> >> See attached unit test. The receiveOneMessageUsingSessionListener() test
> >> hangs.
> >>
> >> Tests all work okay with, for example, Tibco EMS.
> >>
> >> http://old.nabble.com/file/p27451302/PublicTestMessageExchange.java
> >> PublicTestMessageExchange.java
> >>
> >> Regards,
> >>
> >> Colin.
> >> --
> >> View this message in context:
> >>
> http://old.nabble.com/Session.setMessageListener-not-working-in-5.3.2-tp27451302p27451302.html
> >> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > http://blog.garytully.com
> >
> > Open Source Integration
> > http://fusesource.com
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/Session.setMessageListener-not-working-in-5.3.2-tp27451302p27497580.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


-- 
http://blog.garytully.com

Open Source Integration
http://fusesource.com

Reply via email to