2 Replies Latest reply on Aug 30, 2002 12:35 PM by chumps

    MDB doesn't receive message

    chumps

      Can somebody help?

      I'm trying to have as servlet send a message to a MDB. This seems like a simple thing, but I can't get it to work.

      Here is the MDB code:

      public void onMessage(Message message) {
      try {
      System.out.println("treating message");
      TextMessage textMsg = (TextMessage) message;
      String collectionUri = textMsg.getText();
      //Directory dmsCollection = (Directory) dms.getDmsObject(collectionUri);
      //handleCollection(dmsCollection);
      //handleLegislations(dmsCollection);
      System.out.println("sending response");
      sendResponse(message,"ok");
      System.out.println("response sent");
      }
      catch (Exception e) {
      throw new EJBException(e);
      }
      }

      here is the ejb-jar.xml

      <ejb-jar>
      <display-name>CanliiDBJAR</display-name>
      <enterprise-beans>
      <message-driven>
      <display-name>DmsSynchronizationProcessEJB</display-name>
      <ejb-name>DmsSynchronizationProcessEJB</ejb-name>
      <ejb-class>org.canlii.ejb.DmsSynchronizationProcessEJB</ejb-class>
      <transaction-type>Container</transaction-type>
      <message-driven-destination>
      <destination-type>javax.jms.Topic</destination-type>
      <subscription-durability>NonDurable</subscription-durability>
      </message-driven-destination>
      <security-identity>

      <run-as>

      <role-name>guest</role-name>
      </run-as>
      </security-identity>
      </message-driven>
      </enterprise-beans>
      </ejb-jar>

      the jboss.xml

      <enterprise-beans>
      <message-driven>
      <ejb-name>DmsSynchronizationProcessEJB</ejb-name>
      <destination-jndi-name>topic/dmsTopic</destination-jndi-name>
      </message-driven>
      </enterprise-beans>


      when I deploy it I notice the following warning:
      WARNING element resource-env-ref not handled in WebApplicationContext[/dmstest, DmsSyncWAR]

      When I run the following code the bean isn't invoked:
      Context jndiContext = new InitialContext();
      TopicConnectionFactory topicFactory = (TopicConnectionFactory)
      jndiContext.lookup("java:comp/env/jms/TopicFactory");
      Topic dmsTopic = (Topic)
      jndiContext.lookup("java:comp/env/jms/Topic");
      TopicConnection connection = topicFactory.createTopicConnection();
      TopicSession session = connection.createTopicSession(true,0);
      TopicPublisher publisher = session.createPublisher(dmsTopic);
      TextMessage msg = session.createTextMessage("/collections/test");
      QueueConnectionFactory queueFactory = (QueueConnectionFactory)
      jndiContext.lookup("java:comp/env/jms/QueueFactory");
      QueueConnection queueConnection = queueFactory.createQueueConnection();
      QueueSession queueSession = queueConnection.createQueueSession(true,0);
      Queue replyQueue = queueSession.createTemporaryQueue();
      msg.setJMSReplyTo(replyQueue);
      QueueReceiver receiver = queueSession.createReceiver(replyQueue);
      System.out.println("sending message");
      publisher.publish(msg);
      queueConnection.start();
      System.out.println("receiving message");
      TextMessage response = (TextMessage) receiver.receive();
      System.out.println("got message");

      here is the web.xml file:
      <resource-env-ref>
      <resource-env-ref-name>jms/Topic</resource-env-ref-name>
      <resource-env-ref-type>javax.jms.Topic</resource-env-ref-type>
      </resource-env-ref>
      <resource-ref>
      <res-ref-name>jms/TopicFactory</res-ref-name>
      <res-type>javax.jms.TopicConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      <resource-ref>
      <res-ref-name>jms/QueueFactory</res-ref-name>
      <res-type>javax.jms.QueueConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      and the jboss-web.xml

      <jboss-web>
      <resource-env-ref>
      <resource-env-ref-name>jms/Topic</resource-env-ref-name>
      <jndi-name>topic/dmsTopic</jndi-name>
      </resource-env-ref>
      <resource-ref>
      <res-ref-name>jms/TopicFactory</res-ref-name>
      <jndi-name>ConnectionFactory</jndi-name>
      </resource-ref>
      <resource-ref>
      <res-ref-name>jms/QueueFactory</res-ref-name>
      <jndi-name>ConnectionFactory</jndi-name>
      </resource-ref>
      </jboss-web>

      Am I doing something wrong? Thanks,

        • 1. Re: MDB doesn't receive message
          chumps

          actually, I get the warning when I deploy the servlet, not the MDB as my previous message suggests.

          • 2. Re: MDB doesn't receive message
            chumps

            I've realised what I was doing wrong. The publisher initiated a transacted session but nver commit the transactions, as a result, messages were never eally sent and I ended up in a deadlock. The JMS tutorial warns us about such things, I should pay more attention... So The trick was to replace the line
            QueueSession queueSession = queueConnection.createQueueSession(true,0);
            by
            QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOLEDGE);

            One thing still puzzles me though, the JMS tutorial advises against this when in comes to EJBs beacuse the container is suppose to take over the transaction managment but I'm still trying to get my bean working with a tansacted session as the tutorial suggests. Anyon knows if this is a problem in JBoss ?

            Thanks