具有多个代理的JMSTemplate。目的地解析异常

时间:2019-01-14 16:59:14

标签: jms messaging spring-jms jms-topic jmstemplate

我遇到了整日试图解决的问题,但没有成功... 我有一个应用程序试图与外部系统A和外部系统B之间收发消息。A和B是基于WLS的外部系统。

我的应用程序即将发布时-我正在读取所有配置并构建我的应用程序JMSProducer,并在其中注入具有预定义目标名称的JMSTemlate。

这是我的代码:

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;
}

现在场景会发生什么。

我的应用程序已启动并正在运行,具有2个队列的外部系统A和具有1个队列的外部系统B也已启动并正在运行。

  1. 我正在检索相关的,已经初始化的JMSProducer,其中我已经在JMSTemplate中注入了destinationName。
  2. 将消息发送到外部系统A的队列
  3. 再次检索与系统B相关的JMSProducer的下一个实例
  4. 将消息发送到外部系统B的队列
  5. 在此阶段,一切都很好,所有消息都传递到外部系统中的相关队列。
  6. 现在,我再次获得与外部系统A相关的JMSProducer,并尝试将消息发送到其中一个队列。在这个阶段,我遇到了一个问题,抛出了DestinationResolutionException:

在JNDI中找不到目标[topic2.queueName]

javax.naming.NameNotFoundException:尝试查找“ topic2.queueName”时未找到子上下文“ topic2”。已解决“”

这是怎么可能的,我刚刚将消息发送到了具有相同目的地的外部系统A,并且工作正常。为什么在尝试将消息发送到B后向A发送消息时会抛出异常?

顺便说一句,如果在定义目标解析器时尝试将缓存标志更改为true,则可以解决此问题。但是,在这种情况下,我的外部系统将要重新启动时开始出现问题。重新启动后,它也有一些与目标解析有关的异常。

1 个答案:

答案 0 :(得分:0)

已解决。

问题是在两个外部系统中,在WLS中,域名,jms服务器名称和jms模块名称都相同。并且weblogic客户端存储状态,并使用该名称进行映射。

这来自WLS文档

  

互操作的WebLogic Server域具有以下内容   限制:

     

域名必须唯一。

     

WebLogic服务器名称必须唯一,即使它们是两个   不同的域。

     

JMS服务器名称必须唯一,即使它们是两个不同的名称也是如此   域。

     

互操作域可能有特殊的安全注意事项。

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

更改所有上述名称后-问题已解决。

相关问题