1 Reply Latest reply on Mar 10, 2004 5:28 PM by Frank Griffin

    Testing a MDB

    tonig Newbie

      Hello,

      i've written now my first MDB and Client. The MDB is running on a JBoss (i can choose it to start, create, remove, etc. it).

      My Client seems to work right, too. But how can i see that the MDB is workin right? I have in the onMessage a simple output Message:

      System.err.println("### in SimpleMessageBean.ejbOnMessage() ###");
      or
      System.out.println("### In SimpleMessageBean.OnMessage()");
      


      Both outputs dont work, i have the same outputs on the other MDB Methods, but my JBoss console doesnt print anything of that.

      So how can i be sure that the MDB is working right? Did i make a mistake and the output should be correct? Do i have to create and start the MDB before i can test i?

      Thank u 4 ur help

        • 1. Re: Testing a MDB
          Frank Griffin Novice

          You probably noticed that there is nothing in the <message-driven> section of the ejb-jar that identifies the Queue being serviced by your MDB.

          WARNING: The XML below is invalid; it has extra spaces in some labels, because otherwise this posting service swallows them

          The way to do this is server-(i.e. JBoss-)specific. You need two things:

          1) you need a file called jbossmq-something-service.xml containing something like:

          < server>
          < mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=yourMDBname">
          < depends optional-attribute-name="DestinationManager">
          jboss.mq:service=DestinationManager
          </ depends>
          </ mbean>
          </ server>

          This goes into your "deploy" directory as a standalone, and basically tells JBoss that your MDB needs messaging services.

          2) You need entries in a jboss.xml file (this goes in the META-INF directory of your EJB jar file, same place as ejb-jar.xml):

          < jboss>
          < secure>false</ secure>
          <resource-managers>
          <!--
          For JMS, we need a resource manager for each Connection Factory
          and each queue or topic.

          The Connection Factories should point to java:/JmsXA.
          -->
          <resource-manager>
          <res-name>QueueFactory</res-name>
          <res-jndi-name>java:/JmsXA</res-jndi-name>
          </resource-manager>
          <resource-manager>
          <res-name>yourMDBName</res-name>
          <res-jndi-name>queue/yourQueueName</res-jndi-name>
          </resource-manager>
          </resource-managers>
          </ jboss>

          This tells JBoss to create a Queue named "yourQueueName" which it will show to the outside world with a JNDI name of queue/yourQueueName, and associate it with your MDB so that when message arrive it will call your bean's onMessage().

          This should do it for an MDB referenced by a client, although you may have to play with whatever needs to precede queue/ in the JNDI name. It's a little more complicated if the client is a session EJB, but I'll leave that out for now.

          You may have problems with this, because the only way I've done it is with a session EJB as the client, and I may have left something out when I pruned stuff out of my descriptors, but give it a try.

          A good reference for this stuff is the JBoss companion workbook for the O'Reilly "Enterprise JavaBeans" book. I thikn this is part of the JBoss docs, or maybe you get it from the O'Reilly site. It has all of the JBoss-specific stuff you need to get the examples in the book to work, along with code.