我怎样才能将这个简单的 (IBM MQ) MDB 项目部署到 Tomee... - 成功部署需要什么配置

How can I get this simple (IBM MQ) MDB project to deploy to Tomee... -what configuration is required for a successful deployment

问题:

什么 CDI 注释、tomee.xml 配置 [等] 可以成功部署这个简单的消息驱动 bean?


我正在尝试使用 CDI 和 IBM MQ - 运行 在 Tomee 7.1 Plume 上部署 MessageDriven bean...

经过多次迭代,我仍然不知道如何克服下面的异常,希望得到一些 help/guidance。

--根据 tomee.xml 文件,我的 "ActivationConfigProperty" 值(在 "ChatBean" mdb 示例中)是否正确?

异常

    -
    -
    -         
    11-Oct-2018 19:20:27.427 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.logAutoCreateResource Auto-creating a Resource with id 'DEV.QUEUE.1' of type 'javax.jms.Queue for 'ChatBean'.
    11-Oct-2018 19:20:27.427 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating Resource(id=DEV.QUEUE.1)
    11-Oct-2018 19:20:27.432 INFO [localhost-startStop-1] org.apache.openejb.config.ConfigurationFactory.configureService Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container)
    11-Oct-2018 19:20:27.432 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.createContainer Auto-creating a container for bean SimpleMDB.Comp263849086: Container(type=MANAGED, id=Default Managed Container)
    11-Oct-2018 19:20:27.432 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.createRecipe Creating Container(id=Default Managed Container)
    11-Oct-2018 19:20:27.437 INFO [localhost-startStop-1] org.apache.openejb.core.managed.SimplePassivater.init Using directory /usr/local/tomee/temp for stateful session passivation
    11-Oct-2018 19:20:27.445 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.processResourceRef Auto-linking resource-ref 'java:comp/env/imq_qcf' in bean SimpleMDB.Comp263849086 to Resource(id=imq_qcf)
    11-Oct-2018 19:20:27.445 INFO [localhost-startStop-1] org.apache.openejb.config.AutoConfig.processResourceEnvRef Auto-linking resource-env-ref 'java:comp/env/imq.baq' in bean SimpleMDB.Comp263849086 to Resource(id=imq.baq)
    11-Oct-2018 19:20:27.449 INFO [localhost-startStop-1] org.apache.openejb.config.AppInfoBuilder.build Enterprise application "/usr/local/tomee/webapps/SimpleMDB" loaded.
    11-Oct-2018 19:20:27.449 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.createApplication Assembling app: /usr/local/tomee/webapps/SimpleMDB
    11-Oct-2018 19:20:27.471 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.JndiBuilder.bind Jndi(name=ChatBean) --> Ejb(deployment-id=ChatBean)
    11-Oct-2018 19:20:27.489 INFO [localhost-startStop-1] org.apache.openejb.cdi.CdiBuilder.initSingleton Existing thread singleton service in SystemInstance(): org.apache.openejb.cdi.ThreadSingletonServiceImpl@340b9973
    11-Oct-2018 19:20:27.554 INFO [localhost-startStop-1] org.apache.openejb.cdi.OpenEJBLifecycle.startApplication OpenWebBeans Container is starting...
    11-Oct-2018 19:20:27.557 INFO [localhost-startStop-1] org.apache.webbeans.plugins.PluginLoader.startUp Adding OpenWebBeansPlugin : [CdiPlugin]
    11-Oct-2018 19:20:27.699 INFO [localhost-startStop-1] org.apache.webbeans.config.BeansDeployer.validateInjectionPoints All injection points were validated successfully.
    11-Oct-2018 19:20:27.703 INFO [localhost-startStop-1] org.apache.openejb.cdi.OpenEJBLifecycle.startApplication OpenWebBeans Container has started, it took 149 ms.
    11-Oct-2018 19:20:27.838 INFO [localhost-startStop-1] org.apache.openejb.assembler.classic.Assembler.destroyApplication Undeploying app: /usr/local/tomee/webapps/SimpleMDB
    11-Oct-2018 19:20:27.841 SEVERE [localhost-startStop-1] jdk.internal.reflect.NativeMethodAccessorImpl.invoke ContainerBase.removeChild: destroy: 
    -
    -
    -
    11-Oct-2018 19:20:27.926 SEVERE [localhost-startStop-1] jdk.internal.reflect.NativeMethodAccessorImpl.invoke ContainerBase.addChild: start: 
     org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SimpleMDB]]
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
            at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
            at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
            at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
            at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
            at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
            at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
            at java.base/java.lang.Thread.run(Thread.java:844)
    Caused by: org.apache.tomee.catalina.TomEERuntimeException: org.apache.openejb.OpenEJBException: Creating application failed: /usr/local/tomee/webapps/SimpleMDB: Error deploying 'ChatBean'.  Exception: class org.apache.openejb.OpenEJBException: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.: MQJCA1011: Failed to allocate a JMS connection.: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.: MQJCA1011: Failed to allocate a JMS connection.
            at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1315)
            at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1125)
            at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133)
            at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
            at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
            at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
            ... 10 more
    Caused by: org.apache.openejb.OpenEJBException: Creating application failed: /usr/local/tomee/webapps/SimpleMDB: Error deploying 'ChatBean'.  Exception: class org.apache.openejb.OpenEJBException: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.: MQJCA1011: Failed to allocate a JMS connection.: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.: MQJCA1011: Failed to allocate a JMS connection.
            at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:1096)
            at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:757)
            at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1303)
            ... 15 more
    Caused by: org.apache.openejb.OpenEJBException: Error deploying 'ChatBean'.  Exception: class org.apache.openejb.OpenEJBException: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.: MQJCA1011: Failed to allocate a JMS connection.: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.: MQJCA1011: Failed to allocate a JMS connection.
            at org.apache.openejb.assembler.classic.Assembler.startEjbs(Assembler.java:1686)
            at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:997)
            ... 17 more
    Caused by: org.apache.openejb.OpenEJBException: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.: MQJCA1011: Failed to allocate a JMS connection.
            at org.apache.openejb.core.mdb.MdbContainer.deploy(MdbContainer.java:250)
            at org.apache.openejb.assembler.classic.Assembler.startEjbs(Assembler.java:1673)
            ... 18 more
    Caused by: com.ibm.mq.connector.DetailedResourceAdapterInternalException: MQJCA1011: Failed to allocate a JMS connection. An internal error caused an attempt to allocate a connection to fail. See the linked exception for details of the failure.
            at com.ibm.mq.connector.services.JCAExceptionBuilder.buildException(JCAExceptionBuilder.java:174)
            at com.ibm.mq.connector.services.JCAExceptionBuilder.buildException(JCAExceptionBuilder.java:135)
            at com.ibm.mq.connector.inbound.ConnectionHandler.allocateConnection(ConnectionHandler.java:394)
            at com.ibm.mq.connector.inbound.MessageEndpointDeployment.acquireConnection(MessageEndpointDeployment.java:289)
            at com.ibm.mq.connector.inbound.MessageEndpointDeployment.<init>(MessageEndpointDeployment.java:229)
            at com.ibm.mq.connector.ResourceAdapterImpl.endpointActivation(ResourceAdapterImpl.java:558)
            at org.apache.openejb.core.mdb.MdbContainer$MdbActivationContext.start(MdbContainer.java:641)
            at org.apache.openejb.core.mdb.MdbContainer.deploy(MdbContainer.java:232)
            ... 19 more
    Caused by: com.ibm.msg.client.jms.DetailedJMSException: JMSFMQ6312: An exception occurred in the Java(tm) MQI.
    The Java(tm) MQI has thrown an exception describing the problem. 
    See the linked exception for further information.
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
            at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
            at com.ibm.msg.client.commonservices.j2se.NLSServices.createException(NLSServices.java:319)
            at com.ibm.msg.client.commonservices.nls.NLSServices.createException(NLSServices.java:226)
            at com.ibm.msg.client.wmq.factories.WMQXAConnectionFactory.createV7ProviderConnection(WMQXAConnectionFactory.java:172)
            at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7815)
            at com.ibm.msg.client.wmq.factories.WMQXAConnectionFactory.createProviderXAConnection(WMQXAConnectionFactory.java:98)
            at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createXAConnectionInternal(JmsConnectionFactoryImpl.java:354)
            at com.ibm.mq.jms.MQXAConnectionFactory.createXAConnection(MQXAConnectionFactory.java:104)
            at com.ibm.mq.connector.inbound.ConnectionHandler.allocateConnection(ConnectionHandler.java:268)
            ... 24 more
    Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2195;AMQ9546: Error return code received. [1=java.lang.NoSuchMethodException[com.ibm.mq.jmqi.remote.api.RemoteFAP.<init>(com.ibm.mq.jmqi.JmqiEnvironment, int)],3=Class.getConstructor0]
            at com.ibm.mq.jmqi.JmqiEnvironment.getInstance(JmqiEnvironment.java:831)
            at com.ibm.mq.jmqi.JmqiEnvironment.getMQI(JmqiEnvironment.java:676)
            at com.ibm.msg.client.wmq.factories.WMQXAConnectionFactory.createV7ProviderConnection(WMQXAConnectionFactory.java:164)
            ... 29 more
    Caused by: java.lang.NoSuchMethodException: com.ibm.mq.jmqi.remote.api.RemoteFAP.<init>(com.ibm.mq.jmqi.JmqiEnvironment, int)
            at java.base/java.lang.Class.getConstructor0(Class.java:3302)
            at java.base/java.lang.Class.getConstructor(Class.java:2110)
            at com.ibm.mq.jmqi.JmqiEnvironment.getInstance(JmqiEnvironment.java:738)
            ... 31 more

    11-Oct-2018 19:20:27.926 SEVERE [localhost-startStop-1] jdk.internal.reflect.NativeMethodAccessorImpl.invoke Error deploying web application archive [/usr/local/tomee/webapps/SimpleMDB.war]
     java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SimpleMDB]]
            at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:758)
            at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
            at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
            at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:985)
            at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
            at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:514)
            at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
            at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
            at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
            at java.base/java.lang.Thread.run(Thread.java:844)

    11-Oct-2018 19:20:27.927 INFO [localhost-startStop-1] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke Deployment of web application archive [/usr/local/tomee/webapps/SimpleMDB.war] has finished in [1,926] ms
    11-Oct-2018 19:20:27.927 INFO [localhost-startStop-1] jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke Deploying web application directory [/usr/local/tomee/webapps/ROOT]
    11-Oct-2018 19:20:27.928 INFO [localhost-startStop-1] org.apache.tomee.catalina.TomcatWebAppBuilder.init ------------------------- localhost -> /
    -
    -
    -

