To call a message-driven rule bean when using WebSphere® MQ, you have to bind the JMS
object message by using a custom data binding.
About this task
A client application can run in IBM® Process Server and
call a message-driven rule bean using WebSphere MQ as
the JMS provider.
The message-driven rule bean expects a java.util.Map as
the payload of a JMS object message, while the client application
expects a business object. The default JMS data binding cannot serialize
this properly. Therefore, you must create a custom JMS data binding
that maps a java.util.Map instance to the business
object representation.
The following example shows a custom
data binding that uses the point-to-point messaging model.
Procedure
To implement a custom data binding and use this binding
in IBM Process Server:
- Implement the com.ibm.websphere.sca.jms.data.JMSDataBinding interface.
Here is the skeleton of such a class:
import javax.jms.JMSException;
import javax.jms.Message;
import com.ibm.websphere.sca.jms.data.JMSDataBinding;
import commonj.connector.runtime.DataBindingException;
import commonj.sdo.DataObject;
public class CustomerApplicationDataBinding implements JMSDataBinding {
public int getMessageType() {return 0;}
public void read(Message arg0) throws JMSException {}
public void write(Message arg0) throws JMSException {}
public boolean isBusinessException() {return false;}
public void setBusinessException(boolean arg0) {}
public DataObject getDataObject() throws DataBindingException {return null;}
public void setDataObject(DataObject arg0) throws DataBindingException {}
}
- Use the following implementation of the getMessageType(), read(Message
arg0), and write(Message arg0) methods
to map the CustApplication business object to the java.util.HashMap.
public int getMessageType() {
return JMSDataBinding.OBJECT_MESSAGE;
}
public void write(Message message) throws JMSException {
try {
ObjectMessage requestMessage = queueSession.createObjectMessage();
// Set the mandatory Rule Execution Server JMS properties.
requestMessage.setStringProperty("ilog_rules_bres_mdb_rulesetPath", rulesetPath);
requestMessage.setStringProperty("ilog_rules_bres_mdb_status", "request");
// Mandatory to get a reply message with the result of the rules execution.
requestMessage.setJMSReplyTo(replyTo);
// Set the ruleset parameters.
HashMap<String, String> parametersIn = new HashMap<String, String>();
CustApplication customerApplication = convertSDOCustApplication(customerApplicationSdo);
parametersIn.put("CustomerApplication", customerApplication);
requestMessage.setObject(parametersIn);
// Send the message.
queueSender.send(requestMessage);
} catch (DataBindingException e) {
throw new JMSException(e.getLocalizedMessage());
}
}
public void read(Message message) throws JMSException {
//Get the payload of the JMS Object message.
ObjectMessage responseMessage = (ObjectMessage) msg;
HashMap parametersOut = (HashMap) responseMessage.getObject();
// Get the number of rules fired.
str.append("\nThere are "
+ parametersOut.get("ilog.rules.firedRulesCount")
+ " rules executed\n");
// Get the value of the output report parameter.
String report = (String) parametersOut.get("report");
CustApplication outCustomerApplication =
(CustApplication) (parametersOut.get("CustomerApplication"));
// Create the business object.
DataObject dobject = convertToSDOCustApplication(outCustomerApplication);
try {
// Set the data object
setDataObject(dobject);
} catch (DataBindingException e) {
throw new JMSException(e.getLocalizedMessage());
}
}
In IBM Process Server, you
can then create a JMS import.
- Right-click the Import, and then
click Generate Binding > Messaging
Binding > MQ JMS Binding.
The Configure WebSphere MQ JMS
Import Service wizard opens.
- Under End-point configuration, select Use
pre-configured messaging provider resources, then enter
the JNDI names for the connection factory, send destination, and receive
destination.
- Click Select to choose the default
data format.
The Data Transformation
Configuration dialog opens.
- Click OK.
- Click Select to find the custom
data binding class from the workspace.
- Clear the security configuration check box, and click Finish.
The MQ JMS import is generated.