简体   繁体   English

Spring DefaultJmsListenerContainer 监听多个队列调优

[英]Spring DefaultJmsListenerContainer tuning for listening to multiple queues

we have 50 @JMSListener classes connecting to 50 different SQS Queues from same application.我们有 50 个 @JMSListener 类连接到来自同一应用程序的 50 个不同的 SQS 队列。 is it better to use the different listener containers for each queue.为每个队列使用不同的侦听器容器是否更好。

We are using the same ListenerContainer with SQSConnectionFactory for sending and receiving the messages.我们使用与 SQSConnectionFactory 相同的 ListenerContainer 来发送和接收消息。 Will it help in performance if we add separate ListenerContainer for queues and multiple JMSTemplates to to send messages to queues with high number of messages.如果我们为队列添加单独的 ListenerContainer 并添加多个 JMSTemplates 以将消息发送到具有大量消息的队列,这是否有助于提高性能。 my configs are as follows.我的配置如下。

 public void sqsContainerFactory(){ connectionFactory = new SQSConnectionFactory( new ProviderConfiguration(), AmazonSQSClientBuilder.standard().withRegion(region).withCredentials(new DefaultAWSCredentialsProviderChain()) ); } //Used in all Listeners as containerFactory @Bean public JmsListenerContainerFactory<?> sqsFactory() { DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory(); factory.setConnectionFactory(this.connectionFactory); factory.setDestinationResolver(new DynamicDestinationResolver()); factory.setConcurrency("1-25"); factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE); return factory; } //Used to send messages to SQS @Bean("SQS") @Primary public JmsTemplate defaultJmsTemplate() { return new JmsTemplate(this.connectionFactory); }

could you please advise您能否提一些建议

If you have 50 @JMSListener classes listening on 50 queues, then you already have 50 ListenerContainers.如果您有 50 个@JMSListener类侦听 50 个队列,那么您已经有 50 个 ListenerContainer。 I don't know of any way to have a DefaultMessageListenerContainer listen on more than one queue.我不知道有什么方法可以让DefaultMessageListenerContainer监听多个队列。

If you are having performance issues, look at the org.messaginghub.pooled.jms.JmsPoolConnectionFactory or the org.apache.activemq.jms.pool.PooledConnectionFactory .如果您遇到性能问题,请查看org.messaginghub.pooled.jms.JmsPoolConnectionFactoryorg.apache.activemq.jms.pool.PooledConnectionFactory By default, the JMSTemplate will create a new JMS connection and session for every message sent.默认情况下, JMSTemplate将为发送的每条消息创建一个新的 JMS 连接和 session。 This is very expensive.这是非常昂贵的。 Depending on your configuration, the DefaultMessageListenerContainer can also do this for every message received.根据您的配置, DefaultMessageListenerContainer也可以为收到的每条消息执行此操作。

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

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