-
1. Re: Connecting to JBoss server(s) through VIP
kparasam Sep 29, 2013 9:50 AM (in response to kparasam)On further testing, its not just with VIP, even if I try an actual IP, the initialContext.lookup("jms/RemoteConnectionFactory") fails to get connection object after restart of JBoss server. Please let me know if anyone has experienced a similar problem or a possible solution for this. Thanks.
Here's my code:
public JMSSender(String message) throws JMSException, NamingException, Exception {
jmsHostIP = "10.0.40.100:4447";
connectToHost = "remote://"+jmsHostIP;
appUser = "user";
appPwd = "pwd";
destinationQueue = "jms/queue/test";
envProp.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
envProp.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
envProp.setProperty(Context.PROVIDER_URL, connectToHost);
envProp.put(Context.SECURITY_PRINCIPAL, appUser);
envProp.put(Context.SECURITY_CREDENTIALS, appPwd);
InitialContext initialContext = new InitialContext(envProp);
Object conObject = initialContext.lookup("jms/RemoteConnectionFactory");
QueueConnectionFactory qcf = (QueueConnectionFactory) conObject;
queCon = qcf.createQueueConnection(appUser, appPwd); // Get the connection from the desired ConnectionFactory with credentials
queue = (Queue) initialContext.lookup(destinationQueue);
queCon.start();
session = queCon.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
sender = session.createSender(queue);
sender.send(message);
}
main {
for(int i=0;i<1000;i++) {
new JMSSender("message");
}
}
-
2. Re: Connecting to JBoss server(s) through VIP
kparasam Sep 30, 2013 12:15 PM (in response to kparasam)I think found the answer. The initialContext has to be closed after it is used (not to wait the garbage collector to free it up). Now, there's no problem reconnecting to JBoss server after it restarts.