2 Replies Latest reply on Jan 14, 2015 3:54 PM by vicedja

    Problems with the gateway message in the "JBOSS ESB Beginner's Guide" Chapter 3 sample project

    vicedja

      I am working through examples in the "JBOSS ESB Beginner's Guide", and I have run into a problem with the gateway message in Chapter 3.  The Chapter 3 code is a template for the rest of the book; so, I need to get it running properly.  According to the JMX MBean View, the messages are being delivered to the queue (MessageCount = 32); but, they are no being consumed (ConsumerCount = 0).  I have copied the message class and the jboss-esb.xml files below.  Any help will be greatly appreciated.

       

       

      jboss-esb.xml File:

      <?xml version="1.0"?>

      <jbossesb parameterReloadSecs="5"

      xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd"

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.3.0.xsd">

      <providers>

        <jms-provider connection-factory="ConnectionFactory" name="JBossMQ">

         <jms-bus busid="chapter3GwChannel">

          <jms-message-filter dest-name="queue/chapter3_Request_gw" dest-type="QUEUE"/>

         </jms-bus>

         <jms-bus busid="chapter3EsbChannel">

          <jms-message-filter dest-name="queue/chapter3_Request_esb" dest-type="QUEUE"/>

         </jms-bus>

        </jms-provider>

      </providers>

      <services>

        <service category="Chapter3Sample"

         description="A template for Chapter3" name="Chapter3Service">

         <listeners>

          <jms-listener busidref="chapter3GwChannel" is-gateway="true" name="Chapter3GwListener"/>

          <jms-listener busidref="chapter3EsbChannel" name="Chapter3Listener"/>

         </listeners>

         <actions mep="OneWay">

        <!--  <action name="action1" class="org.jboss.soa.esb.samples.chapter3.test.SendJMSMessage" process="displayMessage"/> -->

        <!--  <action name="action2" class="org.jboss.soa.esb.actions.SystemPrintln" name="PrintBefore"> -->

          <action class="org.jboss.soa.esb.actions.SystemPrintln" name="PrintBefore">

           <property name="message"/>

           <property name="printfull" value="true"/>

          </action>

         </actions>

        </service>

      </services>

      </jbossesb>

       

       

      Message Class:

      package org.jboss.soa.esb.samples.chapter3.test;

       

      import java.util.Properties;

       

      import javax.jms.JMSException;

      import javax.jms.MessageConsumer;

      import javax.jms.ObjectMessage;

      import javax.jms.Queue;

      import javax.jms.QueueConnection;

      import javax.jms.QueueConnectionFactory;

      import javax.jms.QueueSender;

      import javax.jms.QueueSession;

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

      import javax.jms.MessageListener;

       

       

      public class SendJMSMessage {

          QueueConnection conn;

          QueueSession session;

          Queue que;

          MessageConsumer consumer = null;

       

          public void setupConnection() throws JMSException, NamingException {

              Properties properties1 = new Properties();

              properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

              properties1.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

              properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");

              InitialContext iniCtx = new InitialContext(properties1);

       

              Object tmp = iniCtx.lookup("ConnectionFactory");

              QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;

              conn = qcf.createQueueConnection();

              que = (Queue) iniCtx.lookup("queue/chapter3_Request_gw");

              session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

             

              /* JV add consumer */

              consumer = session.createConsumer(que);

             // MessageListener myListener = consumer.getMessageListener();

             // consumer.setMessageListener(myListener);

             /*  JV add consumer */

             

              conn.start();

              System.out.println("Connection Started");

             

        

              //System.out.println("Connection Started " + conn.getMetaData().toString());

          }

       

          public void stop() throws JMSException {

              conn.stop();

              session.close();

              conn.close();

          }

         

          public void sendAMessage(String msg) throws JMSException {

              //System.out.println("here in sendAMessage(String msg) method of SendJMSMessage class");

              //System.out.println("The message is " + msg);

              //System.out.println("que name is " + que.getQueueName());

             

              QueueSender send = session.createSender(que);       

              ObjectMessage tm = session.createObjectMessage(msg);

              consumer.receive();

             

              //System.out.println("que " + que.getQueueName());

                  send.send(tm);

                  send.close();

          }

       

          public static void main(String args[]) throws Exception {

              SendJMSMessage sm = new SendJMSMessage();

              sm.setupConnection();

              sm.sendAMessage("Chapter 3 says Hello!");

              sm.stop();

          }

      }