注意,我的示例(CDI 注释)MDB 派生自此 link:

    http://tomee.apache.org/examples-trunk/simple-mdb-and-cdi/

...不幸的是(对我来说)我找不到 tomee.xml 或 resources.xml 示例 - "simple-mdb-and-cdi" - 注释所基于的.. .

conf/tomee.xml

    <tomee>

        <Container id="imq_container" type="MESSAGE">
            ResourceAdapter=imq_ra
            MessageListenerInterface=javax.jms.MessageListener
            ActivationSpecClass=com.ibm.mq.connector.inbound.ActivationSpecImpl
        </Container>

        <Resource id="imq_ra" type="com.ibm.mq.connector.ResourceAdapterImpl" class-name="com.ibm.mq.connector.ResourceAdapterImpl">
            connectionConcurrency=5
            maxConnections=10
            logWriterEnabled=false
            reconnectionRetryCount=5
            reconnectionRetryInterval=300000
            traceEnabled=false
            traceLevel=3
        </Resource>

        <Resource id="imq_qcf" type="javax.jms.ConnectionFactory" class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl">
            TransactionSupport=none
            ResourceAdapter=imq_ra
            HostName=172.17.0.3
            Port=1414
            QueueManager=QM1
            Channel=DEV.ADMIN.SVRCONN
            TransportType=CLIENT
            UserName=admin
            Password=passw0rd
        </Resource>

        <Resource id="imq_container-javax.jms.QueueConnectionFactory" type="javax.jms.QueueConnectionFactory" class-name="com.ibm.mq.connector.outbound.ManagedQueueConnectionFactoryImpl">
            TransactionSupport=xa
            ResourceAdapter=imq_ra
        </Resource>

        <Resource id="imq.bar" type="javax.jms.Queue" class-name="com.ibm.mq.connector.outbound.MQQueueProxy">
            arbitraryProperties
            baseQueueManagerName=QM1
            baseQueueName=DEV.QUEUE.1
            CCSID=1208
            encoding=NATIVE
            expiry=APP
            failIfQuiesce=true
            persistence=APP
            priority=APP
            readAheadClosePolicy=ALL
            targetClient=JMS
        </Resource>

        <Resource id="imq.baq" type="javax.jms.Queue" class-name="com.ibm.mq.connector.outbound.MQQueueProxy">
            arbitraryProperties
            baseQueueManagerName=QM1
            baseQueueName=DEV.QUEUE.2
            CCSID=1208
            encoding=NATIVE
            expiry=APP
            failIfQuiesce=true
            persistence=APP
            priority=APP
            readAheadClosePolicy=ALL
            targetClient=JMS
        </Resource>        

    </tomee>

