0 Replies Latest reply on Aug 12, 2004 8:55 AM by jkario_78

    Sending JMS messages from MDB

    jkario_78 Newbie

      Hi,

      I'm using an MDB as a "server" for my own QueueRequestor (added timeout). Response messages are sent back through temporary queues. Now everything works perfectly as long as I initialize JMS QueueConnection and QueueSession (the ones that use to send response messages back to the requestor) in the ejbCreate method of the MDB and use the same connection and session for all requests that the MDB receives.

      // ejbCreate
      QueueConnectionFactory connectionFactory = (QueueConnectionFactory) ctx.lookup("java:comp/env/jms/ConnectionFactory");
      queueConnection = connectionFactory.createQueueConnection();
      queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      queueConnection.start();


      // send response message method
      QueueSender responseQueueSender = queueSession.createSender(queue);
      ObjectMessage objectMessage = queueSession.createObjectMessage(msg);
      objectMessage.setJMSCorrelationID(correlationID);
      responseQueueSender.send(queue, objectMessage);
      



      However if I create a new connection and session in the sendResponse method things don't work. The reply message is sent ok to the temporary queue but the consumer (QueueRequestor) never receives it. I've tried switching between UIL2, OIL2 and JVM connection factories.

      The reason I'm asking this is because a lot of the example on the net use the latter approach and create a new connection and session for each response message (create connection, create session, create sender, send message, close connection, move on).

      Is there any best practices on this subject (how to send JMS messages from within an MDB / where to create the JMS stuff)? Why is the latter approach not working for me?

      The same best practices question applies to sessions beans that send JMS messages or consumes them synchronously. Where would I create the JMS stuff (ejbCreate or some helper method that is called when I need to do JMS).

      Using JBoss 3.2.3.

      * Janne