我想建立一个从数据库中获取数据的骡子流,构建一个对象,然后触发一个流氓规则。我的问题是initialFacts-ref ="#[payload.MapObject]"无法解决。在部署时,我得到了没有名为'#[payload.MapObject]'已定义'如何将有效负载对象作为事实获取到规则中?
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bpm="http://www.mulesoft.org/schema/mule/bpm"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/db
http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/json
http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/vm
http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/jms
http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/bpm
http://www.mulesoft.org/schema/mule/bpm/3.2/mule-bpm.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking
http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/ee/dw
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<bpm:drools />
<flow name="myFlow" >
<http:listener config-ref="HTTP_Listener_Configuration" path="/myflow" doc:name="HTTP">
<http:response-builder>
<http:header headerName="Access-Control-Allow-Origin" value="*"/>
</http:response-builder>
</http:listener>
<db:select config-ref="MySQL_Finance" doc:name="Database">
<db:parameterized-query><![CDATA[SELECT * FROM myTable WHERE ID = #[message.inboundProperties.'http.query.params'.ID]]]></db:parameterized-query>
</db:select>
<response>
<json:object-to-json-transformer doc:name="Object to JSON"/>
</response>
<component class="org.mule.transformers.myMapping" doc:name="myMapping"/>
<bpm:rules doc:name="myRule" rulesDefinition="src/main/resources/rules/myRule.drl" initialFacts-ref="#[payload.MapObject]"/>
</flow>
</mule>
package org.mule.transformers;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;
public class myMapping extends AbstractMessageTransformer {
/**
* @param args
*/
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
Object myMapping = null;
if(message != null){
myMapping = message.getPayload();
}
return myMapping;
}
}
答案 0 :(得分:1)
initialFacts-ref
引用现有的Spring bean,因此您不能在尝试使用MEL表达式时使用。它用于加载初始事实,这就是为什么它是静态的。
在您的情况下,您似乎只想处理规则中的当前消息,而不是向规则引擎提供一组初始事实。在这种情况下,没有任何关系。当前的消息有效负载将传递给Drools,因此您可以直接访问它。