ChatBean.java

包 org.superbiz.mdb;

    import javax.annotation.Resource;
    import javax.ejb.ActivationConfigProperty;
    import javax.ejb.MessageDriven;
    import javax.inject.Inject;
    import javax.jms.Connection;
    import javax.jms.ConnectionFactory;
    import javax.jms.DeliveryMode;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.MessageProducer;
    import javax.jms.Queue;
    import javax.jms.Session;
    import javax.jms.TextMessage;

    @MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "DEV.QUEUE.1"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })
    public class ChatBean implements MessageListener {

        @Resource(name = "java:comp/env/imq_qcf")
        private ConnectionFactory connectionFactory;

        @Resource(name = "java:comp/env/imq.baq")
        private Queue answerQueue;

        @Inject
        private ChatRespondCreator responder;

        @Override
        public void onMessage(Message message) {
        try {
            final TextMessage textMessage = (TextMessage) message;
            final String question = textMessage.getText();
            respond("...the question was: " + question);
        } catch (JMSException e) {
            throw new IllegalStateException(e);
        }
        }

        private void respond(String text) throws JMSException {

        Connection connection = null;
        Session session = null;

        try {
            connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create a MessageProducer from the Session to the Topic or Queue
            MessageProducer producer = session.createProducer(answerQueue);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            // Create a message
            TextMessage message = session.createTextMessage(text);

            // Tell the producer to send the message
            producer.send(message);
        } finally {
            // Clean up
            if (session != null) {
            session.close();
            }
            if (connection != null) {
            connection.close();
            }
        }
        }
    }

