0 Replies Latest reply on Dec 5, 2005 12:43 PM by Holger Ahl

    (re-)connect at ProducerManager results in IllegalStateExcep

    Holger Ahl Newbie


      I'm trying to call a MDB with ProducerManager extension. When I open a JMS connection by calling connect method at ProducerManager object, close this connection and try to open a new one by calling connect again, I get a

      javax.jms.IllegalStateException: The session is closed

      as soon as I try to call a MDB method.

      This is the client trying to re-connect to JMS queue:

       MDBTestInterface bean = null;
       ProducerManager manager = null;
       try {
       Properties props = new Properties();
       props.put(InitialContext.PROVIDER_URL, "jnp://");
       InitialContext ctx = new InitialContext(props);
       bean = (MDBTestInterface) ctx.lookup(MDBTestInterface.class.getName());
       ProducerObject po = (ProducerObject) bean;
       manager = po.getProducerManager();
       } catch (Exception e) {
       manager.connect(); // internally create a JMS connection
       try {
       } finally {
       manager.close(); // clean up the JMS connection
       manager.connect(); // internally (re-)create a JMS connection
       try {
       bean.doWork("Hello2"); // produces IllegalStateException
       } finally {
       manager.close(); // clean up the JMS connection

      This is the MDB interface:

      @MessageProperties(delivery=DeliveryMode.NON_PERSISTENT, timeToLive=10000, priority=1)
      public interface MDBTestInterface {
       public void doWork (String text);

      This is the consumer:

      @Consumer(activateConfig =
      public class MDBListener implements MDBTestInterface {
       private static final Logger log = Logger.getLogger(MDBListener.class);
       public void doWork(String text) {

      This is only a stupid example (closing and connectin again) but is needed for the case the state (if connected or not) is unknown. So for each MDB call in a method the connection shall be established and closed finally.

      Does anybody know if connecting after closing the connection is not allowed? Or is there any other way to (re-)connect to a JMS queue with the same MDB object retrieved from JNDI lookup?