I have problem which I am trying solve all day, without success... I have an application which trying to send/receive messages to/from external system A and external system B. A and B it is WLS based external systems.
While my application is coming up - i am reading all configurations and building my applicational JMSProducer and injecting JMSTemlate with predefined destination name in it.
Here is my code:
private JMSProducer initProducer(Conf conf) {
DestinationResolver destinationResolver = getDestinationResolver(conf);
ConnectionFactory connectionFactory = getConnectionFactory();
String destinationName = conf.getDestinationName();
JmsTemplate jmsTemplate = new JmsTemplate();
jmsTemplate.setConnectionFactory(connectionFactory);
jmsTemplate.setDestinationResolver(destinationResolver);
jmsTemplate.setDefaultDestinationName(destinationName);
return new JMSProducer(jmsTemplate);
}
public DestinationResolver getDestinationResolver(Conf conf) {
JndiDestinationResolver destinationResolver = new JndiDestinationResolver();
destinationResolver.setCache(false);
destinationResolver.setJndiTemplate(getJNDITemplate(conf));
return destinationResolver;
}
private JndiTemplate getJNDITemplate(Conf conf) {
JndiTemplate jndiTemplate = new JndiTemplate();
Properties properties = new Properties();
String connectionFactoryClassName = externalSystemConf.getConnectionParam().getConnectionFactory();
properties.setProperty("java.naming.factory.initial", connectionFactoryClassName);
properties.setProperty("java.naming.provider.url", getProviderURL(conf.getConnectionParam()));
jndiTemplate.setEnvironment(properties);
return jndiTemplate;
}
Now scenario what happens.
My app is up and running, external system A with 2 queues and external system B with 1 queue also is up and running.
- I am retrieving relevant, already initialized JMSProducer in which I have already injected JMSTemplate with destinationName.
- Sending messages to queues of external system A
- Again retrieving next instance of JMSProducer relevant for system B
- Sending messages to queue of external system B
- At this stage everything is good, all messages delivered to relevant queues in external systems.
- Now I am getting again JMSProducer which relevant for external system A, and trying to send messages to one of the queues. And in this stage I have a problem, DestinationResolutionException is thrown:
Destination [topic2.queueName] not found in JNDI
javax.naming.NameNotFoundException: While trying to lookup 'topic2.queueName' didn't find subcontext 'topic2'. Resolved ""
How it is possible, I have just sent messages to external system A with the same destination and it worked fine. Why it throwing exception when I am sending message to A after I tried to sent it to B?
By the way, If I will try to change cache flag to true when defining destination resolver, it is solving this problem. However in this case I starting to have problem when my external system is going to be restarted. After restart it also have some exception related to destination resolving.