(re-)connect at ProducerManager results in IllegalStateExcep
hahl Dec 5, 2005 12:43 PMHi,
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.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext ctx = new InitialContext(props);
bean = (MDBTestInterface) ctx.lookup(MDBTestInterface.class.getName());
ProducerObject po = (ProducerObject) bean;
manager = po.getProducerManager();
} catch (Exception e) {
e.printStackTrace();
}
manager.connect(); // internally create a JMS connection
try {
bean.doWork("Hello");
} 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:
@Producer
@MessageProperties(delivery=DeliveryMode.NON_PERSISTENT, timeToLive=10000, priority=1)
public interface MDBTestInterface {
public void doWork (String text);
}
This is the consumer:
@Consumer(activateConfig =
{
@ActivationConfigProperty(propertyName="destinationType",
propertyValue="javax.jms.Queue"),
@ActivationConfigProperty(propertyName="destination",
propertyValue="queue/mdbjobs")
})
public class MDBListener implements MDBTestInterface {
private static final Logger log = Logger.getLogger(MDBListener.class);
public void doWork(String text) {
log.info(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?
Thanks.
Holger