title: EJB3.0 How to use MDB
body: <p>Hey, I am new to coding in j2ee. My question is regarding MDB.
  I have already set up my weblogic 11g server. and the queue has been set up. </p>
  
  <p>I have written the client code which is a java se client that sends a msg to the queue.</p>
  
  <pre><code>import java.util.Hashtable;
  import java.util.Properties;
  
  import javax.jms.Queue;
  import javax.jms.QueueConnection;
  import javax.jms.QueueConnectionFactory;
  import javax.jms.QueueSender;
  import javax.jms.QueueSession;
  import javax.jms.TextMessage;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  
  public class MyMDBClient {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
           QueueConnection cnn = null;
              QueueSender sender = null;
              QueueSession session = null;
              InitialContext ctx;
              Hashtable ht = new Hashtable();
  
              try {
                  ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
                  ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
  
                  ctx = new InitialContext(ht);
                  Queue queue = (Queue) ctx.lookup("jms/testQueue");
                  QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("jms/connectionFactory");
                  cnn = factory.createQueueConnection();
                  session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
                  TextMessage msg = session.createTextMessage();
                  msg.setText("helloworld");
                  sender = session.createSender(queue);
                  sender.send(msg);
  
                  System.out.println("Message sent successfully to remote queue.");
                  session.close(); // this is important.
              } catch (Exception e) {
                  e.printStackTrace();
              }
      }
  }
  </code></pre>
  
  <p>I can see the message on the queue on my administrative console of weblogic.</p>
  
  <p>however, my mdb on the server end is not invoked. </p>
  
  <p>Can anyone tell me what is wrong. I will prefer the solution to be in java annotations. thank you all for reading this. </p>
  
  <p>here is my server code:</p>
  
  <pre><code>/**
   * import
   *
   */
  
  import javax.jms.JMSException;
  import javax.jms.Message;
  import javax.jms.MessageListener;
  import javax.jms.TextMessage;
  
  import weblogic.ejbgen.*;
  
  
  /**
   * Message-Driven Bean implementation class for: MyMDB
   *
   */
  @MessageDriven(ejbName="mdb", destinationType="javax.jms.queue",destinationJndiName="jms/testQueue"  )
  public class mdb implements MessageListener {
  
      /**
       * Default constructor. 
       */
      public mdb() {
      }
  
      /**
       * @see MessageListener#onMessage(Message)
       */
      public void onMessage(Message message) {
          TextMessage tmsg = null;
          tmsg = (TextMessage) message; 
  
          System.out.println("----------------");
          System.out.println("Received message : ");        
          try {
              System.out.println(tmsg.getText());
          } catch (JMSException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }   
  
          System.out.println("----------------");        
      }
  }
  </code></pre>