简体   繁体   中英

Quarkus IBM MQ integration

I'm looking for solution to integrate Quarkus (only CDI without EJB) with IBM MQ. Anybody hat such problem? or have any idea.

Parameters which I'm using to connect:

  • host
  • port
  • channel
  • queue manager
  • queue name

I know I can create my own connection factory as bean like in stand alone app and then pool of consumers. Which is actually my alternative solution. But maybe there is better or "prettier" solution. Maybe library like camel allow for such configuration? I couldn't find such configuration example

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM