The Rule Mediator is to integrate the WSO2 Rules component to the WSO2 ESB in order to define dynamic integration decisions in terms of rules.
...
Table of Contents | ||||
---|---|---|---|---|
|
...
|
...
Syntax
Code Block | ||||
---|---|---|---|---|
| ||||
<rule>
<ruleset>
<source [ key="xs:string" ]>
[ in-Lined ]
</source>
<creation>
<property name="xs:string" value="xs:string"/>*
</creation>
</ruleset>
<session type="[stateless|stateful]"/>*
<facts>
<fact name="xs:string" type="xs:string" expression="xs:string" value="xs:string"/>+
</facts>
<results>
<result name="xs:string" type="xs:string" expression="xs:string" value="xs:string"/>*
</results>
[ <childMediators>
<mediator/>*
</childMediators> ]
</rule>
|
...
The <source
> is the only mandatory element of the <ruleset
>. However, the properties required for the creation of the Ruleset can also be specified within <ruleset
>. The key attribute is a registry "key", which is to lookup the Rule script from the registry if the rule script is in the registry. The Ruleset can be given as a child node of <source
> element. If the Ruleset is non-XML, you may need to wrap it with a CDATA section inside a XML tag. For example,
Code Block | ||||
---|---|---|---|---|
| ||||
<X><![CDATA[ native code]]></X>
|
...
- "name" - The unique name.
- "value" - Represents any static value.
"expression" - XPath expression for extracting data from the message being passed between ESB components.
Info title Tip The default value is the first child of the SOAP Body.
- type- Defines the type of the input data. There are a few built-in types:
- Message
- Context
- Map
- POJO
Mediator
Info title Note Using the
rule-component.conf
, you can register new types along with adapters, which are responsible for formulating specified types from the data. If there is no registered adapter for a given type, then, we assume the given type as a valid Java class name and uses POJO adapter to formulate the POJO instance whose class is the given type.
...
The Main Elements of the Rule Mediator
- #Rule Rule Set
- #Rule Rule Set Creation Properties
- #Rule Rule Session
- #Rule Rule Session Configuration Properties
- #FactsFacts
- Results
Rule Set
Anchor | ||||
---|---|---|---|---|
|
...
For example, when using the Drool native language (DRL) for rule script, it is necessary to provide a DSL file.This can be done using the attribute named source
and value DRL
.
Code Block | ||||
---|---|---|---|---|
| ||||
<ruleSet>
<creation>
<property name="source" value="drl"/>
</creation>
</ruleSet>
|
...
Info | ||
---|---|---|
| ||
You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window. |
...
Example
Code Block | ||||
---|---|---|---|---|
| ||||
<rule>
<ruleset>
<source key="rule/sample.xml"/>
</ruleset>
<facts>
<fact name="symbol" type="java.lang.String"
expression="//m0:getQuote/m0:request/m0:symbol/child::text()"
xmlns:m0="http://services.samples"/>
</facts>
<childMediators>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
<drop/>
</childMediators>
</rule>
|
In the above configuration, the Rule script is picked from the registry with key rule/sample.xml
. There is one fact
and it is a string variable. Its value is calculated from the current SOAP message using an expression. The Rule engine uses these facts to decide what rules should fire.
Excerpt | ||
---|---|---|
| ||
Description of the Rule Mediator in WSO2 ESB. |