Friday, 19 February 2016


Simple flow using JavaCompute Node in Message Broker 


Step 1:- Create a flow with MQInput Node,JavaCompute Node & MQOutput Node as follows.

Step 2:- Then paste the following code into JCN.

import com.ibm.broker.javacompute.MbJavaComputeNode;
import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbOutputTerminal;
import com.ibm.broker.plugin.MbUserException;
public class Java_Compute_Node_JavaCompute extends MbJavaComputeNode {
public void evaluate(MbMessageAssembly inAssembly) throws MbException {
MbOutputTerminal out = getOutputTerminal("out");
//MbOutputTerminal alt = getOutputTerminal("alternate");
MbMessage inMessage = inAssembly.getMessage();
MbMessageAssembly outAssembly = null;
try {
// create new message as a copy of the input
MbMessage outMessage = new MbMessage(inMessage);
outAssembly = new MbMessageAssembly(inAssembly, outMessage);
MbElement xml = outAssembly.getMessage().getRootElement().getLastChild();
MbElement emp = xml.getFirstChild();
emp.setName("Student");
MbElement sno = emp.getFirstChild();
sno.setName("sno");
MbElement sname = sno.getNextSibling();
sname.setName("sname");
sname.setValue(sname.getValue().toString().toUpperCase());
out.propagate(outAssembly);
} catch (MbException e) {
// Re-throw to allow Broker handling of MbException
throw e;
} catch (RuntimeException e) {
// Re-throw to allow Broker handling of RuntimeException
throw e;
} catch (Exception e) {
// Consider replacing Exception with type(s) thrown by user code
// Example handling ensures all exceptions are re-thrown to be
// handled in the flow
throw new MbUserException(this, "evaluate()", "", "", e.toString(),
null);
}
// The following should only be changed
// if not propagating message to the 'out' terminal
out.propagate(outAssembly);
}
}


Step 3:- Provide the input as follows:-
<Employee><eno>1</eno><ename>ajay</ename></Employee>

Step 4:- The result would be like 
<Student><sno>1</sno><sname>AJAY</sname></Student>

No comments: