1 Reply Latest reply on Dec 11, 2017 10:30 AM by Cheng Fang

    jmsItemReader

    Richard Moore Master

      I was looking at the JmsItemReaderWriterBase code and noticed that destination is built first, then connectionfactory, and lastly the connection. I had to write my own jndi so I am confused. The steps I have to go through when setting up code for MQ is the following which does not fit the sequence in the reader. What am I missing?

       

       

      PropertiesConfiguration properties = new PropertiesConfiguration();

      properties.read(new StringReader(FrameworkTestQueue.JNDI_CONFIGURATION));

       

      MQQueueConnectionFactory factory = new MQQueueConnectionFactory();

      factory.setHostName(configuration.getString(FrameworkTestQueue.HOST));

      factory.setChannel(configuration.getString(FrameworkTestQueue.CHANNEL));

      factory.setPort(configuration.getInt(FrameworkTestQueue.PORT));

      factory.setQueueManager(configuration.getString(FrameworkTestQueue.QUEUE_MANAGER));

      String transportTypeClassname = configuration.getString(TRANSPORT_TYPE_CLASS);

      String transportTypeFieldName = configuration.getString(TRANSPORT_TYPE_NAME);

      Field f = Class.forName(transportTypeClassname).getField(transportTypeFieldName);

      factory.setTransportType(f.getInt(null));

       

      QueueConnection connection = factory.createQueueConnection();

      connection.start();

       

      Session session = connection.createSession(FrameworkTestQueue.TRANSACTED_SESSION, Session.AUTO_ACKNOWLEDGE);

       

      Destination destination = session.createQueue(FrameworkTestQueue.QUEUE_NAME);

       

      // Perform produce, consume, browse using session and destination.

       

      session.close();

      connection.close();

       

       

      private final static String QUEUE_NAME = "MYQUEUE";

      private final static boolean TRANSACTED_SESSION = false;

       

      private final static String JNDI_CONFIGURATION = "javax.jms.port=2121" + "\n"

      + "javax.jms.host=MYHOST" + "\n"

      + "javax.jms.channel=MYCHANNEL" + "\n"

      + "javax.jms.queue.manager=MYMGR" + "\n"

      + "javax.jms.queue=" + QUEUE_NAME + "\n"

      + "javax.jms.transport.type.class=com.ibm.msg.client.wmq.v6.jms.internal.JMSC" + "\n"

      + "javax.jms.transport.type.name=MQJMS_TP_CLIENT_MQ_TCPIP" + "\n"

      + "javax.jms.factory.initial=com.ibm.mq.jms.MQQueueConnectionFactory";

       

      private static final String FACTORY = "javax.jms.factory.initial";

      private static final String PORT = "javax.jms.port";

      private static final String HOST = "javax.jms.host";

      private static final String CHANNEL = "javax.jms.channel";

      private static final String QUEUE_MANAGER = "javax.jms.queue.manager";

      private static final String TRANSPORT_TYPE_CLASS = "javax.jms.transport.type.class";

      private static final String TRANSPORT_TYPE_NAME = "javax.jms.transport.type.name";

        • 1. Re: jmsItemReader
          Cheng Fang Master

          The jberet-support class and method you mentioned:

          org.jberet.support.io.JmsItemReaderWriterBase#open

          jsr352/JmsItemReaderWriterBase.java at master · jberet/jsr352 · GitHub

           

          This jms reader or writer classes rely on either jndi lookup or CDI injection to obtain JMS ConnectionFactory and Destination resource, which means these resources are already pre-configured and ready for service.  The JMS reader or writer just needs to somehow get hold of them, and this is what JmsItemReaderWriterBase is doing.  In Java EE environment, these resources are configured and managed by the application server.  In Java SE standalone, your application needs to configure and create these resources somewhere outside the Jms reader or writer classes, and then JmsItemReaderWriterBase can obtain them via CDI injection, and less commonly, JNDI lookup.

           

          There is a test class for jms reader and writer in Java SE standalone:

          jsr352/JmsReaderWriterTest.java at master · jberet/jsr352 · GitHub

           

          Here the test uses an embedded JMS server (from Artemis JMS, non-standard) to configure and create jms resources, set them to a static field in MessagingResourceProducer class (for testing purpose only), which also implements CDI producer methods to inject these resources:
          jsr352/MessagingResourceProducer.java at master · jberet/jsr352 · GitHub