I try to consume messages from an ActiveMQ queue in grails. I've configured some spring beans for the connection and everything works great so far.
The problem starts when I try to set the concurrentConsumers
above 8. It seems that 8 is set as maximum for one client - if I configure more than 8, the ActiveMQ explorer still shows 8 consumers for the queue. If I configure two listeners for different queues with more than 8 concurrentConsumers
, the number of consumers shown by ActiveMQ oszillate, but the sum is always 8.
What am I doing wrong? Configuration examples show concurrentConsumers of up to 50...
Here is my configuration, written as groovy DSL, I guess it is no problem to read it...
jmsFactory(org.apache.activemq.pool.PooledConnectionFactory) { bean ->
bean.destroyMethod = "stop"
connectionFactory = { org.apache.activemq.ActiveMQConnectionFactory cf ->
brokerURL = "tcp://localhost:61616"
}
}
jmsTemplate(org.springframework.jms.core.JmsTemplate) {
connectionFactory = jmsFactory
}
jmsMessageListener(org.springframework.jms.listener.adapter.MessageListenerAdapter, ref("messageService")) {
defaultListenerMethod = "onMessage"
}
jmsContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) {
connectionFactory = jmsFactory
concurrency="10"
concurrentConsumers="15"
destinationName = "demoQueue"
messageListener = jmsMessageListener
transactionManager = ref("transactionManager")
autoStartup = false
}
jmsMessageListener2(org.springframework.jms.listener.adapter.MessageListenerAdapter, ref("messageService")) {
defaultListenerMethod = "onMessage2"
}
jmsContainer2(org.springframework.jms.listener.DefaultMessageListenerContainer) {
connectionFactory = jmsFactory
destinationName = "demoQueue2"
messageListener = jmsMessageListener2
transactionManager = ref("transactionManager")
autoStartup = false
}
Since Petter pointed out that it can't be a problem with the ActiveMQ or Spring configuration, I created a spring consumer in java and tried to find the difference to my grails consumer.
The java consumer works as expected, but doesn't use a transaction manager. So I removed the transaction manager from my grails confid and it works!
I then googled a little bit and found a hint to the cacheLevel setting: http://static.springsource.org/spring/docs/2.0.8/api/org/springframework/jms/listener/DefaultMessageListenerContainer.html#setCacheLevel%28int%29
The cacheLevel is set to none when a transaction manager is used - bingo! If I now set the cacheLevel to CACHE_CONSUMER, everything works as expected...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.