src/main/resources/beans.xml

    <beans/>

IBM MQ 9.1 jar 从 wmq.jmsra-9.1.0.0.rar 中提取,并添加到 tomee/lib 文件夹(根据:tomee.apache.org/tomee-and-webspheremq.html)

    bcpkix-jdk15on.jar
    bcprov-jdk15on.jar
    com.ibm.mq.connector.jar
    com.ibm.mq.headers.jar
    com.ibm.mq.jar
    com.ibm.mq.jmqi.jar
    com.ibm.mqjms.jar
    com.ibm.mq.pcf.jar

pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>aaa.bbb.ccc</groupId>
        <artifactId>SimpleMDB</artifactId>
        <version>1</version>
        <packaging>war</packaging>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <timestamp>${maven.build.timestamp}</timestamp>
            <maven.build.timestamp.format>yyyyMMdd.HHmmss</maven.build.timestamp.format>
            <skipTests>true</skipTests>
        </properties>
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.11</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-api</artifactId>
                <version>8.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.5</version>
            </dependency>    
            <dependency>
              <groupId>org.glassfish.jaxb</groupId>
              <artifactId>jaxb-runtime</artifactId>
              <version>2.3.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.ibm.mq</groupId>
                <artifactId>com.ibm.mq.allclient</artifactId>
                <version>9.1.0.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.tomee</groupId>
                <artifactId>openejb-core</artifactId>
                <version>7.1.0</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <finalName>${project.artifactId}</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <release>10</release>
                        <fork>true</fork>
                        <executable>/usr/local/jdkv10/bin/javac</executable>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <archive>
                            <manifestEntries>
                                <Tomee-Application-Version>${project.version}-${timestamp}</Tomee-Application-Version>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>

