I have an application deployed on tomcat which tries to work with remote JMS queues of external system A and B. External systems are deployed on Weblogic, so in order to communicate with them I am providing also wlthint3client.
That is my code:
public void myMethod () {
// Sending message to first ext system
// jndi queue name - topic1.extsys1.tosend.messages
magicMethod(Params of External system A);
// Sending message to second ext system
// jndi queue name - topic1.extsys2.tosend.messages
magicMethod(Params of External system B);
// AGAIN Sending message to FIRST ext system
// jndi queue name - topic1.extsys1.tosend.messages
magicMethod(Params of External system A);
}
private void magicMethod(String factoryName, String url, String connectionFactoryJNDI, String queueName) throws Exception {
javax.jms.QueueConnectionFactory queueConnectionFactory = null;
javax.jms.QueueSession queueSession = null;
javax.jms.Queue queue = null;
javax.jms.QueueSender queueSender = null;
javax.jms.QueueConnection queueConnection = null;
InitialContext ic = null;
try {
final Properties initialContextProperties = new Properties();
initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY, factoryName);
initialContextProperties.put(Context.PROVIDER_URL, url);
initialContextProperties.put(Context.SECURITY_PRINCIPAL, "");
initialContextProperties.put(Context.SECURITY_CREDENTIALS, "");
ic = new InitialContext(initialContextProperties);
queueConnectionFactory = (QueueConnectionFactory) ic.lookup(connectionFactoryJNDI);
queue = (javax.jms.Queue) ic.lookup(queueName);
} catch (NamingException e) {
System.out.println("Could not create JNDI context: " + e.getMessage());
}
try {
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
ObjectMessage objectMessage = queueSession.createObjectMessage("message");
queueSender.send(objectMessage);
} catch (JMSException e) {
System.out.println(e.getMessage());
} finally {
ic.close();
queueConnection.close();
queueSession.close();
queueSender.close();
}
}
When I am sending message to ext system A - everything is ok. Sending message to ext system B - still message is sent, everything is fine.
When Trying AGAIN send message to ext system A - I am failing.
Could not create JNDI context: While trying to lookup 'topic1.extsys1.tosend.messages' didn't find subcontext 'extsys1'. Resolved 'topic1'
So I am trying understand:
- What I did wrong?
- Why it is not sending messages to system A, after I succeeded to send to ext system B?
- Do these internal java objects (InitialContext, JNDI objects, etc...) having some state somewhere? Maybe I need clean something?
- I feel like something messed up with JNDI names...
- Maybe I need to change names? (Actually I have already tried to have totally different jndi queue names but it had no effect, however I didn't restart external systems, don't sure if it is requeired).
Any Ideas, directions to move??? Please
ps - jms server and jms module has the same name in both A and B external systems. Provider URL's are - ext1.xxx.corp.com
, ext2.xxx.corp.com