JMS client unable to reconnect after restarting JBoss EAP 6
Issue
I'm getting an error when trying to create a new connection to the queue after the reconnect attempts have failed, but after I've restarted the queue.
First I get an error saying:
Session was closed
Then, if I try to create a new connection, I get:
org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is org.jboss.remoting3.NotOpenException: Writes closed]
This is what I'm doing:
producer.send("Message");
The auto-reconnect works, but I want to be able to return a message to the user if the message can not be sent, so I don't want to use infinite retry attempts. So I want to error out of the send and manually retry to reconnect later (create a new initialcontext and a new connection.)
Here is some sample code of how I'm doing the send. The problem happens when JBoss EAP restarts and the JMS client is not configured to automatically reconnect.
public void connect() throws Exception {
try {
if( needsReconnect ) {
// Create the connection and initial context
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "factory");
props.put(Context.PROVIDER_URL, "url");
props.put(Context.SECURITY_PRINCIPAL, "securityPrincipal");
props.put(Context.SECURITY_CREDENTIALS, "securityCredentials");
InitialContext initialContext = new InitialContext(props);
ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("ConnectionFactory");
connection = connectionFactory.createConnection();
session = connection.createSession(false, HornetQJMSConstants.INDIVIDUAL_ACKNOWLEDGE);
connection.start();
Topic topic = session.createTopic(topicName);
producer = session.createProducer(topic);
needsReconnect = false;
return;
}
} catch( Exception e ) {
}
needsReconnect = true;
}
public void send() {
if( needsReconnect )
connect();
try {
producer.send(message);
} catch( Exception e ) {
needsReconnect = true;
}
}
Environment
- Red Hat JBoss Enterprise Application Platform
- 6.0
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