FWIW,提供更多上下文:此无状态 bean(下方)中的 "sendMessage" 和 "receiveMessage" 方法与 tomee.xml 配置和 tomee/lib MQ 罐子。

这些问题似乎与(间接?)消息驱动 bean(MDB) 的 CDI 注释/"wiring" 相关...我认为也许我的注释可能不正确连接到 tomee.xml 配置(?)

    package org.superbiz.mdb;

    import javax.annotation.Resource;
    import javax.ejb.Stateless;
    import javax.jms.Connection;
    import javax.jms.ConnectionFactory;
    import javax.jms.DeliveryMode;
    import javax.jms.JMSException;
    import javax.jms.MessageConsumer;
    import javax.jms.MessageProducer;
    import javax.jms.Queue;
    import javax.jms.Session;
    import javax.jms.TextMessage;

    @Stateless
    public class Messages {

        @Resource(name = "imq_qcf")
        private ConnectionFactory connectionFactory;    


        @Resource(name = "imq.bar")
        private Queue devQueue1;    


        public void sendMessage(String text) throws JMSException {

        System.out.println("\n\n...........................Messages/sendMessage............................\n\n");

        Connection connection = null;
        Session session = null;

        try {
            connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create a MessageProducer from the Session to the Topic or Queue
            MessageProducer producer = session.createProducer(devQueue1);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            // Create a message
            TextMessage message = session.createTextMessage(text);

            // Tell the producer to send the message
            producer.send(message);
        } finally {
            // Clean up
            if (session != null) session.close();
            if (connection != null) connection.close();
        }
        }

        public String receiveMessage() throws JMSException {

        System.out.println("\n\n...........................Messages/receiveMessage............................\n\n");        

        Connection connection = null;
        Session session = null;
        MessageConsumer consumer = null;
        try {
            connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create a MessageConsumer from the Session to the Topic or Queue
            consumer = session.createConsumer(devQueue1);

            // Wait for a message
            TextMessage message = (TextMessage) consumer.receive(1000);

            return message.getText();
        } finally {
            if (consumer != null) consumer.close();
            if (session != null) session.close();
            if (connection != null) connection.close();
        }
        }
    }

环境:

Java 10
IBM MQ Version 9.0
Tomee 7.1.0 Plume

现在可以在 apache tomee plume 上部署工作 MDB 7.x 连接到 IBM MQ 队列等

到目前为止,我很喜欢 Apache Tomee - 但是,必须 research/google 将来自不同帖子 and/or 文档片段的信息拼凑起来才能得到下面的 poc/solution。 .. - 不清楚这个解决方案是否被推荐(或者,不明智),但是,这是我正在寻找的,因为我不想在我的 war(或 ear)文件...-但是,更想部署到 "pre-configured"(lib、配置文件)tomee 服务器等(在我的例子中,驻留在 Docker 容器中)

首先将 "wmq.jmsra-9.1.0.0.rar" 中的 jar 文件放入 tomee/lib 文件夹

-rw-r--r--. 1 1000 1000  464030 Jul  5 21:38 com.ibm.mq.connector.jar
-rw-r--r--. 1 1000 1000  359297 Jul  5 21:37 com.ibm.mq.headers.jar
-rw-r--r--. 1 1000 1000  397171 Jul  5 21:37 com.ibm.mq.jar
-rw-r--r--. 1 1000 1000 3374322 Jul  5 21:38 com.ibm.mq.jmqi.jar
-rw-r--r--. 1 1000 1000  127566 Jul  5 21:37 com.ibm.mq.pcf.jar
-rw-r--r--. 1 1000 1000 3999810 Jul  5 21:38 com.ibm.mqjms.jar
-rw-r--r--. 1 1000  1000   792825 Jul  5 21:37 bcpkix-jdk15on.jar
-rw-r--r--. 1 1000  1000  4092400 Jul  5 21:37 bcprov-jdk15on.jar

(note: this seemed adequate for non-MDB, IBM MQ connectivity)

创建了名为 "ibm_rar" 的文件夹并将 "wmq.jmsra-9.1.0.0.rar" 文件放入其中

