尝试向 weblogic 上的队列发送消息

问题描述 投票:0回答:2

我有一个部署在 WebLogic 服务器上的 Spring Boot 应用程序,在该服务器上定义了一个 JmsModule,我需要用它来发送消息。

我的发送类如下:

@Component
public class JmsMessageSender {
    @Value("${spring.jms.queue}")
    private String jmsQueue;

    public JmsMessageSender(ConnectionFactory connectionFactory) {
        this.jmsTemplate = new JmsTemplate(connectionFactory);
    }

    public void send(Message message) {
        jmsTemplate.convertAndSend(jmsQueue, message.getBody(), mess -> {
            log.info("setting standard JMS headers before sending");
            mess.setJMSMessageID(determineMessageId(message));
            return mess;
        });
    }
...

队列有一个 JNDI 名称,并通过 spring 属性检索,它的定义为:

spring:
  jms:
    jndi-name: jms/ConnectionFactory
    queue: jms/ProcessEventQueue

启动应用程序时,我在日志中没有看到任何错误,但是当我尝试访问这段代码时,会显示以下错误:

2022-06-30T10:22:20,072 [ERROR] org.springframework.boot.web.servlet.support.ErrorPageFilter ([ACTIVE] ExecuteThread: '19' for queue: 'weblogic.kernel.Default (self-tuning)') - Forwarding to error page from request [/ha] due to exception [Uncategorized exception occurred during JMS processing; nested exception is weblogic.jms.common.JMSException: [JMSExceptions:045103]While trying to find a topic or a queue, the specific JMS server requested could not be found. The linked exception may contain more information about the reason for failure.]
org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is weblogic.jms.common.JMSException: [JMSExceptions:045103]While trying to find a topic or a queue, the specific JMS server requested could not be found. The linked exception may contain more information about the reason for failure.
    at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:311) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:691) ~[spring-jms-5.3.20.jar:5.3.20]
...
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'weblogic.jms.backend.jms'. Resolved 'weblogic.jms.backend'
    at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1292) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:354) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:227) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:214) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.ServerNamingNode.lookup(ServerNamingNode.java:532) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:228) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.ServerNamingNode.lookup(ServerNamingNode.java:532) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:228) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.ServerNamingNode.lookup(ServerNamingNode.java:532) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:228) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.ServerNamingNode.lookup(ServerNamingNode.java:532) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.RootNamingNode.lookup(RootNamingNode.java:84) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:307) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:435) ~[com.oracle.weblogic.jndi.jar:12.2.1.4]
    at weblogic.jms.frontend.FEManager.destinationCreate(FEManager.java:300) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.jms.frontend.FEManager.invoke(FEManager.java:588) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.messaging.dispatcher.Request.wrappedFiniteStateMachine(Request.java:1015) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.messaging.dispatcher.DispatcherImpl.syncRequest(DispatcherImpl.java:256) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.messaging.dispatcher.DispatcherImpl.dispatchSyncNoTran(DispatcherImpl.java:359) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.jms.dispatcher.DispatcherAdapter.dispatchSyncNoTran(DispatcherAdapter.java:67) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.messaging.dispatcher.CrossPartitionDispatcher.dispatchSyncNoTran(CrossPartitionDispatcher.java:64) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.jms.client.JMSSession.createDestination(JMSSession.java:3460) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.jms.client.JMSSession.createQueue(JMSSession.java:2749) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at weblogic.jms.client.WLSessionImpl.createQueue(WLSessionImpl.java:945) ~[com.oracle.weblogic.jms.jar:12.2.1.4]
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveQueue(DynamicDestinationResolver.java:85) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveDestinationName(DynamicDestinationResolver.java:59) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.support.destination.JmsDestinationAccessor.resolveDestinationName(JmsDestinationAccessor.java:115) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.core.JmsTemplate.lambda$send$3(JmsTemplate.java:585) ~[spring-jms-5.3.20.jar:5.3.20]
    at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:504) ~[spring-jms-5.3.20.jar:5.3.20]

我已验证是否检索到了正确的属性,并且它与 WebLogic 中 JmsModule 的 JNDI 名称相匹配。 web.xml 和 weblogic.xml 是标准的,不包含与 JMS 相关的任何内容。我是否做错了什么/遗漏了什么?

java spring-boot jms
2个回答
0
投票

我已经找到解决办法了。在这种情况下,WebLogic 不会返回可用于创建 JmsTemplate 以便与 JmsQueue 交互的 ConnectionFactory。

解决方案是不从提供的 ConnectionFactory 创建 JmsTemplate,而是直接引用 JmsTemplate。

@Component
public class JmsMessageSender {

    @Resource
    private JmsTemplate jmsTemplate;

    public JmsMessageSender() {
        ...
    }
    ...

0
投票

最后是怎么解决的?你说的是什么意思:

解决方案是不要从提供的 JmsTemplate 创建 JmsTemplate ConnectionFactory而是直接引用JmsTemplate。

© www.soinside.com 2019 - 2024. All rights reserved.