ILOG JRules 和 WebSphere Process Server 集成概述3

 

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 会话调用规则

可以通过 EJB 调用本地或远程地访问 ILOG JRules 中部署的规则服务。图 16 显示使用 EJB 绑定调用规则集的模型。

图 16. 使用 EJB 调用 JRules

图 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 会话调用规则服务。

清单 2. 使用 EJB 调用 JRules 的示例

 

//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

使用 Web 服务调用规则

在 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 服务。

图 18. 使用 Web 服务调用 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 服务绑定导入的接口。

使用 JMS 调用规则

业务流程可以使用 Java Message Service (JMS) 消息标准异步地调用在 JRules 上运行的规则集。图 21 显示使用 JMS 调用规则集的模型。

图 21. 使用 JMS 调用 JRules 服务

图 21 显示客户机应用程序使用 JMS 消息标准调用 JRules 服务。它把 JMS 消息发送到一个消息目的地,在那里由消息驱动的规则 bean (MDB) 监听到达的消息。这个 MDB(即 JRules MDB)是一个作为消息监听器的企业 bean。在这个 bean 中,IlrRuleExecutionBean 是队列 MDB,IlrRuleExecutionTopicEJB 是主题 MDB(清单 3)。可以使用应用服务器资源分配由消息驱动的规则 bean 的目的地。

清单 3. ILOG JRules 中的队列和主题 MDB

 

<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…

     

如果这文章对你有帮助,请扫左上角微信支付-支付宝,给于打赏,以助博客运营

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注