root@c2865c04748a:/usr/local/tomee# ls -l
total 120
-rw-r--r--. 1 root staff 52711 Jul 10 11:41 LICENSE
-rw-r--r--. 1 root staff  7692 Jul 10 11:22 NOTICE
-rw-r--r--. 1 root staff  7316 Jun 20 19:51 RELEASE-NOTES
-rw-r--r--. 1 root staff 16722 Jun 20 19:51 RUNNING.txt
drwxr-xr-x. 2 root staff  4096 Oct 15 17:55 bin
drwxr-xr-x. 4 root staff  4096 Oct 15 20:57 conf
drwxr-x---. 3 root root     19 Sep 20 14:33 data
drwxr-xr-x. 3 root root     58 Oct 15 17:55 ibm_rar  <== contains ".rar" file
drwxr-xr-x. 2 root staff  8192 Oct 15 17:37 lib
drwxr-xr-x. 2 root staff  4096 Oct 16 14:11 logs
drwxr-xr-x. 2 root staff  4096 Oct 16 14:11 temp
drwxr-xr-x. 7 root staff  4096 Oct 15 22:37 webapps
drwxr-xr-x. 3 root staff    21 Sep 20 14:33 work
root@c2865c04748a:/usr/local/tomee# 

手动创建文件夹的内容-任意命名:"ibm_rar"

root@c2865c04748a:/usr/local/tomee/ibm_rar# ls -l
total 12080
drwxr-x---. 3 root root     4096 Oct 15 17:55 wmq.jmsra-9.1.0.0
-rw-rw-r--. 1 1000 1000 12361911 Oct  4 21:11 wmq.jmsra-9.1.0.0.rar
root@c2865c04748a:/usr/local/tomee/ibm_rar# 

(note: appears that on startup, the tomee server explodes the ".rar" file into a corresponding folder)

tomee.xml

的内容

注意 "Deployments" 条目指向 .rar 文件的位置

root@c2865c04748a:/usr/local/tomee/conf# cat tomee.xml
<tomee>
    <!-- folder containing resource adapter -->
    <Deployments dir="ibm_rar" />
    <Resource id="wmqRA" type="com.ibm.mq.connector.ResourceAdapterImpl" class-name="com.ibm.mq.connector.ResourceAdapterImpl">
        connectionConcurrency=5
        maxConnections=10
        logWriterEnabled=false
        reconnectionRetryCount=5
        reconnectionRetryInterval=300000
        traceEnabled=false
        traceLevel=3
    </Resource>
    <Resource id="wmqCF" type="javax.jms.ConnectionFactory" class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl">
        TransactionSupport=none
        ResourceAdapter=wmqRA
        HostName=172.17.0.3
        Port=1414
        QueueManager=QM1
        Channel=DEV.ADMIN.SVRCONN
        TransportType=Client
        UserName=admin
        Password=passw0rd
    </Resource>
    <Resource id="wmqQCF" type="javax.jms.QueueConnectionFactory" class-name="com.ibm.mq.connector.outbound.ManagedQueueConnectionFactoryImpl">
        TransactionSupport=xa
        ResourceAdapter=wmqRA
    </Resource>
    <Container id="wmq" type="MESSAGE">
        BrokerXmlConfig = 
        ResourceAdapter=wmqRA
        MessageListenerInterface=javax.jms.MessageListener
        ActivationSpecClass=com.ibm.mq.connector.inbound.ActivationSpecImpl
    </Container>
    <Resource id="devQueue1" type="javax.jms.Queue" class-name="com.ibm.mq.connector.outbound.MQQueueProxy">
        arbitraryProperties
        baseQueueManagerName=QM1
        baseQueueName=DEV.QUEUE.1
        CCSID=819
        encoding=NATIVE
        expiry=APP
        failIfQuiesce=true
        persistence=APP
        priority=APP
        readAheadClosePolicy=ALL
        targetClient=JMS
    </Resource>
    <Resource id="devQueue2" type="javax.jms.Queue" class-name="com.ibm.mq.connector.outbound.MQQueueProxy">
        arbitraryProperties
        baseQueueManagerName=QM1
        baseQueueName=DEV.QUEUE.2
        CCSID=819
        encoding=NATIVE
        expiry=APP
        failIfQuiesce=true
        persistence=APP
        priority=APP
        readAheadClosePolicy=ALL
        targetClient=JMS
    </Resource>        
