如何使用JMS模板连接池?

问题描述 投票:0回答:1

据我所知,具有默认配置的 JMS 模板使用同步方法向 MQ 发送消息,这使得性能指标非常糟糕。这里有什么方法可以使用连接池吗?

public void insertIntoMQ(String kafkaMessage) {
        //log.info("Inside insertIntoMQ function");
        try{
            jMSConfiguration2.insertIntoMQ(kafkaMessage); 
            log.info("Message Inserted Successfully :\n" + kafkaMessage);
        } catch (Exception e) {

            log.error("Exception Inserting Message Into MQ ", e);
        }
    }

上面的方法在不同的类中调用下面的InsertIntoMQ方法来插入消息。我尝试使用单例以外的不同范围来获取多个实例,这可能会提高性能,但我仍然没有得到任何性能提升。

package ca.bell.outagenotification.config.kafka;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
@Scope("prototype")
public class JMSConfiguration2 {

    @Autowired
    private JmsTemplate jmsTemplate;
    
    private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager
            .getLogger(JMSConfiguration2.class);

    @Value("${ibm.mq.queueName}")
    private String queueName;
    
    @Async
    public void insertIntoMQ(String kafkaMessage) {
        //log.info("Inside insertIntoMQ function");
        try{
                    
            jmsTemplate.convertAndSend(queueName, kafkaMessage); 
            log.info("Message Inserted Successfully :\n" + kafkaMessage);
        } catch (Exception e) {

            log.error("Exception Inserting Message Into MQ ", e);
        }
    }

    
}

请帮助我了解如何在 JMS 模板中使用池化

spring-boot jms activemq ibm-mq spring-jms
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.