是否可以从远程应用程序服务器连接到Websphere Liberty中部署的队列?

我使用产品的免费版本(Liberty 8.5.5.7) . 我在server.xml中配置了连接工厂:

<messagingEngine>
    <queue id="Queue1" receivedAllowed="false" maxMessageDepth="1000"/>
</messagingEngine>

<jmsQueueConnectionFactory jndiName="qcf/ConnectionFactory" connectionManagerRef="ConMgr2">
    <properties.wasJms nonPersistentMapping="ExpressNonPersistent" persistentMapping="ReliablePersistent"/>
</jmsQueueConnectionFactory>
<connectionManager id="ConMgr2" maxPoolSize="10"/>

jms服务器正在侦听localhost:7276 .

我编写了一个简单的客户端应用程序,并在类路径中包含必要的客户端jar(com.ibm.ws.ejb.thinclient_8.5.0.jar,com.ibm.ws.orb_8.5.0.jar和com.ibm.ws.sib . client.thin.jms_8.5.0.jar):

Properties env = new Properties();
env.put(Context.PROVIDER_URL,"iiop://localhost:7276");
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext ctx = new InitialContext(env);
Object qcf = ctx.lookup("qcf/ConnectionFactory");

运行该程序会产生以下异常:

javax.naming.ServiceUnavailableException: A communication failure occurred while attempting to obtain an initial context with the provider URL: "iiop://localhost:7276".  Make sure that any bootstrap address information in the URL is correct and that the target name server is running.  A bootstrap address with no port specification defaults to port 2809.  Possible causes other than an incorrect bootstrap address or unavailable name server include the network environment and workstation network configuration. [Root exception is org.omg.CORBA.TRANSIENT: java.net.ConnectException: Connection refused: connect:host=192.168.9.208,port=7276  vmcid: 0x4942f000  minor code: 3586  completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.mapInitialReferenceFailure(WsnInitCtxFactory.java:2373)

如果在Liberty中禁用此功能,则原始IBM文档不会清楚地讨论 .

Solution: 在Liberty中无法使用JNDI进行远程查找 . 使用此论坛主题:link,可以以编程方式构造ConnectionFactory .

JmsFactoryFactory jff = JmsFactoryFactory.getInstance();
JmsQueueConnectionFactory qcf = jff.createQueueConnectionFactory();
qcf.setBusName("myBus");
qcf.setProviderEndpoints("localhost:7276:BootstrapBasicMessaging");
qcf.setTargetTransportChain("InboundBasicMessaging");

在类路径中只需要这个jar:com.ibm.ws.orb_8.5.0.jar,com.ibm.ws.sib.client.thin.jms_8.5.0.jar . (在WebSphere \ AppServer \ runtimes中找到,其中WebSphere是完整的WAS安装目录)