通過異步消息整合 ILOG JRules 和 WebSphere Process Server4

7. 單擊 References 標籤,配置 IlrRuleExecutionEJB 的資源引用。將 ResourceRef eis/XUConnectionFactory 的 JNDI 名字設為 eis/XUConnectionFactoryResourceRef jms/BRESQueueConnectionFactory 的 JNDI 名字為 jms/BRESQueueConnectionFactory

圖 23. 配置 JRules MDB 的資源引用

8. 然後輸出 EAR。

圖 24. 輸出 ear

9. 將 EAR 文件部署到安裝 JRules 執行服務器的應用程序服務器。完成 EAR 部署之後,在管理控制台啟用它。

現在 JRules 服務就準備好被調用了。

客戶機開發

客戶機應用程序可以直接使用 JMS APIs 或者 JMS/MQ JMS 綁定來調用部署在服務器端的 JRules MDB。它向服務集成總線或者JRules MDB 正在監聽的 WebSphere MQ 的請求隊列發送 JMS 消息,然後從響應隊列中獲取結果。

在 POJO 中使用 JMS APIs 調用 JRules MDB

您可以直接使用 POJO 組件中的 JMS APIs 來調用 JRules MDB。這個界面可以使單向的或者請求-響應。

1. 使客戶能夠定位連接工廠和隊列:

清單 2. 定位連接工廠和隊列

 

//Locate the connection factory and queues

InitialContext ctx = new InitialContext();

QueueConnectionFactory queueConnectionFactory =

(QueueConnectionFactory) ctx.lookup(“jms/BRESQueueConnectionFactory”);

Queue queueIn = (Queue) ctx.lookup( “jms/BRESQueueIn”);

Queue queueOut = (Queue) ctx.lookup(“jms/BRESQueueOut”);

 

//Get the client to create the queue connection and session

QueueConnection queueConnection =

queueConnectionFactory.createQueueConnection(“”,””);

QueueSession queueSessionJMSTx = queueConnection.createQueueSession(true, 0);

 

2. 讓客戶創建一個發送端,然後就向 JRules MDB 正在監聽的隊列發送請求消息。JMS 的消息體是一個 javax.jms.ObjectMessage 中的 java.util.Map。為了參數化調用,這個消息必須包括 ILOG_rules_bres_mdb_rulesetPathILOG_rules_bres_mdb_status JMS 屬性。請求消息的 JMSReplyTo 頭文件指定 JMS 響應目的地。

清單 3. 創建並發送請求消息

 

//Create a sender

QueueSender queueSender = queueSessionJMSTx.createSender(queueIn);

 

//Create the request message and initialization

ObjectMessage requestMessage = queueSessionJMSTx.createObjectMessage();

 

//Create the parameters

HashMap inputParameters = new HashMap();

inputParameters.put(“CustomerApplication”, customerApplication);

 

//Set the parameters

requestMessage.setObject(inputParameters);

 

//Set the JMS message header properties

requestMessage.setStringProperty(“ILOG_rules_bres_mdb_rulesetPath”,rulesetPath);

requestMessage.setStringProperty(“ILOG_rules_bres_mdb_status”,”request”);

 

//Set the destination of the response message

requestMessage.setJMSReplyTo(queueOut);

 

//Send the message

queueSender.send(requestMessage);

System.out.println(“>>> Sent JMS message to MDB queue”);

queueSender.close();

 

//Get the request message ID

requestMsgID=requestMessage.getJMSMessageID();

 

3. 如果界面是請求-響應型,讓客戶在另一個事務創建一個接收端,然後從響應隊列接收響應消息。使用請求消息 ID 和響應相關 ID 獲取匹配的響應消息。

清單 4. 獲取響應消息

 

//Create a receiver

StringBuffer selectorBuffer = new StringBuffer(“JMSCorrelationID”);

selectorBuffer.append(” = ‘”);

selectorBuffer.append(requestMsgID);

selectorBuffer.append(“‘”);

QueueReceiver queueReceiver =

queueSessionJMSTx.createReceiver(queueOut, selectorBuffer.toString());

 

//Begin to receive message

Message messageOut = queueReceiver.receive();

queueReceiver.close();

 

//Get the response message

ObjectMessage responseMessage = (ObjectMessage) messageOut;

HashMap parameters = (HashMap) responseMessage.getObject();

CustBO outCustomerBO = (CustBO) (parameters.get(“CustomerBO”));

 

使用 JMS 綁定/MQ JMS 綁定調用 JRules MDB

JRules MDB 期待 java.util.Map 作為一個 JMS 對象消息的負載,而 WPS 的客戶機應用程序期待一個業務對象。因為 WPS 提供的默認 JMS 數據綁定不能適當處理格式轉換,我們需要創建一個在 WPS 中可以映射到 java.util.Map 和業務對象的自定義 JMS 數據綁定

1. 實現一個自定義 JMS 數據綁定。自定義數據綁定實現必須實現 com.ibm.websphere.sca.jms.data.JMSDataBinding。這一類的框架如下所示:

清單 5. 自定義 JMS 數據綁定類的框架

 

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 {}

}

 

2. getMessageType() 的以下實現示例,read(Message arg0) 和 write(Message arg0) 可以用於在 CustBO 業務對象和 java.util.HashMap 之間進行映射。

清單 6. 自定義 JMS 數據綁定實現的示例

 

public int getMessageType() {

return JMSDataBinding.OBJECT_MESSAGE;

}

 

public void write(Message message) throws JMSException {

try {

ObjectMessage requestMessage = (ObjectMessage) message;

 

//Get the data object

DataObject customerBO = getDataObject();

 

//Create the java.util.HashMap

HashMap inputParameters = new HashMap();

inputParameters.put(“CustomerBO”, customerBO);

 

//Set the payload of the JMS Object Message

requestMessage.setObject(inputParameters);

String rulesetPath = “/” + RULEAPP_NAME + “/” + RULESET_NAME_EMEARULE;

 

//Set the JMS message header properties

requestMessage.setStringProperty(“ILOG_rules_bres_mdb_rulesetPath”,

rulesetPath);

requestMessage.setStringProperty(“ILOG_rules_bres_mdb_status”, “request”);

} 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) message;

 

//Get the business object

HashMap parameters = (HashMap) responseMessage.getObject();

DataObject dobject = (CustBO) (parameters.get(“CustomerBO”));

try {

// Set the data object

setDataObject(dobject);

} catch (DataBindingException e) {

throw new JMSException(e.getLocalizedMessage());

}

}

 

3. 當 WAS 中的默認消息提供者被用作 JMS 消息提供者時,可以用一個 JMS 綁定導入調用 JRules MDB:

圖 25. 生成 JMS 綁定

以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營