How to set WMQConstants.USERID in springboot application to connect to IBM MQ?

158 Views Asked by At

I'm trying to connect to IBM MQ (Remote queue) through my spring boot application.

Configuration:

@Configuration
@EnableJms
@ConditionalOnProperty(value = "mq.enabled", havingValue = "true")
@Import({MQAutoConfiguration.class, JmsAutoConfiguration.class})
public class MQConfiguration {

  @Bean
  JmsListenerContainerFactory<?> jmsListenerContainerFactory(
      ConnectionFactory connectionFactory,
      DefaultJmsListenerContainerFactoryConfigurer configurer) {
    var factory = new DefaultJmsListenerContainerFactory();
    configurer.configure(factory, connectionFactory);
    return factory;
  }
}

Listener:

@JmsListener(destination = "${test-queue}")
  public void receive(TextMessage message) {
    try {
      var foo =
          objectMapper.readValue(message.getText(), Foo.class);
      LOGGER.info("Incoming JMS message : " + message.getText());
      //Business logic
    } catch (Exception e) {
        e.printStackTrace();
    }
  }

application.yaml:

ibm:
  mq:
    channel: DEV.CHNL
    user: app
    conn-name: ${ibm.mq.host}(${ibm.mq.port})
    queue-manager: QM_NAME

pom.xml:

<dependency>
    <groupId>com.ibm.mq</groupId>
    <artifactId>mq-jms-spring-boot-starter</artifactId>
    <version>${ibm-mq.version}</version>
</dependency>

The Queue manager needs UserId to connect to the queue. The userId is automatically set by process name and not from the yaml as mentioned here https://www.ibm.com/support/pages/how-specify-userid-and-password-when-connecting-ibm-mq

If the property is set to the default value, then the WebSphere MQ classes for Java will query the Java system property user.name. Even after setting these props its not working as expected.

ibm.mq.user
ibm.mq.password

The core internal library from ibm is somehow reading System.getProperty("user.name").

The only way I can set is uing

set - _JAVA_OPTIONS=-Duser.name=myUser

Is there anyway we can set WMQConstants.USERID without having to set java user name?

0

There are 0 best solutions below