</tomee>

ChatBean.java (MDB)

package org.superbiz.mdb;

import javax.annotation.Resource;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

@MessageDriven(activationConfig = {
    //...annotating "ejb-jar.xml" properties here...
    @ActivationConfigProperty(propertyName = "destination",propertyValue = "DEV.QUEUE.1"),
    @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "channel",propertyValue = "DEV.ADMIN.SVRCONN"),
    @ActivationConfigProperty(propertyName = "hostName",propertyValue = "172.17.0.3"),
    @ActivationConfigProperty(propertyName = "port",propertyValue = "1414"),
    @ActivationConfigProperty(propertyName = "queueManager",propertyValue = "QM1"),
    @ActivationConfigProperty(propertyName = "transportType",propertyValue = "CLIENT"),
    @ActivationConfigProperty(propertyName = "username",propertyValue = "admin"),
    @ActivationConfigProperty(propertyName = "password",propertyValue = "passw0rd")
}
)
public class ChatBean implements MessageListener {

    @Resource(name = "wmqCF") 
    private ConnectionFactory connectionFactory;

    @Resource(name = "devQueue2")
    private Queue answerQueue;

    @Override
    public void onMessage(Message message) {
    try {
        final TextMessage textMessage = (TextMessage) message;
        final String msg = textMessage.getText();

        System.out.println("\n\n\n..........ChatBean/onMessage..........incoming message: " + String.valueOf(msg));

        respond("...the message received was: " + String.valueOf(msg));

    } catch (JMSException e) {
        throw new IllegalStateException(e);
    }
    }

    private void respond(String text) throws JMSException {

    Connection connection = null;
    Session session = null;

    try {
        connection = connectionFactory.createConnection();
        System.out.println("\n\n\n..........ChatBean/respond..........connection object:" + String.valueOf(connection));  
        System.out.println("\n\n\n..........ChatBean/respond..........responding with text:" + String.valueOf(text));    
        connection.start();

        // Create a Session
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        // Create a MessageProducer from the Session to the Topic or Queue
        MessageProducer producer = session.createProducer(answerQueue);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        // Create a message
        TextMessage textmessage = session.createTextMessage(text);
        System.out.println("\n\n\n..........ChatBean/respond..........responding with textmessage:" + String.valueOf(textmessage));    
        System.out.println("\n\n\n");            

        // Tell the producer to send the message
        producer.send(textmessage);
    } finally {
        // Clean up
        if (session != null) {
            session.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>aaa.bbb.ccc</groupId>
    <artifactId>SimpleMDB</artifactId>
    <version>1.11</version>
    <packaging>war</packaging>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <timestamp>${maven.build.timestamp}</timestamp>
    <maven.build.timestamp.format>yyyyMMdd.HHmmss</maven.build.timestamp.format>
    <skipTests>true</skipTests>
    </properties>

    <dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>    

    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId>
      <version>2.3.0.1</version>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>        

    </dependencies>
    <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>10</release>
                <fork>true</fork>
                <executable>/usr/local/jdkv10/bin/javac</executable>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.2</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <archive>
                    <manifestEntries>
                        <Tomee-Application-Version>${project.version}-${timestamp}</Tomee-Application-Version>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

    </plugins>
    </build>
</project>

war 文件 copied/deployed 到 tomee/webapps 文件夹

root@c2865c04748a:/usr/local/tomee/webapps# ls -l
total 1668
drwxr-xr-x.  3 root staff    4096 Sep 20 14:18 ROOT
drwxr-x---.  4 root root       53 Oct 15 22:37 SimpleMDB
-rw-rw-r--.  1 1000  1000 1694696 Oct 15 22:36 SimpleMDB.war
drwxr-xr-x. 14 root staff    4096 Sep 20 14:18 docs
drwxr-xr-x.  5 root staff      82 Sep 20 14:18 host-manager
drwxr-xr-x.  5 root staff    4096 Sep 20 14:18 manager
root@c2865c04748a:/usr/local/tomee/webapps# 

(tomee server explodes into corresponding folder on startup)