Embracing the Messiness in Search of Epic Solutions

Spring Boot: Connecting to IBM MQ over JMS using non-IBM JRE

Posted

in

,

There are several ways to connect to IBM MQ:-

  • com.ibm.mq.MQQueueManager
  • com.ibm.mq.jms.MQQueueConnectionFactory
  • com.ibm.msg.client.jms.JmsConnectionFactory

This article shows you how to connect with Spring’s JmsTemplate.

CONNECTIVITY INFO

Typically, the MQ admin will provide the following connectivity info that allows you to connect to MQ:-

  • Queue manager name, ex: MY.QUEUE.MANAGER
  • Host name, ex: server.com
  • Port, ex: 1415
  • Channel name, ex: MY.SSL.CHANNEL
  • SSL Cipher Suite, ex: SSL_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  • User, ex: user
  • Password, ex: password
  • Queue name, ex: MY.QUEUE

DEPENDENCY

Add the following dependency:-

dependencies {
  compile 'com.ibm.mq:mq-jms-spring-boot-starter:2.1.1'
}

SPRING CONFIGURATION

While the connectivity info can be hardcoded in Spring Boot’s application.properties, it’s probably more logical to use Spring @Configuration to dynamically set the values especially dealing with credential.

So, create a Spring configuration that looks something like this:-

// while all the value are hardcoded here for simplicity sake, you can inject
// sensitive values from DB, through <code>Environment</code>, etc.
@EnableJms
@Configuration
class JmsConfig {
  // Adding @Primary will force Spring Boot to use this bean
  // instead of the one provided by the dependency
  @Primary
  @Bean
  MQConfigurationProperties mqConfigurationProperties() {
    System.setProperty('javax.net.ssl.keyStore', '/path/to/keystore.jks')
    System.setProperty('javax.net.ssl.keyStorePassword', 'XXXXXXX')

    return new MQConfigurationProperties(
      queueManager: 'MY.QUEUE.MANAGER',
      channel: 'MY.SSL.CHANNEL',
      connName: 'server.com(1415)',
      user: 'user',
      password: 'password',
      userAuthenticationMQCSP: true,

      // If the provided SSL cipher suite begins with "SSL",
      // replace it with "TLS" instead.
      // SSL_* is IBM JRE CipherSuite name.
      // TLS_* is Oracle JRE CipherSuite name.
      sslCipherSuite: 'TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256',

      // true - if using IBM JRE
      // false - if using non-IBM JRE, ex: Oracle, OpenJDK, etc
      useIBMCipherMappings: false
    )
  }
}

USING JMS TEMPLATE

Finally, to listen to the given queue, it is as easy as autowiring JmsTemplate and start using it.

@Autowired
JmsTemplate jmsTemplate

...

final Message message = jmsTemplate.receive('MY.QUEUE')
println message

Comments

3 responses to “Spring Boot: Connecting to IBM MQ over JMS using non-IBM JRE”

  1. JoshMc Avatar

    Nice post, coming from the MQ admin side this wtill help me guide application developers in the use of spring boot with IBM MQ.

    1. Choon-Chern Lim Avatar

      @JoshMc, by the way, thank you very much for your help on SO. The problem was due to misconfiguration from my MQ admin, hence, my machine’s user ID kept getting passed to MQ server.

  2. Naveen Avatar
    Naveen

    I tried to replicate above code but getting error… any quick help in this regards is appreciated… Getting error at this line
    return new MQConfigurationProperties(queueManager: ‘MY.QUEUE.MANAGER’,
    channel: ‘MY.SSL.CHANNEL’,
    connName: ‘server.com(1415)’,
    user: ‘user’,
    password: ‘password’,
    userAuthenticationMQCSP: true,
    useIBMCipherMappings: false);

    Here’s the error…

    Multiple markers at this line
    – Invalid character constant
    – Syntax error on token “:”, delete
    this token

Leave a Reply