6 Replies Latest reply on Nov 16, 2002 12:17 PM by Juha Lindfors

    Message Driven Bean in JBoss

    koltar Newbie

      I have gotten the template stuff working but now I am attempting to make a Hello World Message Driven Bean and I can not find any good documentation on how to do this in JBoss 3.0.4.

      Writing the code for the message driven bean is trivial but setting up JBoss is a task. Is there anyone who has a good hello world example that states what I need to put in the xml files and what xml files are to be touched in Jboss 3.0.4? I took a look at the example in the old online-manual but the xml files names are different and it does not tell you where these newly created xml files need to go.

      I've made a brief attempt at it and currently its telling the JNDI name is not bound. I know it has to do with all of these different xml files that need to be created and edited but I can not find an example that works with 3.0.4.

      Any help is greatly appreciated.

        • 1. Re: Message Driven Bean in JBoss
          koltar Newbie

          I'm trying to make a this client code work from a JSP. The code goes through without throwing an exception I was able to fix the ConnectionFactory error but using ConnectionFactory and added loginAuditQueue to the jbossmq-destination.xml.

          The code runs through without an error but I am not abel to get a System.out.println or logging to file. It is as if the Message Driven Bean I created is not listening to the Queue and the onMessage is not getting called. I'm not sure what piece I am missing.

          Any help would be apprciated greatly!

          JSP Code that runs without error

          Context context = new InitialContext();
          QueueConnectionFactory queueFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
          QueueConnection queueConnection = queueFactory.createQueueConnection();
          QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
          Queue queue = (Queue)context.lookup("queue/loginAuditQueue");
          QueueSender queueSender = queueSession.createSender(queue);
          ObjectMessage message = queueSession.createObjectMessage();
          message.setObject("Login: TESTING");
          queueSender.send(queue, message);
          queueSession.close();
          queueConnection.close();

          HelloWorld MessageDriven Bean

          import java.rmi.RemoteException;
          import javax.ejb.CreateException;
          import javax.ejb.EJBException;
          import javax.ejb.RemoveException;
          import javax.ejb.MessageDrivenBean;
          import javax.ejb.MessageDrivenContext;
          import javax.jms.Message;
          import javax.jms.MessageListener;

          /**
          * Message Driven Bean Template
          *
          * @ejb:bean name="LoginAuditMDB"
          * display-name="Message Driven Login Audit Bean"
          * transaction-type="Container"
          * acknowledge-mode="Auto-acknowledge"
          * destination-type="javax.jms.Queue"
          * subscription-durability="NonDurable"
          *
          * @jboss:destination-jndi-name name="queue/loginAuditQueue"
          **/
          public class LoginAuditMDB
          implements MessageDrivenBean, MessageListener {

          // -------------------------------------------------------------------------
          // Static
          // -------------------------------------------------------------------------

          // -------------------------------------------------------------------------
          // Members
          // -------------------------------------------------------------------------

          private MessageDrivenContext mContext;

          // -------------------------------------------------------------------------
          // Methods
          // -------------------------------------------------------------------------

          /**
          * This method is called by the JMS implementation when a message is
          * ready to be delivered.
          *
          * @param pMessage Message send by JMS
          **/
          public void onMessage( Message pMessage ) {
          Log log = new Log();
          log.setFilepath("/usr/local/jboss-3.0.4_tomcat-4.1.12/logs");
          log.setFilename("test.log");
          log.setLogIdentity("LOGINAUDIT");
          log.setPrefix("ERROR");
          log.setMessage("LoginAuditMDB.onMessage() got message " + pMessage);
          try {log.save();} catch (Exception e) {}
          System.out.println("LoginAuditMDB.onMessage() got message " + pMessage );
          }

          /**
          * Create the Session Bean
          *
          * @throws CreateException
          **/
          public void ejbCreate() {
          System.out.println("ejbCreate() called");
          }

          /**
          * Describes the instance and its content for debugging purpose
          *
          * @return Debugging information about the instance and its content
          **/
          public String toString() {
          return "LoginAuditMDB [ " + " ]";
          }

          // -------------------------------------------------------------------------
          // Framework Callbacks
          // -------------------------------------------------------------------------

          public void setMessageDrivenContext( MessageDrivenContext aContext )
          throws
          EJBException {
          mContext = aContext;
          System.out.println("setMessageDrivenContext called");
          }

          public void ejbRemove() {
          System.out.println("ejbRemove() called");
          }
          }

          • 2. Re: Message Driven Bean in JBoss
            koltar Newbie

            I have found part of the problem looking through the build from ant it is only showing the template test entries in the message-driven bean tags. Where is the ant script writing the META-INF xml files from? I can not seem to find them in the source. How do I get the ant script to accept my new files. The above code shows the xdoclet changes I made but when I build nothing new is coming in the build. I even edited the entry pointing to test/message/** to mytest/message/**.

            Any suggestions? If someone knows about some good documentation that would be cool. Everything is bits and pieces with no complete reference.

            • 3. Re: Message Driven Bean in JBoss
              koltar Newbie

              Anyone ever successfully implemented MDB on JBoss that was not the template? If so what should I use for a resource I'm still stuck...

              • 4. Re: Message Driven Bean in JBoss
                Juha Lindfors Master

                weelll.. where's your code that sends the message?

                • 5. Re: Message Driven Bean in JBoss
                  koltar Newbie

                  2nd Message, I thought that sent the message with the line: queueSender.send(queue, message); Tells what que it goes in and what message to send? Is that not correct?

                  • 6. Re: Message Driven Bean in JBoss
                    Juha Lindfors Master

                    oops, I musta been blind