Currently, the standard Java programming interface for MQ is JMS. You can pull in the MQ JMS client as a dependency to your project by addding the following to your maven pom.xml:
<!-- JMS API interfaces -->
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
</dependency>
<!-- MQ JMS client packages -->
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.allclient</artifactId>
<version>${mq.version}</version>
</dependency>
</dependencies>
That will enable you to create a JMS ConnectionFactory programmatically within your app using the JMSFactoryFactory class, as described in:
https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q032180_.htm
This doesn't allow you to use injection, you need to declare and create your ConnectionFactory within the application itself.
Within Quarkus, in order to be able to inject a ConnectionFactory object into your application, you could write your own extension.
There are more details about writing an extension at:
https://quarkus.io/guides/writing-extensions
The central requirement for that would be to write a Producer class in the runtime part of your extension that produces a JMSConnectionFactory object using properties defined in a config object (which also needs to be defined to contain the properties you want to set in the ConnectionFactory).
The producer would need a method similar to:
@Produces
@ApplicationScoped
@DefaultBean
public ConnectionFactory connectionFactory() throws JMSException {
JmsFactoryFactory ff;
JmsConnectionFactory factory;
try {
// Get a new JMSConnectionFactory
ff = JmsFactoryFactory.getInstance(JmsConstants.WMQ_PROVIDER);
factory = ff.createConnectionFactory();
// Always work in TCP/IP client mode
factory.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
// Now set the properties in this ConnectionFactory from the config.
if (config.hostname.isPresent())
factory.setStringProperty(CommonConstants.WMQ_HOST_NAME, config.hostname.get());
if (config.port.isPresent())
factory.setIntProperty(CommonConstants.WMQ_PORT, config.port.get());
if (config.channel.isPresent())
factory.setStringProperty(CommonConstants.WMQ_CHANNEL, config.channel.get());
if (config.queuemanager.isPresent())
factory.setStringProperty(CommonConstants.WMQ_QUEUE_MANAGER, config.queuemanager.get());
}
catch (JMSException je) {
// Something went wrong. Either handle it here or throw it on.
throw je;
}
return factory;
}