Java Spring JMS: JmsTemplate to IBM MQ

Rand0m picture Rand0m · Feb 21, 2017 · Viewed 8.3k times · Source

Update

It was my mistake I forget the ssl debugging running, it is super fast now and working like magic

I have a Spring Boot application that connects to IBM MQ using spring JMS. I realized that the jmsTemplate is super slow compared to not using Spring at all. I am sure I have something not configured correctly. Hope Someone can help.

I create a connection factory using IBM MQ 8 jar files.

@Bean
public ConnectionFactory connectionFactory() {
            properties.getCipherSpec());
    MQConnectionFactory factory = new MQConnectionFactory();
    try {
        factory.setHostName(properties.getHost());
        factory.setPort(properties.getPort());
        factory.setQueueManager(properties.getQueueManager());
        factory.setChannel(properties.getChannel());
        factory.setTransportType(WMQConstants.WMQ_CM_CLIENT);
        factory.setClientReconnectTimeout(CLIENT_RECONNECT_TIMEOUT);
        factory.setClientReconnectOptions(WMQConstants.WMQ_CLIENT_RECONNECT);
        if (properties.isEnableSsl()) {
            factory.setSSLCipherSuite(properties.getCipherSpec());
            factory.setSSLSocketFactory(socketFactory());
        }   
        factory.setUseConnectionPooling(true);  
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return factory;
}

Then I am creating a caching Connection factory and setting Target Connection Factory to the connection factory above.

@Bean(name = "cachingConnectionFactory")
public CachingConnectionFactory cachingConnectionFactory(){
    CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setSessionCacheSize(50);
    factory.setTargetConnectionFactory(connectionFactory());
    factory.setReconnectOnException(true);
    factory.afterPropertiesSet();
    return factory;
}

and then in the Service class I am using the cache connection factory bean to create JmsTemplate per each thread and use the normal send receive operations.

@Autowired
private CachingConnectionFactory connectionFactory;

@PostConstruct
@DependsOn(value = "cachingConnectionFactory")
public void setJmsConnectionFactory(){
     this.jmsQueueTemplate = new JmsTemplate(this.cachingConnectionFactory);
}

Any help will be appreciated ...

Answer