是否可以从远程应用程序服务器连接到部署在 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)
原始 IBM 文档没有明确讨论 Liberty 中是否禁用此功能。
解决方案:无法在 Liberty 中使用 JNDI 进行远程查找。
使用此论坛主题:link https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014949432,可以通过编程方式构造 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 安装目录)