5 Replies Latest reply on Sep 30, 2004 4:49 PM by AAAAA BBBBB

    Connecting from MDB

    Jerry Payne Newbie

      I have an app that is being deployed using Ant. It includes a servlet that is able to pass a message to the "queue/testQueue". The problem is that the bean does not read the messages. I have an ejb-jar.xml file created that defines the destination-type as javax.jms.Queue for the Message Driven Bean. I have created a jboss.xml file that maps the Message Driven Bean to the jndi name "queue/testQueue".

      My question is this: How does the Message Driven Bean know which connection factory to use?

      I deploy the bean out just fine. I am able to send messages to the queue, but my bean does read them.

      Thanks for any help.

        • 1. Re: Connecting from MDB
          Oguz Kologlu Newbie


          Your mappings are probably not correct. By default jboss will create a queue for anymessage driven beans that are not attached to a queue.

          Check http://localhost:8080/jmx-console to see what queues you have.

          Post your config files if you don't have any luck

          • 2. Re: Connecting from MDB
            Jerry Payne Newbie

            Here is the ejb-jar.xml and the jboss.xml. I am getting a message that says I cannot find "queue/MyMessageBean". In the configuration I am trying to point the Message Bean to "queue/TestQueue".


            Message Driven Bean EJB



            • 3. Re: Connecting from MDB
              AAAAA BBBBB Newbie

              The MDB does not need to know the connection factory. You just need to link the MDB with the queue, which you are doing correctly in the jboss.xml

              Maybe the problem is in your servlet code where you are sending the messages.

              • 4. Re: Connecting from MDB
                Jerry Payne Newbie

                I have checked the servlet code and it is working. I wrote a class that uses QueueBrowser to check the messages. All of the messages I sent are on the Queue.

                Here is the code for the servlet:

                package com.hott.servlets;
                import javax.jms.*;
                import javax.naming.*;
                import javax.servlet.http.*;
                import javax.servlet.*;
                import java.io.*;
                import java.util.Properties;
                 * sends messages to a JMS queue that will be processed by a Message Driven Bean
                public class MyMessageServlet extends HttpServlet {
                 QueueConnection queueConnection = null;
                 QueueSession queueSession = null;
                 Queue queue = null;
                 QueueSender queueSender = null;
                 TextMessage message = null;
                 public void init() {
                 Properties env = new Properties();
                 try {
                 Context jndiContext = new InitialContext(env);
                 QueueConnectionFactory queueConnectionFactory =
                 (QueueConnectionFactory) jndiContext.lookup("ConnectionFactory");
                 queue = (Queue) jndiContext.lookup("queue/testQueue");
                 queueConnection = queueConnectionFactory.createQueueConnection();
                 queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                 queueSender = queueSession.createSender(queue);
                 message = queueSession.createTextMessage();
                 } catch (JMSException e) {
                 } catch (NamingException ne){
                 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
                 String text = req.getParameter("message");
                 PrintWriter out = resp.getWriter();
                 out.println("<html><head><title>Send Results</title></head><body>");
                 try {
                 out.println("Sending message: <b>" + message.getText()+"</b><br>");
                 out.println("Your message has been sent successfully.");
                 } catch (JMSException e) {
                 out.println("Your message was not sent.");
                 } finally {
                 public void destroy(){
                 if (queueConnection != null) {
                 try {
                 } catch (JMSException e) {}

                • 5. Re: Connecting from MDB
                  AAAAA BBBBB Newbie


                  I am not sure about this, but have you changed the JNDI name for the connection factory. The default name is "JmsXA"