[英]Limit JMS connections created by Spring JmsListener
I have total 4 JmsListener
defined in my application.我的应用程序中总共定义了 4 个
JmsListener
。 I am using DefaultMessageListenerContainerFactory
and have concurrency set to 25-75
.我正在使用
DefaultMessageListenerContainerFactory
并将并发设置为25-75
。 I see my application is creating lot of JMS connections and exhausting the limit.我看到我的应用程序正在创建大量 JMS 连接并耗尽限制。 Is there a way I can limit this connection?
有没有办法可以限制这种连接?
JmsListenerContainerFactory<DefaultMessageListenerContainer> createJmsListenerContainerFactory(
ConnectionFactory cf,DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
configurer.configure(factory, cf);
factory.setSessionTransacted(true);
factory.setSessionAcknowledgeMode(2);
factory.setBackOff(new FixedBackOff());
return factory;
}
Here is how I use it in listener.这是我在侦听器中使用它的方式。
@Bean(name = "containerFactory")
public MQConnectionFactory mqConnectionFactory(DefaultJmsListenerContainerFactoryConfigurer configurer) throws NamingException {
//call to createJmsListenerContainerFactory()
}
@JmsListener(destination = "queue1", containerFactory = "containerFactory", concurrency = "25-75")
I have my 6 instances of my application running.我有我的应用程序的 6 个实例正在运行。 I need to restrict JMS connection limit per instance.
我需要限制每个实例的 JMS 连接限制。
Wrap your connection factory in a SingleConnectionFactory
and they will all share the same connection.将您的连接工厂包装在
SingleConnectionFactory
中,它们将共享相同的连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.