6 Replies Latest reply on Oct 29, 2009 10:24 AM by komet_1978

    EJB3 MDB Annotations not working.


      I attempting to deploy my MDB as follows.

      import java.util.logging.Logger;

      import javax.ejb.MessageDriven;
      import javax.ejb.ActivationConfigProperty;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      /*
      * The MDB
      */

      @MessageDriven(activationConfig = {
      @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
      @ActivationConfigProperty(propertyName="destination", propertyValue="queue/orderQueue")
      })
      public classOrderMDB implements MessageListener {

      public void onMessage(Message recvMsg){

      log.info("----------------");
      log.info("Received message");
      log.info("----------------");
      }

      private static Logger log = Logger.getLogger(OrderMDB.class.getName());

      }

      /*
      * The client
      */

      public void placeOrderUsing(Order anOrder){

      /*
      * persist and log this transaction,order
      */
      try {
      QueueConnection cnn = null;
      QueueSender sender = null;
      QueueSession session = null;
      InitialContext ctx = new InitialContext();
      log.info("obtained initial context");
      javax.jms.Queue queue = (Queue) ctx.lookup("queue/orderQueue");
      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
      cnn = factory.createQueueConnection();
      session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);


      ObjectMessage msg = session.createObjectMessage();

      msg.setObject(anOrder);

      sender = session.createSender(queue);
      sender.send(msg);


      log.info("message sent to orderQueue");
      }
      catch(Exception ex1){
      ex1.printStackTrace();
      }


      }

      I receive the following stack trace indicating that the name orderQueue is not bound.


      javax.naming.NameNotFoundException: orderQueue not bound
      06:57:42,804 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
      06:57:42,804 ERROR [STDERR] at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
      06:57:42,804 ERROR [STDERR] at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
      06:57:42,804 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
      06:57:42,804 ERROR [STDERR] at org.jnp.server.NamingServer.lookup(NamingServer.java:399)
      06:57:42,805 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
      06:57:42,805 ERROR [STDERR] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
      06:57:42,805 ERROR [STDERR] at javax.naming.InitialContext.lookup(InitialContext.java:392)


      What am I doing wrong.

      Thanks in advance.

        • 1. Re: EJB3 MDB Annotations not working.
          komet_1978

          1) You must define a dependency to your queue to make sure that your mdbean is activated after the queue has been deployed:

          @org.jboss.ejb3.annotation.Depends(value = "jboss.messaging.destination:service=Queue,name=orderQueue")
          public classOrderMDB ...


          2) You must define your queue. There are several ways to achieve that. One is to define it in destinations-service.xml file which is placed in the jboss_home/server/<your config>/deploy/messaging folder.

          There you can find two default queues named DLQ and ExpiryQueue which are defined by mbeans. Add mbean for your queue.

          Look at the jboss wiki how to define queues in jboss 5.



          • 2. Re: EJB3 MDB Annotations not working.


            Thanks. I defined the queue in messaging/destinations. I no longer receive the exceptions,
            and the message is being sent. However. I notice in my startup log that the OrderServiceMDB is not being deployed.

            There must be something else going on here.

            I'm using JB 5.1.0GA
            OS: Ubuntu Linux 8.0.4


            Thanks again.

            • 3. Re: EJB3 MDB Annotations not working.
              komet_1978

               

              "thenewmexican" wrote:

              Thanks. I defined the queue in messaging/destinations.


              Did you add the @Depends annotation to your mdb?

              • 4. Re: EJB3 MDB Annotations not working.


                Yes. The MDB now looks like this:

                @org.jboss.ejb3.annotation.Depends(value = "jboss.messaging.destination:service=Queue,name=OrderQueue")
                @MessageDriven(activationConfig = {
                @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
                @ActivationConfigProperty(propertyName="destination", propertyValue="queue/orderQueue")
                })
                public class OrderMDB implements MessageListener{

                public void onMessage(Message recvMsg){

                log.info("----------------");
                log.info("Received message");
                log.info("----------------");
                }

                private static Logger log = Logger.getLogger(OrderMDB.class.getName());

                }

                //: The destinations-service.xml entry looks like this:

                <mbean code="org.jboss.jms.server.destination.QueueService"
                name="jboss.messaging.destination:service=Queue,name=OrderQueue"
                xmbean-dd="xmdesc/Queue-xmbean.xml">
                <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer
                jboss.messaging:service=PostOffice
                queue/orderQueue
                10000
                5

                • 5. Re: EJB3 MDB Annotations not working.
                  komet_1978

                   

                  "thenewmexican" wrote:

                  Yes. The MDB now looks like this:

                  @org.jboss.ejb3.annotation.Depends(value = "jboss.messaging.destination:service=Queue,name=OrderQueue")


                  That's the mistake: the name of your queue is "orderQueue" and not "OrderQueue".



                  • 6. Re: EJB3 MDB Annotations not working.
                    komet_1978

                     

                    "komet_1978" wrote:
                    "thenewmexican" wrote:

                    Yes. The MDB now looks like this:

                    @org.jboss.ejb3.annotation.Depends(value = "jboss.messaging.destination:service=Queue,name=OrderQueue")


                    That's the mistake: the name of your queue is "orderQueue" and not "OrderQueue".



                    But you named your Queue in the destination service "OrderQueue", so change the property value of the destination to "queue/OrderQueue" then.