JMSTemplate with multiple brokers. Destination resolving exception

被刻印的时光 ゝ 提交于 2019-12-11 17:03:24

问题


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.

  1. I am retrieving relevant, already initialized JMSProducer in which I have already injected JMSTemplate with destinationName.
  2. Sending messages to queues of external system A
  3. Again retrieving next instance of JMSProducer relevant for system B
  4. Sending messages to queue of external system B
  5. At this stage everything is good, all messages delivered to relevant queues in external systems.
  6. 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.


回答1:


Solved.

Problem was that in both external systems, in WLS - domain name, jms server name, and jms module name were the same. And weblogic client stores state, map with this names.

This is from WLS documentation

Interoperating WebLogic Server domains have the following restrictions:

Domain names must be unique.

WebLogic server names must be unique, even if they are in two different domains.

JMS server names must be unique, even if they are in two different domains.

Interoperating domains may have special Security considerations.

https://docs.oracle.com/cd/E28280_01/web.1111/e13738/best_practice.htm#JMSAD635

After changing all above mentioned names - problem was solved.



来源:https://stackoverflow.com/questions/54185975/jmstemplate-with-multiple-brokers-destination-resolving-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!