0
votes

I am using Spring JMS with ActiveMQ as the broker and running the application on Tomcat. I have one queue, let's say queue.a. In my web app, I already have a MessageListener running whenever I start my web app. The only thing is, I want to add some kind of queue consumer but synchronously. I already try using JmsTemplate etc. But when both of my consumer (listener async & consumer synchronous) is up and I trigger the .receive() method, the message sent to the queue always sucked up to the message listener that have been always online since the web app started. After the end of the timeout,the synchronous receiver did not consume any message at all.

But,when I comment out the messageListener, the synchronous customer run well.

I'm still a newbie,do any of you have any way to make what I want possible? Thanks! Sorry for my bad english :(

1
Are you using defaults for everything on your consumers and queue config (prefetch, exclusive, priority, etc)?Erik Williams
I think yes because I am new in using JMS in spring..Is there any way to do the config?Is it inside the beans config?I just follow everything in the doc & internetNico
It sounds very much like you have an exclusive consumer. Do you have anything set like this on your consumer that is getting the messages: YOUR.QUEUE?consumer.exclusive=true And have you verified that the consumer using receive() has a handle on the queue (consumer count +1 )?Erik Williams
this is the other way to answer this question. thanks erik, but i already use consumer.priority. is it better to use consumer.exclusive?hmm,i'm considering to build the same implementation but not with 2 consumer,just 1 listener.is there any kind of queue manager that can be used?Nico
You use exclusive consumer when you want to be sure only one consumer is given messages (first come fist serve). Priority will always try to give the highest priority consumer messages first, but give other consumers a chance when the higher priority consumer is tied up.Erik Williams

1 Answers

0
votes
<bean id="someQueue" class="org.apache.activemq.command.ActiveMQQueue">
  <constructor-arg index="0" value="TEST.QUEUE?consumer.priority=10" />
</bean>

and then, set it to your listener/receiver bean:

<bean id="someReceiver" class="blah.blah.SomeReceiver">
  <property name="destination" ref="someQueue" />
  <property name="jmsTemplate" ref="jmsTemplate" />
</bean>

Does this solve your problem?