简体   繁体   English

concurrentMons队列的并发消费者

[英]concurrentConsumers for an ActiveMQ queue

I try to consume messages from an ActiveMQ queue in grails. 我尝试使用grails中的ActiveMQ队列消息。 I've configured some spring beans for the connection and everything works great so far. 我为连接配置了一些spring bean,到目前为止一切都很好。

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. 当我尝试将concurrentConsumers设置为8以上时,问题就出现了。似乎将8设置为一个客户端的最大值 - 如果配置超过8,则ActiveMQ资源管理器仍会显示8个队列消费者。 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. 如果我为具有8个以上concurrentConsumers消费者的不同队列配置两个侦听器,则ActiveMQ oszillate显示的消费者数量,但总和始终为8。

What am I doing wrong? 我究竟做错了什么? Configuration examples show concurrentConsumers of up to 50... 配置示例显示最多50个并发消费者...

Here is my configuration, written as groovy DSL, I guess it is no problem to read it... 这是我的配置,写作groovy DSL,我想这是没有问题阅读它...

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. 由于Petter指出它不是ActiveMQ或Spring配置的问题,我在java中创建了一个spring使用者,并试图找到我的grails使用者的差异。

The java consumer works as expected, but doesn't use a transaction manager. java使用者按预期工作,但不使用事务管理器。 So I removed the transaction manager from my grails confid and it works! 所以我从我的grails confid中删除了事务管理器,它的工作原理!

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 然后我用google搜索了一下,并找到了cacheLevel设置的提示: 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! 使用事务管理器时,cacheLevel设置为none - bingo! If I now set the cacheLevel to CACHE_CONSUMER, everything works as expected... 如果我现在将cacheLevel设置为CACHE_CONSUMER,一切都按预期工作......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM