WebSphere Liberty:中间上下文不存在:jms / <连接工厂jndi>

问题描述

尝试通过Liberty 20.0.0.1。上的jndi查找将xml消息发送到JMS队列时遇到问题。

我的server.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<server description="Default server">
    <featureManager>
        <feature>el-3.0</feature>
        <feature>localConnector-1.0</feature>
        <feature>monitor-1.0</feature>
        <feature>restConnector-2.0</feature>
        <feature>jacc-1.5</feature>
        <feature>servlet-4.0</feature>
        <feature>jndi-1.0</feature>
        <feature>concurrent-1.0</feature>
        <feature>requestTiming-1.0</feature>
        <feature>ssl-1.0</feature>
        <feature>jdbc-4.0</feature>
        <feature>cdi-2.0</feature>
        <feature>jms-2.0</feature>
        <feature>jaxrs-2.1</feature>
        <feature>ejbLite-3.2</feature>
    </featureManager>

    <httpEndpoint id="defaultHttpEndpoint"
              host="*"
              httpPort="9080"
              httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files-->
    <applicationManager autoExpand="true"/>
    <applicationMonitor updateTrigger="mbean"/>

    <messagingEngine>
        <queue id="jmsQueue" forceReliability="ReliablePersistent" maxMessageDepth="5000"></queue>
    </messagingEngine>

    <jmsQueueConnectionFactory jndiName="jms/JMS_CF" connectionManagerRef="ConMgr">
        <properties.wasJms
            nonPersistentMapping="ExpressNonPersistent"
            persistentMapping="ReliablePersistent"/>
    </jmsQueueConnectionFactory>

    <connectionManager id="ConMgr" maxPoolSize="10"/>

    <jmsQueue id="jms_StockQueue" jndiName="jms/STOCK_JMS_QUEUE">
        <properties.wasJms queueName="stockQueue"
            deliveryMode="Application"
            timetoLive="500000"
            priority="1"
            readAhead="AsConnection" />
    </jmsQueue>

    <jmsActivationSpec id="core_indexing/jms-mdb/StockMDB">
        <properties.wasJms destinationRef="jms_StockQueue" />
    </jmsActivationSpec>
</server>

和我的Java(非ejb类)代码是:

final InitialContext context = new InitialContext();
final QueueConnectionFactory qcf = (QueueConnectionFactory) context.lookup("jms/JMS_CF");
final Queue destination = (Queue) context.lookup("jms/STOCK_JMS_QUEUE");
queueConnection = qcf.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,0);
final ObjectMessage message = queueSession.createObjectMessage(object);
queueSender = queueSession.createSender(destination);
queueSender.send(message);

但是,当我针对此容器内代码运行测试时,我得到了:

Intermediate context does not exist: jms/JMS_CF
javax.naming.NameNotFoundException: Intermediate context does not exist: jms/JMS_CF
at com.ibm.ws.jndi.internal.ContextNode.getTargetNode(ContextNode.java:125) ~[?:?]
at com.ibm.ws.jndi.internal.ContextNode.lookup(ContextNode.java:211) ~[?:?]
at com.ibm.ws.jndi.internal.WSContext.lookup(WSContext.java:306) ~[?:?]
at com.ibm.ws.jndi.WSContextBase.lookup(WSContextBase.java:61) ~[?:?]
at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161) ~[?:?]
at javax.naming.InitialContext.lookup(InitialContext.java:428) ~[?:1.8.0]

如果我更改Java代码,以便使用@Resource即完成连接工厂查找。

@Resource(lookup = "jms/JMS_CF")
private QueueConnectionFactory queueConnectionFactory;

错误是:

[ERROR   ] SRVE0315E: An exception occurred: java.lang.Throwable: 
javax.ejb.EJBException: CWNEN0030E: The server was unable to obtain an object 
instance for the 
java:comp/env/com.xyz.www.stock.api.ws.StockWS/queueConnectionFactory 
reference.  The exception message was: CWNEN1003E: The server was unable to 
find the jms/JMS_CF binding with the javax.jms.QueueConnectionFactory type 
for the java:comp/env/com.xyz.www.stock.api.ws.StockWS/queueConnectionFactory
reference.

用wasJmsServer-1.0和jJ-2.0替换jms-2.0 wasJmsClient-2.0摆脱了JNDI查找错误,但MDB无法激活。

解决方法

排序!

已替换

<feature>jms-2.0</feature>

使用

<feature>wasJmsServer-1.0</feature>
<feature>wasJmsClient-2.0</feature>
<feature>mdb-3.2</feature>
,

尽管 <jmsQueueConnectionFactory> 具有应用程序正在寻找的确切 JNDI 名称,但我也收到此错误。

原来的问题是连接工厂被配置为使用 IBM WebSphere MQ,而 Open Liberty 中没有。按照 Is there a "feature" in Open Liberty to connect to IBM MQ,equivalent to wmqJmsClient-2.0 in Liberty Profile? 中的步骤操作后,错误消失了。