1 Reply Latest reply on Jul 20, 2008 5:26 AM by Rafal Scipien

    check if message is in queue

    Rafal Scipien Newbie

      hi all

      My message driven bean can't reciver message and i wont to check where i made mistake in sending or in MDB
      1) i am sending message form stateless bean could be there problem?
      2) i must set this method setMessageListener() could it be constructor?

      ----------------------------------------

      InitialContext ctx = new InitialContext();
      QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
      
      Queue que = (Queue)ctx.lookup("queue/A");
      
      
      QueueConnection connection = factory.createQueueConnection();
      
      
      QueueSession session = connection.createQueueSession(false, javax.jms.QueueSession.AUTO_ACKNOWLEDGE);
      
      MessageProducer producer = session.createProducer(que);
      
      
      MapMessage mapMsg = session.createMapMessage();
      mapMsg.setString("subject", subject);
      mapMsg.setString("content", content);
      mapMsg.setString("mimi", mime);
      mapMsg.setString("mailTo", mailTo);
      
      System.out.println("EJB");
      
      producer.send(mapMsg);
      
      

      --------------------------------------------
      ***********************************
      ***********************************
      -----------------------------------------------
      @MessageDriven(activationConfig =
      {
       @ActivationConfigProperty(propertyName="destinationType",
       propertyValue="javax.jms.Queue"),
       @ActivationConfigProperty(propertyName="destination",
       propertyValue="queue/A")
      })
      public class NotificationJms implements MessageListener {
      
      public NotificationJms() {
      
      try{
      
      System.out.println("JMS KONSTRUKTOR");
      
      InitialContext ctx = new InitialContext();
      QueueConnectionFactory factory =
      (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
      Queue que = (Queue)ctx.lookup("queue/A");
      
      
      QueueSession session = connection.createQueueSession(false, javax.jms.QueueSession.AUTO_ACKNOWLEDGE);
      
      MessageConsumer cons = session.createConsumer(que);
      cons.setMessageListener(this);
      
      connection.start();
      
      
      }catch(NamingException e){} catch (JMSException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
       }
       }
      
      
      
      
      public void onMessage(Message message) {
      
      System.out.println("JMS onMessage METODA");
      
      MapMessage mapMsg = (MapMessage)message;
      try {
      
      
      System.out.println(mapMsg.getStringProperty("subject")+
      mapMsg.getStringProperty("content")+
      mapMsg.getStringProperty("mimi")+
      mapMsg.getStringProperty("mailTo"));
      
      } catch (JMSException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }