For that you need to write a class mediator which appends the SOH and payload, then send to the back end. In this example we are going to the send the payload with SOH to IBMMQ server (which we consider as our BE).
Step 1
Create the class mediator as following
package com.home; import com.ibm.mq.jms.JMSC; import com.ibm.mq.jms.MQQueue; import com.ibm.mq.jms.MQQueueConnectionFactory; import org.apache.synapse.MessageContext; import org.apache.synapse.mediators.AbstractMediator; import javax.jms.*; public class SOHCustomMediator extends AbstractMediator { public boolean mediate(MessageContext messageContext) { try { String sohCharactor = (String) messageContext.getProperty("regProperty"); String messageBody = (String) messageContext.getProperty("messagebody"); //====================================================== MQQueueConnectionFactory queueConnectionFactory = new MQQueueConnectionFactory(); //Configure the connection properties queueConnectionFactory.setHostName ("localhost"); queueConnectionFactory.setPort (1414); queueConnectionFactory.setQueueManager ("ESBQManager"); queueConnectionFactory.setChannel ("mychannel"); queueConnectionFactory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP); // Started the queue connection QueueConnection queueConnection = queueConnectionFactory.createQueueConnection ("mqm", "1qaz2wsx@"); queueConnection.start(); // Set JMS configuration for queue and session Queue queue = new MQQueue("LocalQueue1"); QueueSession session = queueConnection.createQueueSession (false, Session.AUTO_ACKNOWLEDGE); QueueSender sender = session.createSender (queue); //Con-cat the message and the SOH TextMessage message = session.createTextMessage(sohCharactor + messageBody); message.setStringProperty("MyCustomProperty", "DUMMY_PROPERTY_VALUE"); System.err.println("Sending message:" + message.getText()); sender.send (message); System.out.println ("sent message: " + message); //close the session and connection session.close(); queueConnection.close(); } catch (Exception e) { e.printStackTrace(); } finally { } return true; } }
Step 2
Store the SOH.txt in the ESB registry (gov:trunk/SOH.txt)
Step 3
Add below jar files to <ESB_HOME>/repository/components/lib folder. Because those are needed for the class mediator to send the message to the IBM MQ.
- com.ibm.dhbcore.jar
- com.ibm.mq.jar
- com.ibm.mqjms.jar
- com.ibm.mq.soap.jar
- com.ibm.msg.client.osgi.wmq_7.0.1.3.jar
Step 4
Here is the sample proxy which is setting the SOH character and message payload to properties and then call the class mediator.
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="SOHProxy" startOnLoad="true" statistics="disable" trace="disable"> <target> <inSequence> <log level="full"/> <property expression="json-eval($)" name="messagebody"/> <property expression="get-property('registry', 'gov:trunk/SOH.txt')" name="regProperty"/> <class name="com.home.SOHCustomMediator"/> </inSequence> </target> <description/> </proxy>
That's all you need to do.
Thank You.
No comments:
Post a Comment