Как получить этот простой (IBM MQ) проект MDB для развертывания в Tomee ... - какая конфигурация необходима для успешного развертывания - PullRequest
0 голосов
/ 11 октября 2018

ВОПРОС:

Какие аннотации CDI, конфигурация tomee.xml [и т. Д.] Позволят успешно развернуть этот простой компонент, управляемый сообщениями?


Я пытаюсь развернутьbean-компонент MessageDriven, использующий CDI и IBM MQ - работающий на Tomee 7.1 Plume ...

После многих итераций я все еще не знаю, как преодолеть приведенное ниже исключение, и буду признателеннекоторая справка / руководство.

- Верны ли мои значения "ActivationConfigProperty" (в примере mdb "ChatBean") на основе файла tomee.xml?

Исключение

    -
    -
    -         
    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) был получен по этой ссылке:

    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/>

Файлы JAR IBM MQ 9.1 были извлечены из 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, чтобы предоставить немного больше контекста: методы "sendMessage" и "receiveMessage" в этом bean-компоненте без состояния (ниже) прекрасно работают с конфигурацией tomee.xml и jar-файлами tomee / lib MQ.

проблемы, похоже, связаны (косвенно?) С аннотациями CDI / "связыванием" бина, управляемого сообщениями (MDB) ... Я думаю, что, возможно, мои аннотацииможет быть неправильно подключен к конфигурации 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

1 Ответ

0 голосов
/ 16 октября 2018

Теперь можно развернуть рабочий MDB на apache tomee plume 7.x, подключаясь к очереди IBM MQ и т. Д.

До сих пор люблю Apache Tomee- но, пришлось исследовать / google, чтобы собрать воедино информацию из различных постов и / или фрагментов документации, чтобы получить этот документ / решение ниже ... -Не ясно, рекомендуется ли это решение (или опрометчиво), но этото, что я ищу, в том, что я НЕ хотел включать файл ".rar" IBM MQ в мой файл war (или ear) ... - но я скорее хотел развернуть его в предварительно сконфигурированном (lib), конфигурационные файлы) tomee server и т. д. (в моем случае, находящиеся в контейнере Docker)

первые файлы jar, помещенные из "wmq.jmsra-9.1.0.0.rar"в папку 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

примечание «Развертывания», указывающее на местоположение файла .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>

файл войны скопирован / развернут в папку 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)
...