-
1. Re: Connecting from MDB
oz_ko Sep 29, 2004 11:16 PM (in response to jerryp64)Jerry,
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
HTH
Oz -
2. Re: Connecting from MDB
jerryp64 Sep 30, 2004 9:49 AM (in response to jerryp64)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".
ejb-jar.xml<ejb-jar> <description> Message Driven Bean EJB </description> <enterprise-beans> <message-driven> <display-name>MyMessageBean</display-name> <ejb-name>MyMessageBean</ejb-name> <ejb-class>com.hott.ejb.MyMessageBean</ejb-class> <transaction-type>Container</transaction-type> <acknowledge-mode>Auto-acknowledge</acknowledge-mode> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> </message-driven-destination> </message-driven> </enterprise-beans> </ejb-jar>
jboss.xml<jboss> <enterprise-beans> <message-driven> <ejb-name>MyMessageBean</ejb-name> <destination-jndi-name>queue/testQueue</destination-jndi-name> </message-driven> </enterprise-beans> </jboss>
-
3. Re: Connecting from MDB
kishoratigre Sep 30, 2004 4:12 PM (in response to jerryp64)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
jerryp64 Sep 30, 2004 4:22 PM (in response to jerryp64)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(); env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); env.put("java.naming.provider.url","localhost:1099"); env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); 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) { e.printStackTrace(); } catch (NamingException ne){ ne.printStackTrace(); } } public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String text = req.getParameter("message"); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println("<html><head><title>Send Results</title></head><body>"); try { message.setText(text); out.println("Sending message: <b>" + message.getText()+"</b><br>"); queueSender.send(message); out.println("Your message has been sent successfully."); } catch (JMSException e) { out.println("Your message was not sent."); } finally { out.println("</body></html>"); } } public void destroy(){ if (queueConnection != null) { try { queueConnection.close(); } catch (JMSException e) {} } } }
-
5. Re: Connecting from MDB
kishoratigre Sep 30, 2004 4:49 PM (in response to jerryp64)jndiContext.lookup("ConnectionFactory");
I am not sure about this, but have you changed the JNDI name for the connection factory. The default name is "JmsXA"