From 64a5f64106cccb3feb68f7155650e603671662df Mon Sep 17 00:00:00 2001 From: Suyog Barve Date: Thu, 2 Mar 2017 16:56:05 -0600 Subject: [PATCH] amq and imp portability using tome amq and imp portability using tome --- examples/tomee-jms-portability/Readme.md | 86 +++++++++++ examples/tomee-jms-portability/pom.xml | 92 +++++++++++ examples/tomee-jms-portability/src/.DS_Store | Bin 0 -> 6148 bytes .../tomee-jms-portability/src/main/.DS_Store | Bin 0 -> 6148 bytes .../src/main/java/.DS_Store | Bin 0 -> 6148 bytes .../src/main/java/com/.DS_Store | Bin 0 -> 6148 bytes .../src/main/java/com/company/.DS_Store | Bin 0 -> 6148 bytes .../main/java/com/company/tutorial/.DS_Store | Bin 0 -> 6148 bytes .../company/tutorial/service/AMQReadBean.java | 28 ++++ .../company/tutorial/service/ChatBean.java | 93 +++++++++++ .../tutorial/service/EchoResource.java | 55 +++++++ .../tutorial/service/JmsTestResource.java | 145 ++++++++++++++++++ .../company/tutorial/service/WMQReadBean.java | 29 ++++ .../src/main/resources/.DS_Store | Bin 0 -> 6148 bytes .../src/main/resources/META-INF/.DS_Store | Bin 0 -> 6148 bytes .../src/main/resources/META-INF/ejb-jar.xml | 102 ++++++++++++ .../main/resources/META-INF/openejb-jar.xml | 14 ++ .../src/main/webapp/.DS_Store | Bin 0 -> 6148 bytes .../src/main/webapp/WEB-INF/beans.xml | 6 + .../src/main/webapp/WEB-INF/resources.xml | 113 ++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 5 + .../tutorial/service/ChatBeanTest.java | 73 +++++++++ 22 files changed, 841 insertions(+) create mode 100644 examples/tomee-jms-portability/Readme.md create mode 100644 examples/tomee-jms-portability/pom.xml create mode 100644 examples/tomee-jms-portability/src/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/java/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/java/com/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/java/com/company/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/java/com/company/tutorial/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/AMQReadBean.java create mode 100644 examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/ChatBean.java create mode 100644 examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/EchoResource.java create mode 100644 examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/JmsTestResource.java create mode 100644 examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/WMQReadBean.java create mode 100644 examples/tomee-jms-portability/src/main/resources/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/resources/META-INF/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/resources/META-INF/ejb-jar.xml create mode 100644 examples/tomee-jms-portability/src/main/resources/META-INF/openejb-jar.xml create mode 100644 examples/tomee-jms-portability/src/main/webapp/.DS_Store create mode 100644 examples/tomee-jms-portability/src/main/webapp/WEB-INF/beans.xml create mode 100644 examples/tomee-jms-portability/src/main/webapp/WEB-INF/resources.xml create mode 100644 examples/tomee-jms-portability/src/main/webapp/WEB-INF/web.xml create mode 100644 examples/tomee-jms-portability/src/test/java/com/company/tutorial/service/ChatBeanTest.java diff --git a/examples/tomee-jms-portability/Readme.md b/examples/tomee-jms-portability/Readme.md new file mode 100644 index 00000000000..13c6b425a55 --- /dev/null +++ b/examples/tomee-jms-portability/Readme.md @@ -0,0 +1,86 @@ +# Tomee-sample application to demo portability between ActiveMQ and IBM MQ +v1.0, created on 2-09-2017 + +### Description +This app demonstrates capability to achive portability/interoperability between ActiveMQ and IBM MQ for tomee based application of type MDB and Custom Java based JMS connection. It covers patterns and learnings as listed below + +1. How to run multiple mdb containers in same JVM +2. Various ways of configuring IBM Queues/Topics vs AMQ Queues/Topics +3. MDB configuration for IBM MQ vs AMQ, Annotations vs Configuration +4. Static vs Dynamic declaration/override of queues/topics +5. Use and importance of RA (Resource Adapaters), Connection Factory +6. Web service samples to write data to IBM Queues and AMQ Queues using injection of resources (connection factories and queue/topics) +7. JNDI reference to resources (see WMQReadBean configuration in ejb-jar.xml) + + +### Running this application +#### Environment +Application can be imported in IDE like eclipse as a maven project and is tested using apache-tomee-plume-7.0.2, apache-activemq-5.14.3 (running as standalone on localhost, IBM MQ 8.x.x (connections details hidden to avoid misuse, those how want to test can reach out to middleware team to get access to managed IBM MQ instance and AppWatch )) + +#### Additional Libraries +In order to connect to IBM MQ, tomee requires additional libraries containing implementation for JCA Resource Adapter, IBM MQ connection factories, queue/topic resources, ActivationConfigs etc. These libraries come with IBM subscription and all of them are not available on maven central, below is list of all IBM specific jar files + +com.ibm.mq.connector.jar +com.ibm.mq.jar +com.ibm.mq.pcf.jar +com.ibm.mq.headers.jar +com.ibm.mq.jmqi.jar +com.ibm.mqjms.jar +providerutil.jar + +com.ibm.mq.connector.jar can be extracted from wmq.jmsra.rar which is availble with IBM MQ installation (not available on internet) + + +#### tomee.xml: +This file (located under tomee_home/conf is left blank as we would like our application to manage all resources.Any resource declared here would be available to all application deployed on the server. +(File not included in this git repo) +``` + + + +``` + +#### catalina.properties: This file can be used to convinently provide -D java arguments as an input to tomee. However in real world these parameters would be configured using environment variables to avoid adding application specific properties in tomme conf (File not included in this git repo) + +``` +com.ibm.msg.client.commonservices.log.status=OFF + +AMQReadBean2.activation.destination=overriden_queue_IMQReadBean +#queue destinations +amq.variable.destination=my_overriden_value +#Resource overrides +#amq_ra.ServerUrl=tcp://xxxxx.xxx.xxx.com:61616 + +#MDB Activation Config overrides +#Hirarchy for activation override rules (specific to generic) +#1 -D.activation.= +#2. -D.activation.= +#3. -D.activation.= +#4. -Dmdb.activation.= +#mdb.activation.destination=overriden_queue_value +WMQReadBean.activation.HostName=10.234.56.789 +``` + +#### resources.xml: +This file is application specific placeholder for resources (it will override any matching resources declared in tomee.xml) like resource-adapters, connection-factories, queues, topics, mdb-containers etc. +This example makes heavy use of this file which is under src/main/webapp/WEB-INF, for applications deployed as war file it get copied to ###/webapps/application-name/WEB-INF/resources.xml . + +#### ejb-jar.xml: +This file is located under src/main/resources/META-INF/ and contains application specific configuration for enterprise beans, in the demo we have configured our message beans in this file. Definitions in this file are equivalent of annotations , version="3.1" will support a combination of configured and annotated beans. One important difference between annotated beans and configured beans is as follows. If there are multiple containers defined or use in same application(Like this application uses amq-container and imq-container) +Any annotated bean is sequentially binded to the container resource, this can bring inpredictability and may result in a Bean getting binded to incorrect target container. As an example ChatBean MDB is intentionally commented as it may throw errors by getting incorrectly binded to IMQ. To deal with such problems, configuration based approach can be used in conjunction with openejb-jar.xml (as described below) + +#### openejb-jar.xml: +This file is located under src/main/resources/META-INF/ and contains additional mapping between ejb and targeted containers. It also has a deployment id which can be used to create multiple deployments for same ejb in a container or across containers. This is very useful when you want to bind a specific bean to desired container (example WMQReadBean should necessarily bind to simple-tomee-1.0/imq_container container) + +#### web.xml: +Typical web resource file, not used much in this tutorial app + +#### beans.xml: +To use @Inject, the first thing you need is a META-INF/beans.xml file in the module or jar. This effectively turns on CDI and allows the @Inject references to work. No META-INF/beans.xml no injection, period +Not used in this tutorial app + + +### Developers + Suyog Barve + + diff --git a/examples/tomee-jms-portability/pom.xml b/examples/tomee-jms-portability/pom.xml new file mode 100644 index 00000000000..cbe09e12269 --- /dev/null +++ b/examples/tomee-jms-portability/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + com.company.tutorials + simple-tomee + war + 1.0 + OpenEJB :: tomee :: IBM MQ AMQ Portability Examples :: MDB Example + + UTF-8 + + + install + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.7 + 1.7 + + + + + + + apache-m2-snapshot + Apache Snapshot Repository + https://repository.apache.org/content/groups/snapshots + + + + + org.apache.tomee + javaee-api + 7.0-1 + provided + + + junit + junit + 4.12 + test + + + ch.qos.logback + logback-classic + 1.1.7 + + + + org.codehaus.janino + janino + 2.7.8 + + + + javax.jms + jms + 2.0 + + + + + + + + + localhost + file://${basedir}/target/repo/ + + + localhost + file://${basedir}/target/snapshot-repo/ + + + diff --git a/examples/tomee-jms-portability/src/.DS_Store b/examples/tomee-jms-portability/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..98d4b02764e43ed63bd431193f282b87ebf9f30e GIT binary patch literal 6148 zcmeHKPfP1S5Z|r!nKYL?o}%C-SD}ac=h17ddK3y3MO12H0$qqnX;O=nLe72+|GekN z5YZ3eH}UAq?zU8_HxZQ?nElPp&g^!7TXwRHF<$Ei%Z%BKF#{B_U_$eT;5h1p6toAC z;~ai3ZTnH;L;raqnjBw|0X(}RJ7pddEFM2Uza5D*t5lwNVX8R&YsN53mSvSJ`*-Q6 z(Mo!a%*(oI&FdVYW=GzlN)@s^w^-g#OsdX<7cSS0E5sB>FFiq1ioA!LazfvhXYb%vO+38oSXs=cW z1N+V}7MK36Z|}DU7nfJpH~;?M-an{A;P8Ky@<-zk9>Ey#5u_)P4?7qJ4}%Da0b+m{ z_~s1gYt68}`9A3969dG+$1{NUg9D1_YRnbNs{!nd=t{m#c%{k>QNH3aKRqh=JD(OsTGo^?&RA z_y6l8>JbCPz>i{p7dIQ5HQ17_trMHWTI+xwgQ8$uu5gqBhAhPpi=}u0R0{YVGyq+V TxkB)O(1(Deff{1qQyF*xmjz?R literal 0 HcmV?d00001 diff --git a/examples/tomee-jms-portability/src/main/.DS_Store b/examples/tomee-jms-portability/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..c829fc5dae425114d0bdae5743fc445818dbb84a GIT binary patch literal 6148 zcmeHK%T5C^3>?D>6>;g2V}5}@h^q1h`~ZD$L6x?mDqQ!*Z!>mWY0-kz69+mYIg>bc zqRe5v24IWh_5qj!n9-c^>BAJh?>50zdalXlXKW9f-Ma60T$~Hf?eK~f-mx0z-{K7~ zIH1RovyIQk+c)^2Yt6hp_NR?=FIAirkOERb3P^zqRv^pt?Cyd!(9@-W6!=*I|2`C& zb4?x^$ESlsv;gFe?f~b}OOT5@$TfLrOb=l#mE2M-TMTRI^p}jQ$wT9o4$J1l@@C5p z#o~6JUm_e<8*7vTQsBD+-g^^sum6vH1@V-^m;4I%_5-~tF3K^+i#j?VMXLSaS~dY0@jc51bKLsN^0 z?w;4J$RHv;+$b9h6I0}!Tx68{^>MkK$MI$*w?)zl@IfZ~xlK?3DnJFO02QDDGg2TA z@_sd=XX2w!0V*&L1?>A!;KrJ4LH~3h_y_tMAK>5S|49o|DnJGPOaWc) zkNX{7D$mxB*R%R5tF~@%&@V@L`w2i|NAVi&hW%m-uqIm&6&Qa6Tm}Xz@KXg|*oF~o literal 0 HcmV?d00001 diff --git a/examples/tomee-jms-portability/src/main/java/com/.DS_Store b/examples/tomee-jms-portability/src/main/java/com/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..7f4114c3f39015a0ead2423e5070c5ce63f6a969 GIT binary patch literal 6148 zcmeHKJ5EC}5S)cbL`st~rLVvZtSFoy7f49Tz(Yb5bg$xE9F5seLG(x$3ec>y9(%oG z%Tv643&7TI$9rH2U`}_$hYwTpefNpoRK$pMp0UR>-jA<`)8jD7{yE^>I~*|J2`}II z!^yW~Qa}nw0VyB_q`;LGr~*4*T=`rbCk3Ry-&erD4~_2F3&+Ixba03kfH-3~jPvLv zh|L4UUN|N)LbIe2lWNssSkf79mDdZ$#H7Qj`LMd#szb53o#(emhxJ5_Qa}ovD{!03 zrPu!l`i1`goTQZ$kOKco0h?{Mn>C+QwRQ41ueFW7qkGOL-Hr30aENkDjB?C{m*Z6= bWnS|+_j}=(7<9&iPSnqU>mri^zpcO*W04h} literal 0 HcmV?d00001 diff --git a/examples/tomee-jms-portability/src/main/java/com/company/.DS_Store b/examples/tomee-jms-portability/src/main/java/com/company/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..729490a268dbebfc1597bc58935fc0dfdee473ca GIT binary patch literal 6148 zcmeHKJ8r`;3?&;62D)U-s4Mgaf{~n{7f4z!1q>Kyo842-m813XGt_XiIg9ZKP*0-x zBxLoPD(U+=>r`~QG(TltnNeEiFQ z8^^&mX;gp;Pys4H1*pKP3S@b0pI1GVhfx74umuI|`%vJ9HE{~`PX`8X0e}s{ZkT&7 z0W1~(*2F0g5ts%Q7*x#`LxYZZ$-J641qNL-n-9&KH9Hjb+i`yJbkQ2fkqS_OxdOXb z?ydfx;CK4}If*MOKm|6XfHue1V}~bYZCyOhYHfj^;g)lQn_=!03|@|bUXHP_a(wWl b$SXF-eodSLosPKEf&3XTU1(I`(F*(mayb>N literal 0 HcmV?d00001 diff --git a/examples/tomee-jms-portability/src/main/java/com/company/tutorial/.DS_Store b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..26b07414eb3bff675605929616f26b9406fe3bd0 GIT binary patch literal 6148 zcmeHKOKL(v5Ufsw2yR?vIalxogP0R|fe>{e2tp)Tzg5oV(Ng^(M4qlBn@|niHPf%_ z4O5HPuL0QdW4i$60H$.activation.= +//2. -D.activation.= +//3. -D.activation.= +//4. -Dmdb.activation.= + +public class AMQReadBean implements MessageListener { + + public void onMessage(Message message) { + try { + final TextMessage textMessage = (TextMessage) message; + final String text = textMessage.getText(); + System.out.println("*************Properties: mdb.activation.destination : " + System.getProperty("mdb.activation.destination")); + System.out.println("*************Properties: java.util.logging.config.file : " + System.getProperty("java.util.logging.config.file")); + + System.out.println("****Read Message****"+ text); + } catch (JMSException e) { + throw new IllegalStateException(e); + } + } +} \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/ChatBean.java b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/ChatBean.java new file mode 100644 index 00000000000..81814c4a429 --- /dev/null +++ b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/ChatBean.java @@ -0,0 +1,93 @@ +/*package com.company.tutorial.service; + +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(name="ChatBean", activationConfig = { +@ActivationConfigProperty( + propertyName = "destinationType", + propertyValue = "javax.jms.Queue"), + @ActivationConfigProperty( + propertyName = "destination", + propertyValue = "${ChatBean}")}) + //propertyValue = "ChatBean")}) +public class ChatBean implements MessageListener { + + + @Resource(name = "amq_qcf") + private ConnectionFactory amq_connectionFactory; + + @Resource(name = "AnswerQueue") + private Queue answerQueue; + + public void onMessage(Message message) { + try { + + final TextMessage textMessage = (TextMessage) message; + final String question = textMessage.getText(); + System.out.println("*************Properties: mdb.activation.destination : " + System.getProperty("mdb.activation.destination")); + System.out.println("*************Properties: java.util.logging.config.file : " + System.getProperty("java.util.logging.config.file")); + + if ("Hello World!".equals(question)) { + + respond("Hello, Test Case!"); + + } else if ("How are you?".equals(question)) { + + respond("I'm doing well."); + + } else if ("Still spinning?".equals(question)) { + + respond("Once every day, as usual."); + + } + } catch (JMSException e) { + throw new IllegalStateException(e); + } + } + + private void respond(String text) throws JMSException { + + Connection connection = null; + Session session = null; + + try { + connection = amq_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(); + } + } + } +} +*/ \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/EchoResource.java b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/EchoResource.java new file mode 100644 index 00000000000..1b589ee8d48 --- /dev/null +++ b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/EchoResource.java @@ -0,0 +1,55 @@ +package com.company.tutorial.service; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +@Path("/echo") +public class EchoResource { + final static Logger logger = LoggerFactory.getLogger(EchoResource.class); + @PUT + @Produces({ MediaType.TEXT_PLAIN }) + @Path("/") + public Response echoPut(@Context HttpServletRequest req) throws IOException { + String body = read(req.getInputStream()); + logger.debug("Received PUT/POST request: " + body); + return Response.ok(body).build(); + } + + @POST + @Produces({ MediaType.TEXT_PLAIN }) + @Path("/") + public Response echoPost(@Context HttpServletRequest req) throws IOException { + return echoPut(req); + } + + @GET + @Produces({ MediaType.TEXT_PLAIN }) + @Path("/") + public Response echoGet(@Context HttpServletRequest req) { + logger.debug("Received GET request."); + return Response.ok().build(); + } + + public static String read(InputStream input) throws IOException { + try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) { + return buffer.lines().collect(Collectors.joining("\n")); + } + } +} \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/JmsTestResource.java b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/JmsTestResource.java new file mode 100644 index 00000000000..04147c877a4 --- /dev/null +++ b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/JmsTestResource.java @@ -0,0 +1,145 @@ +package com.company.tutorial.service; + +import java.io.IOException; + +import javax.annotation.Resource; +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + + +@Path("/jms") +public class JmsTestResource { + + @Resource(name = "imq.bar") + private Queue imq_barQueue; + + @Resource(name = "amq.bar") + private Queue amq_barQueue; + + @Resource(name = "amq.bar.pop") + private Queue amq_bar_popQueue; + + @Resource(name = "amq.variable") + private Queue amq_variableQueue; + + @Resource(name = "imq_qcf") + private ConnectionFactory imq_connectionFactory; + + @Resource(name = "amq_qcf") + private ConnectionFactory amq_connectionFactory; + + + @GET + @Produces({ MediaType.TEXT_PLAIN }) + @Path("/send2imq") + public Response testSend1(@QueryParam("msg") String msg) throws IOException, JMSException { + Connection connection = imq_connectionFactory.createConnection(); + connection.start(); + + // Create a Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Create a MessageProducer from the Session to the Topic or Queue + MessageProducer producer = session.createProducer(imq_barQueue); + + System.out.println("*************producer.getClass() = "+ producer.getClass()); + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Create a message + TextMessage message = session.createTextMessage((msg!=null && !msg.isEmpty()) ? msg : "Hello World!"); + + // Tell the producer to send the message + producer.send(message); + + return Response.ok().build(); + } + + + @GET + @Produces({ MediaType.TEXT_PLAIN }) + @Path("/send2amq") + public Response testSend2(@QueryParam("msg") String msg) throws IOException, JMSException { + Connection connection = amq_connectionFactory.createConnection(); + connection.start(); + + // Create a Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Create a MessageProducer from the Session to the Topic or Queue + MessageProducer producer = session.createProducer(amq_barQueue); + + System.out.println("*************producer.getClass() = "+ producer.getClass()); + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Create a message + TextMessage message = session.createTextMessage((msg!=null && !msg.isEmpty()) ? msg : "Hello World!"); + + // Tell the producer to send the message + producer.send(message); + + return Response.ok().build(); + } + + @GET + @Produces({ MediaType.TEXT_PLAIN }) + @Path("/send2amq2") + public Response testSend3(@QueryParam("msg") String msg) throws IOException, JMSException { + Connection connection = amq_connectionFactory.createConnection(); + connection.start(); + + // Create a Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Create a MessageProducer from the Session to the Topic or Queue + MessageProducer producer = session.createProducer(amq_bar_popQueue); + + System.out.println("*************producer.getClass() = "+ producer.getClass()); + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Create a message + TextMessage message = session.createTextMessage((msg!=null && !msg.isEmpty()) ? msg : "Hello World!"); + + // Tell the producer to send the message + producer.send(message); + + return Response.ok().build(); + } + + @GET + @Produces({ MediaType.TEXT_PLAIN }) + @Path("/send2amq3") + public Response testSend4(@QueryParam("msg") String msg) throws IOException, JMSException { + Connection connection = amq_connectionFactory.createConnection(); + connection.start(); + + // Create a Session + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + // Create a MessageProducer from the Session to the Topic or Queue + MessageProducer producer = session.createProducer(amq_variableQueue); + + System.out.println("*************producer.getClass() = "+ producer.getClass()); + System.out.println("*************amq.variable.destination : "+ System.getProperty("amq.variable.destination")); + producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); + + // Create a message + TextMessage message = session.createTextMessage((msg!=null && !msg.isEmpty()) ? msg : "Hello World!"); + + // Tell the producer to send the message + producer.send(message); + + return Response.ok().build(); + } +} \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/WMQReadBean.java b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/WMQReadBean.java new file mode 100644 index 00000000000..4237a15163a --- /dev/null +++ b/examples/tomee-jms-portability/src/main/java/com/company/tutorial/service/WMQReadBean.java @@ -0,0 +1,29 @@ +package com.company.tutorial.service; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.TextMessage; + + +//1 -D.activation.= +//2. -D.activation.= +//3. -D.activation.= +//4. -Dmdb.activation.= + +public class WMQReadBean implements MessageListener { + + public void onMessage(Message message) { + try { + + final TextMessage textMessage = (TextMessage) message; + final String text = textMessage.getText(); + System.out.println("*************Properties: mdb.activation.destination : " + System.getProperty("mdb.activation.destination")); + System.out.println("*************Properties: java.util.logging.config.file : " + System.getProperty("java.util.logging.config.file")); + + System.out.println("****Read Message****"+ text); + } catch (JMSException e) { + throw new IllegalStateException(e); + } + } +} \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/resources/.DS_Store b/examples/tomee-jms-portability/src/main/resources/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b85d727251b9cdc3c31bdd352fa4f83d9dbbe561 GIT binary patch literal 6148 zcmeHKJ5EC}5S)b+Pohal=?hSB0}~}k6wrhNAV?W01)_gd&XuEO_EQi&=#nOymDXdg zcWilzw{HR1;%D;+%mEB^N9=u=n(w<$?4}|{r1OjiyxV4xa|gU)g?Bvt z=6~*XTi=vP0VyB_q<|EV0%ujA%Ik1<)>Czu6p#Yfpn!iL8r`uMj*0Q<;1DeUamH{M z=g~_Ln+J%!a7<)`W=SO`)vCp?q%+xmkrfD|}Y z;5L_Yum3ChKmGqHNh>KJ1+Gc~n=RMN1)o&4b@Di`wT=Ek_nZUWjq{*zh;mGfa?FL7 eH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + + + + + + + + AMQReadBean + com.company.tutorial.service.AMQReadBean + + javax.jms.MessageListener + + + + destination + AMQReadBean + + + destinationType + javax.jms.Queue + + + + + + + + + AMQReadBean2 + com.company.tutorial.service.AMQReadBean + + javax.jms.MessageListener + + + + destination + AMQReadBean2 + + + destinationType + javax.jms.Queue + + + + + + + + WMQReadBean + com.company.tutorial.service.WMQReadBean + javax.jms.MessageListener + Container + + + destinationType + javax.jms.Queue + + + + destination + openejb:Resource/simple-tomee-1.0/imq.bar + + + useJNDI + true + + + + HostName + 1.1.1.1 + + + Port + 1414 + + + QueueManager + XXXXXXX + + + Channel + CLIENT.T.EICOM9 + + + TransportType + CLIENT + + + + + + + \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/resources/META-INF/openejb-jar.xml b/examples/tomee-jms-portability/src/main/resources/META-INF/openejb-jar.xml new file mode 100644 index 00000000000..34b20a2136e --- /dev/null +++ b/examples/tomee-jms-portability/src/main/resources/META-INF/openejb-jar.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/webapp/.DS_Store b/examples/tomee-jms-portability/src/main/webapp/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ee486585642eab4aaa0532224d5ce0dfcde9a725 GIT binary patch literal 6148 zcmeHKyG{c!5S)cbL`svA(mz1KA6Ta(QW_eHvpcS z=p~5F1H@i9CNe^^q!N>A)nZuE8E=)>3&+Hy!>akPy4k8jvACV*w@8QeM2%8F3Y;r& zo6Duw|26$W|9?)>N(xAUf2DxUR?n+}PpaBFd7RhUMt`Au&KKQ{^Pq5ua!ibJ%!QZZ d`$)>X=5y}%!Z9)Ej0c^lp8?lJCIx<5ffKS&6eIuu literal 0 HcmV?d00001 diff --git a/examples/tomee-jms-portability/src/main/webapp/WEB-INF/beans.xml b/examples/tomee-jms-portability/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 00000000000..24329ff1b59 --- /dev/null +++ b/examples/tomee-jms-portability/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/webapp/WEB-INF/resources.xml b/examples/tomee-jms-portability/src/main/webapp/WEB-INF/resources.xml new file mode 100644 index 00000000000..b6df0477b0f --- /dev/null +++ b/examples/tomee-jms-portability/src/main/webapp/WEB-INF/resources.xml @@ -0,0 +1,113 @@ + + + + + BrokerXmlConfig = + ServerUrl = tcp://127.0.0.1:61616 + + + + ResourceAdapter = amq_ra + + + + ResourceAdapter = amq_ra + + + + destination=AnswerQueue + + + + destination=ChatBean + + + + destination=amq.bar.pop + + + + + destination=defaultValue + + + + + + + ResourceAdapter=imq_ra + MessageListenerInterface=javax.jms.MessageListener + ActivationSpecClass=com.ibm.mq.connector.inbound.ActivationSpecImpl + + + + + connectionConcurrency=5 + maxConnections=10 + logWriterEnabled=false + reconnectionRetryCount=5 + reconnectionRetryInterval=300000 + traceEnabled=false + traceLevel=3 + + + + + TransactionSupport=none + ResourceAdapter=imq_ra + HostName=10.123.45.678 + Port=1414 + QueueManager=XXXXXX + Channel=CLIENT.T.XXXXX + TransportType=CLIENT + + + + TransactionSupport=xa + ResourceAdapter=imq_ra + + + + TransactionSupport=xa + ResourceAdapter=imq_ra + + + + arbitraryProperties + baseQueueManagerName=XXXXXXXX + baseQueueName=QL.XXX.WW.XXXXXX.TEST + CCSID=1208 + encoding=NATIVE + expiry=APP + failIfQuiesce=true + persistence=APP + priority=APP + readAheadClosePolicy=ALL + targetClient=MQ + + + + arbitraryProperties + baseTopicName=WW.XXXXXXXX.XX.XXXXX + brokerCCDurSubQueue=SYSTEM.JMS.D.CC.SUBSCRIBER.QUEUE + brokerDurSubQueue=SYSTEM.JMS.D.SUBSCRIBER.QUEUE + brokerPubQueue + brokerPubQueueManager + brokerVersion=1 + CCSID=1208 + encoding=NATIVE + expiry=APP + failIfQuiesce=true + persistence=APP + priority=APP + readAheadClosePolicy=ALL + targetClient=MQ + + + \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/main/webapp/WEB-INF/web.xml b/examples/tomee-jms-portability/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 00000000000..108fc142d75 --- /dev/null +++ b/examples/tomee-jms-portability/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/examples/tomee-jms-portability/src/test/java/com/company/tutorial/service/ChatBeanTest.java b/examples/tomee-jms-portability/src/test/java/com/company/tutorial/service/ChatBeanTest.java new file mode 100644 index 00000000000..dfb4eb07c08 --- /dev/null +++ b/examples/tomee-jms-portability/src/test/java/com/company/tutorial/service/ChatBeanTest.java @@ -0,0 +1,73 @@ +//package com.company.tutorial.service; +// +//import junit.framework.TestCase; +// +//import java.util.Properties; +// +//import javax.annotation.Resource; +//import javax.ejb.embeddable.EJBContainer; +//import javax.jms.Connection; +//import javax.jms.ConnectionFactory; +//import javax.jms.JMSException; +//import javax.jms.MessageConsumer; +//import javax.jms.MessageProducer; +//import javax.jms.Queue; +//import javax.jms.Session; +//import javax.jms.TextMessage; +// +//import org.apache.openejb.loader.SystemInstance; +//import org.apache.openejb.testing.Configuration; +//import org.apache.openejb.testng.PropertiesBuilder; +// +//public class ChatBeanTest extends TestCase { +// +// @Resource +// private ConnectionFactory connectionFactory; +// +// @Resource(name = "ChatBean") +// private Queue questionQueue; +// +// @Resource(name = "AnswerQueue") +// private Queue answerQueue; +// +// public void test() throws Exception { +// +// EJBContainer.createEJBContainer().getContext().bind("inject", this); +// +// final Connection connection = connectionFactory.createConnection(); +// +// connection.start(); +// +// final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); +// +// final MessageProducer questions = session.createProducer(questionQueue); +// +// final MessageConsumer answers = session.createConsumer(answerQueue); +// +// sendText("Hello World!", questions, session); +// +// assertEquals("Hello, Test Case!", receiveText(answers)); +// +// sendText("How are you?", questions, session); +// +// assertEquals("I'm doing well.", receiveText(answers)); +// +// sendText("Still spinning?", questions, session); +// +// assertEquals("Once every day, as usual.", receiveText(answers)); +// +// } +// +// private void sendText(String text, MessageProducer questions, Session session) throws JMSException { +// +// questions.send(session.createTextMessage(text)); +// +// } +// +// private String receiveText(MessageConsumer answers) throws JMSException { +// +// return ((TextMessage) answers.receive(1000)).getText(); +// +// } +// +//} \ No newline at end of file