|
Map inputParameters = new HashMap(); String strAMERICASPricing = serialize(AMERICASPricingSdo, “http://AMERICAS_Pricing”, “AMERICAS_Pricing”); inputParameters.put(“AMERICASPricing”, strAMERICASPricing);
//Get the session factory for a Java rulesession invocation IlrSessionFactory sessionFactory = new IlrPOJOSessionFactory(); IlrSessionRequest request = sessionFactory.createRequest(); request.setRulesetPath(IlrPath.parsePath(rulesetPath)); request.getInputParameters().putAll(inputParameters);
//create a stateless rule session IlrStatelessSession ruleSession = sessionFactory.createStatelessSession(); IlrSessionResponse result = ruleSession.execute(request);
Map outputParameters = result.getOutputParameters(); String strOutAMERICASPricing = (String) outputParameters.get (“AMERICASPricing”); DataObject response = createResponse(“http://com”, “AMERICAS_Pricing_RuleProjectExecutionResult”); response.set(“AMERICASPricing”, deserialize (strOutAMERICASPricing,”AMERICAS_Pricing”)); |
JRules 在 Integration Developer 中提供一個 Decision Service Wizard,可以用它自動地生成 SCA POJO 組件(圖 15)。
圖 15. 在 WebSphere Integration Developer 中使用 Decision Wizard 生成 SCA POJO
可以通過 EJB 調用本地或遠程地訪問 ILOG JRules 中部署的規則服務。圖 16 顯示使用 EJB 綁定調用規則集的模型。
圖 16 顯示客戶機應用程序使用規則會話(IlrStatelessRuleSession 或 IlrStatefulRuleSession)調用規則集。在規則會話中,將調用 IlrStatelessRuleSessionEJB 或 IlrStatefulRuleSessionEJB。IlrStatelessRuleSessionEJB 和 IlrStatefulRuleSessionEJB 可以駐留在與客戶機不同的 JVM 中。IlrStatelessRuleSessionEJB 或 IlrStatefulRuleSessionEJB 進而本地地調用在 XU 上運行的規則集。在 ILOG JRules 中,IlrStatelessRuleSession、IlrStatefulRuleSession、IlrStatelessRuleSessionEJB 和 IlrStatefulRuleSessionEJB 都打包在 jrules-res-session-WAS7.jar 中。客戶機是 Process Server 中調用規則服務的場景。服務器是 ILOG JRules Execution Server 所在的應用服務器。
清單 2 所示的 Java 代碼使用 EJB 會話調用規則服務。
|
//Sets IN and INOUT parameters. Map inputParameters = new HashMap(); String strCreditpricing = serialize(creditpricingSdo,”http://creditpricing”, “CreditPricing”); inputParameters.put(“creditpricing”, strCreditpricing);
Properties properties = new Properties(); properties.put(JAVA_NAMING_FACTORY_INITIAL, INITIAL_CONTEXT_FACTORY); properties.put(JAVA_NAMING_PROVIDER_URL, ENGINE_URL);
IlrSessionRequest request = new IlrSessionRequest(rulesetPath); request.getExecutionSettings().getInputParameters().setParameters (inputParameters);
//Get the provider for a Remote EJB IlrRuleSessionProvider rsProvider = new IlrRuleSessionProviderFactory.Builder( properties).setJNDINameOfRuleSessionStateless(JNDI_NAME).build();
//create a stateless rule session IlrStatelessRuleSession ruleSession = rsProvider.createStatelessRuleSession(); IlrSessionResponse result = ruleSession.executeRules(request);
ilog.rules.bres.session.IlrSessionParameters outputParameters = result .getExecutionResult().getOutputParameters();
String strOutCreditpricing = (String) outputParameters.getObjectValue (“creditpricing”); DataObject response = createResponse(“http://com”, “PricingrulesExecutionResult”); response.set(“creditpricing”, deserialize(strOutCreditpricing,”CreditPricing”)); |
JRules 在 Integration Developer 中提供一個 Decision Service Wizard,可以用它自動地生成調用此代碼的 SCA POJO 組件和 EJB(圖 17)。
圖 17. 在 WebSphere Integration Developer 中使用 Decision Wizard 生成 SCA POJO
在 Process Server 中,可以通過 Web 服務訪問規則服務。ILOG JRules 使用透明決策服務為規則集提供 Web 服務訪問。JRules 提供兩種透明決策服務:
駐留的透明決策服務:這實際上是一個部署為 Web 服務器的規則集。它安裝在與 Rule Execution Server 相同的應用服務器上,然後與 Rule Execution Server 集成。
監視的透明決策服務:這個服務是由 Rule Studio 生成的,駐留在與 Rule Execution Server 相同的應用服務器上,但是不與它集成。這個決策服務獨立於 Rule Execution Server,但是通過訪問它執行規則。
對於監視的透明決策服務,支持的應用服務器只有 JBoss 和 Tomcat。因此,在與 Process Server 集成時,只能使用駐留的透明決策服務。圖 18 說明如何使用駐留的透明決策服務訪問 JRules 服務。
要想使用 Web 服務訪問規則集,應該把駐留的透明決策服務 (jrules-res-htds-WAS7.ear) 部署到 Rule Execution Server 所在的 Process Server。這可以是與進行調用的業務流程相同的主機,也可以是不同的主機。
圖 19. 把透明決策服務部署到 WebSphere Process Server
要想使用 Web 服務調用規則集,首先需要從 Rule Execution Server 控制台導出目標規則應用程序的 WSDL(圖 20)。
圖 20. 從 Rule Execution Server 控制台導出 WSDL
然後,在 Integration Developer 中,把這個 WSDL 文件導入要調用規則服務的 SCA 模塊,指定 WSDL 文件中定義的用於 Web 服務綁定導入的接口。
業務流程可以使用 Java Message Service (JMS) 消息標準異步地調用在 JRules 上運行的規則集。圖 21 顯示使用 JMS 調用規則集的模型。
圖 21 顯示客戶機應用程序使用 JMS 消息標準調用 JRules 服務。它把 JMS 消息發送到一個消息目的地,在那裡由消息驅動的規則 bean (MDB) 監聽到達的消息。這個 MDB(即 JRules MDB)是一個作為消息監聽器的企業 bean。在這個 bean 中,IlrRuleExecutionBean 是隊列 MDB,IlrRuleExecutionTopicEJB 是主題 MDB(清單 3)。可以使用應用服務器資源分配由消息驅動的規則 bean 的目的地。
|
<message-driven> <ejb-name>IlrRuleExecutionEJB</ejb-name> <ejb-class>ILOG.rules.bres.mdb.ejb.IlrRuleExecutionBean</ejb-class> … </message-driven>
<message-driven> <ejb-name>IlrRuleExecutionTopicEJB</ejb-name> <ejb-class>ILOG.rules.bres.mdb.ejb.IlrRuleExecutionBean</ejb-class> … </message-driven> |
以下文章點擊率最高
Loading…