Connect a JMS adapter to a Liberty profile server
We can develop and test MobileFirst adapters that use Java Message Service (JMS) on a WAS Liberty profile ND server.
To create adapters that use the JMS API, we must understand that the WAS Liberty profile included with MPF does not contain the built-in Liberty JMS features. Therefore, an embedded MobileFirst Development Server or a local external instance of this bundled WAS Liberty profile server cannot act as a JMS provider.
JMS is supported by the WAS Liberty profile V8.5 ND (Network Deployment) server. If we have a local copy of this application server installed on the same workstation as the MobileFirst tools, we can use it to develop and test the JMS applications.
Because WAS Liberty profile does not support remote JNDI lookups, it is not possible to make remote connections to the JMS server. The MobileFirst adapter must be running on the same local Liberty profile server that has JMS enabled.
The following procedure shows how to connect to an external Liberty profile server that supports JMS.
- Enable JMS on the Liberty profile ND server using the procedures in the WebSphere Application Server user documentation at Configure point-to-point messaging for a single Liberty profile server. Make a note of the JNDI connection factory and queue name, as shown in the following code example:
<!-- Enable features --> <featureManager> <feature>jsp-2.2</feature> <feature>wasJmsServer-1.0</feature> <feature>wasJmsClient-1.1</feature> <feature>jndi-1.0</feature> </featureManager> <messagingEngine id="defaultME"> <queue id="libertyQ" forceReliability="ReliablePersistent" maxQueueDepth="5000"> </queue> </messagingEngine> <jmsQueueConnectionFactory jndiName="jms/libertyQCF" connectionManagerRef="ConMgr2"> <properties.wasJms nonPersistentMapping="ExpressNonPersistent" persistentMapping="ReliablePersistent"/> </jmsQueueConnectionFactory> <connectionManager id="ConMrg2" maxPoolSize="2"/> <jmsQueue jndiName="jms/libertyQue"> <properties.wasJms queueName="libertyQ" deliveryMode="Application" timeToLive="500000" priority="1" readAhead="AsConnection" /> </jmsQueue>
- Create a MobileFirst JMS adapter.
- Because the adapter runs on a JMS-enabled Liberty profile server, the naming connection section of the adapter.xml file is not necessary. It can remain commented out.
- Enter the JNDI name for the connection factory created in the server.xml file.
<connectivity> <connectionPolicy xsi:type="jms:JMSConnectionPolicyType"> <!-- <namingConnection url="MY_JNDI_URL" initialContextFactory="providers_initial_context_factory_class_name" user="JNDIUserName" password="JNDIPassword"/> --> <jmsConnection connectionFactory="jms/libertyQCF" user="admin" password="admin" /> </connectionPolicy> </connectivity>
- In the JMS adapter implementation file, enter the JNDI name for the queue as the destination for both the read and write methods:
function readMessage() { var result = WL.Server.readSingleJMSMessage({ destination:"jms/libertyQue", timeout: 60 }); if (!result.message) { WL.Logger.debug(">> JMS adapter >> readNextMessage >> no message in queue"); return {}; } else { WL.Logger.debug(">> JMS adapter >> readNextMessage >> message received ::"); return result.message; }
- Change the MobileFirst target server in MobileFirst Studio to point to the Liberty ND server. See Work with multiple MobileFirst Server instances in MobileFirst Studio.
- Build and deploy the MobileFirst adapter to the Liberty profile ND server. We can test the JMS adapter in the browser using the following URL syntax:
http://<liberty-hostname>:<port>/<context-root>/invoke?adapterName= <adapterName>&procedure=<procedureName>¶meters=["<parameters>"]An example of a URL pointing to an external Liberty profile ND server:
http://localhost:9080/worklight/invoke?adapter=JMSAdapter&procedure= writeMessage¶meters=["Hello World"]
Parent topic: JMS adapters