Connect a JMS adapter to WebSphere MQ
We can connect a MobileFirst Java Message Service (JMS) adapter to WebSphere MQ.
Ensure we have prior knowledge of WebSphere MQ and have a WebSphere MQ Message Broker setup with the appropriate JMS administered objects. For more information about setting up WebSphere MQ for JMS, see the IBM WebSphere MQ user documentation.
The MobileFirst JMS adapter does not support connecting to WebSphere MQ through bindings mode, only in client mode. A TCP connection is created for each JMS request, even if the JMS broker and MobileFirst adapter are running on the same computer.
To connect a MobileFirst JMS adapter to WebSphere MQ, you create a project, copy some JAR files to the project directory, and modify the adapter file.
Include the required WebSphere MQ Java libraries
- Create a MobileFirst project.
- Locate the java/lib directory in the WebSphere MQ directory.
Example: /opt/mqm/java/lib
- Copy the following JAR files from the java/lib directory into the server/lib directory of the project.
- CL3Export.jar
- CL3Nonexport.jar
- com.ibm.mq.axis2.jar
- com.ibm.mq.commonservices.jar
- com.ibm.mq.defaultconfig.jar
- com.ibm.mq.headers.jar
- com.ibm.mq.jar
- com.ibm.mq.jmqi.jar
- com.ibm.mq.jms.Nojndi.jar
- com.ibm.mq.pcf.jar
- com.ibm.mq.postcard.jar
- com.ibm.mq.soap.jar
- com.ibm.mq.tools.ras.jar
- com.ibm.mqjms.jar
- connector.jar
- dhbcore.jar
- fscontext.jar
- jta.jar
- providerutil.jar
- rmm.jar
Modify the adapter XML file
- Create a MobileFirst JMS adapter.
- Open the adapter.xml file.
- In the namingConnection element of the xml file, set the URL to the location of the bindings file that was generated by WebSphere MQ.
Example:
url="file:/home/user/JMS"
- In the namingConnection element of the XML file, set the initialContextFactory attribute to com.sun.jndi.fscontext.RefFSContextFactory.
- In the jmsConnection element, set the connectionFactory attribute to the name of the connection factory that was set up in WebSphere MQ.
- Optional: If security is enabled in WebSphere MQ, include the credentials as shown in the following code example.
<connectivity> <connectionPolicy xsi:type="jms:JMSConnectionPolicyType"> <namingConnection url="file:/home/user/JMS" initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory" user="admin" password="password"/> <jmsConnection connectionFactory="myConnFactory" user="admin" password="password"/> </connectionPolicy> </connectivity>Modify the adapter implementation file
- Open the adapter's implementation file.
- In the autogenerated read and write methods, replace the destination property with the name that was configured in the JMS administered object in WebSphere MQ.
Example:
function readMessage() { var result = WL.Server.readSingleJMSMessage({ destination: "JMS1", timeout: 60 }); WL.Logger.debug(result); if (result.errors) { WL.Logger.debug(">> JMS adapter >> readNextMessage >> errors occured"); return result; } else if (!result.message) { WL.Logger.debug(">> JMS adapter >> readNextMessage >> no messages in queue"); return result; } else { WL.Logger.debug(">> JMS adapter >> readNextMessage >> message received ::"); }
Results
The MobileFirst JMS adapter is now properly configured to connect to WebSphere MQ. We can test the JMS adapter in the browser using the following URL:http://host:<port>/<context-root>/invoke?adapterName=<adapterName>&procedure= <procedureName>¶meters=[‘<parameters>']
Example
http://localhost:10080/worklight/invoke?adapter=JMSAdapter&procedure= writeMessage¶meters=[‘Hello World']
Parent topic: JMS adapters