【问题标题】:WebSphere Liberty: Intermediate context does not exist: jms/<connection factory jndi>WebSphere Liberty:中间上下文不存在:jms/<connection factory jndi>
【发布时间】:2021-01-13 20:53:15
【问题描述】:

我在尝试通过 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.

将 jms-2.0 替换为 wasJmsServer-1.0 和 wasJmsClient-2.0 消除了 JNDI 查找错误,但 MDB 不会激活。

【问题讨论】:

    标签: jms jndi websphere-liberty


    【解决方案1】:

    尽管 &lt;jmsQueueConnectionFactory&gt; 具有应用程序正在寻找的确切 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? 的步骤后,错误消失了。

    【讨论】:

      【解决方案2】:

      排序!

      替换

      <feature>jms-2.0</feature>
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多