1 Reply Latest reply on Mar 13, 2003 12:05 AM by adrian.brock

    HelloMDB Example not working

    seanrocket

      Hello,

      I am trying to get the simple Hello message driven Bean example to work but it does not seem to be receiving the messages. I am using JBOSS 3.0.4 and running on Windows 2000. I do not use Windows Explorer to move the file but I use the cmd prompt window. I use HelloSender in the example directory to send messages. And I've checked that the messages are written and received correctly because I have used HelloReceiver to receive the messages successfully.

      1. Can someone tell me why the HelloMDB is not receiving messages?

      2. How can you tell if the message driven bean is deployed correctly and bound to the correct queue? Is it by using http://localhost:8080/jmx-console and looking in the JNDI view list?

      3. Is there a graphical interface to see the actual messages in the queue?

      In my example I am sending messages to the queue/testQueue.

      I have checked the queue name is correct in the jboss.xml and it matches the HelloSender code.
      I have also tried to using resource-ref tag in the ejb-jar.xml and resource-ref tag in the jboss.xml file.
      I have also checked the transacted type is false.

      According to the server.log, it has successfully deployed
      13:30:14,808 INFO [MainDeployer] Starting deployment of package: file:/C:/jboss
      /jboss-3.0.4/server/default/deploy/mdbhello.jar
      13:30:14,839 INFO [MainDeployer] Deployed package: file:/C:/jboss/jboss-3.0.4/s
      erver/default/deploy/mdbhello.jar

      My mdbhello.jar consists of 4 files
      E:\client_mdb\classes>jar tvf mdbhello.jar

      71 Wed Mar 12 13:29:44 EST 2003 META-INF/MANIFEST.MF
      836 Wed Mar 12 13:29:32 EST 2003 meta-inf/ejb-jar.xml
      340 Wed Mar 12 13:27:14 EST 2003 meta-inf/jboss.xml
      1372 Tue Mar 11 16:03:28 EST 2003 org/jboss/docs/jms/mdb/bean/HelloMDB.class

      helloMDB:************************************************

      import javax.jms.MessageListener;
      import javax.jms.Message;

      /**
      * Simple HelloWorld Message Driven Bean. May be bound to both a Topic or a Queue through the deployment descriptor.
      *
      *
      * Created: Thu Jul 26 13:20:32 2001
      *
      * @author Peter Antman
      * @version $Revision: 1.1 $ $Date: 2001/08/07 21:08:59 $
      */

      public class HelloMDB implements MessageDrivenBean, MessageListener {

      private MessageDrivenContext ctx = null;

      public HelloMDB() {
      }

      //--- MessageDrivenBean
      public void setMessageDrivenContext(MessageDrivenContext ctx)
      throws EJBException {
      this.ctx = ctx;
      }

      public void ejbCreate() {}

      public void ejbRemove() {ctx=null;}

      //--- MessageListener
      public void onMessage(Message message) {
      System.err.println("Bean got message" + message.toString() );
      }

      } // HelloMDB

      ejb-jar.xml :*******************************************
      <?xml version="1.0"?>
      <!DOCTYPE ejb-jar>
      <ejb-jar>
      <enterprise-beans>
      <message-driven>
      <ejb-name>HelloQueueMDB</ejb-name>
      <ejb-class>org.jboss.docs.jms.mdb.bean.HelloMDB</ejb-class>
      <message-selector></message-selector>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
      <destination-type>javax.jms.Queue</destination-type>
      </message-driven-destination>
      </message-driven>
      </enterprise-beans>
      <assembly-descriptor>
      <container-transaction>

      <ejb-name>HelloQueueMDB</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>

      jboss.xml :*********************************************
      <?xml version="1.0"?>

      <enterprise-beans>
      <message-driven>
      <ejb-name>HelloQueueMDB</ejb-name>
      <configuration-name>Standard Message Driven Bean</configuration-name>
      <destination-jndi-name>queue/testQueue</destination-jndi-name>
      </message-driven>
      </enterprise-beans>


      HelloSender: ****************************************
      /*
      * JBoss, the OpenSource EJB server
      *
      * Distributable under LGPL license.
      * See terms of license at gnu.org.
      */

      package org.jboss.docs.jms.client;

      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueConnection;
      import javax.jms.QueueSession;
      import javax.jms.QueueSender;
      import javax.jms.Queue;
      import javax.jms.TextMessage;
      import javax.jms.Session;
      import javax.jms.JMSException;
      import java.util.Hashtable;
      /**
      * Simple JMS client, send text messages to testQueue Queue.
      *
      *
      * NOTEThis code is showcase only. It may not provide a stable production example.
      * @author Peter Antman
      * @version $Revision: 1.1 $
      */

      public class HelloSender {

      /**
      * Queue connection, hold on to this so you may close it.
      */
      QueueConnection queueConnection;

      /**
      * Queue session, hold on to this so you may close it. Also used to create messages.
      */
      QueueSession queueSession;

      /**
      * Use this to send messages.
      */
      QueueSender queueSender;

      /**
      * Destination to send to
      */
      Queue queue;


      /**
      * Sets up all the JMS fixtures.
      *
      * Use close() when finished with object.
      *
      * @param factoryJNDI name of the queue connection factory to look up.
      * @param queueJNDI name of the queue destination to look up
      */
      public HelloSender(String factoryJNDI, String queueJNDI) throws JMSException, NamingException {
      System.out.println(" *!!!!!!!!!!!!1before initial context");
      Hashtable ht = new Hashtable();

      ht.put(Context.INITIAL_CONTEXT_FACTORY,new String("org.jnp.interfaces.NamingContextFactory"));
      ht.put(Context.PROVIDER_URL, "localhost:1099");

      ht.put("java.naming.factory.url.pkgs",new String("org.jboss.naming:org.jnp.interfaces"));
      // Get the initial context
      Context context = new InitialContext(ht);
      System.out.println(" ************** after initial context");
      ht = context.getEnvironment();

      String factinit =(String)ht.get(Context.INITIAL_CONTEXT_FACTORY);
      String urlpkg = (String)ht.get("java.naming.factory.url.pkgs");
      System.out.println("factory inital 1: " + factinit);
      System.out.println("url package : " + urlpkg);
      // Get the connection factory
      QueueConnectionFactory queueFactory =
      (QueueConnectionFactory)context.lookup(factoryJNDI);
      System.out.println("after lookup of QueueConntectionFactory");
      // Create the connection
      queueConnection = queueFactory.createQueueConnection();
      System.out.println("after create queueconnection");
      // Create the session
      queueSession = queueConnection.createQueueSession(
      // No transaction
      false,
      // Auto ack
      Session.AUTO_ACKNOWLEDGE);
      System.out.println("after create queue session");
      // Look up the destination
      queue = (Queue)context.lookup(queueJNDI);
      System.out.println("after lookup of queue");
      // Create a sender
      queueSender = queueSession.createSender(queue);

      }

      /**
      * Send the given String as a JMS message to the testQueue queue.
      */
      public void send(String msg) throws JMSException {

      // Create a message
      TextMessage message = queueSession.createTextMessage();
      message.setText(msg);

      // Send the message
      queueSender.send(queue, message);
      }

      /**
      * Close session and connection. When done, no sending is possible any more.
      */
      public void close() throws JMSException {
      queueSession.close();
      queueConnection.close();
      }

      /**
      * Run an example sending 10 messages to testQueue. Only works up to and including JBoss 2.4.x
      */
      public static void main(String[] args) {
      try {

      //Create the HelloSender, giving it the name of the QueueConnection
      //Factory and the Queue destination to use in lookup.

      HelloSender sender = new HelloSender(
      // Name of ConnectionFactory
      "ConnectionFactory",//"QueueConnectionFactory" is not used for ver 2.4 and later
      // Name of destination to send to
      "queue/testQueue"
      );

      // Send 10 messages
      for (int i = 1; i < 11; i++) {
      String msg = "Hello World no. real cooool " + i;
      System.out.println("Sending message: " + msg);
      sender.send(msg);
      }

      // Close down your sender
      sender.close();

      }catch(Exception ex) {
      System.err.println("An exception occured while testing HelloSender: " + ex);
      ex.printStackTrace();
      }

      }

      } // HelloSender

      -Sean