Drools in FIX Edge Java

1.  Intro

Drools is an extension on the current Business Layer, not its replacement. It is present in standard package, embedded in FEJ and can be used without some additional components.

FEJ API can be called from Drools rules. External Drools server cannot be used.

2. Drools Engine documentation

The following property is used to configure if Drools Engine is enabled or disabled:

drools.engine.enabled

Possible values: true | false. Default value: false.

This property is specified in fixedge.properties file in FIXEdge Java.

2.1.1. Methods to work with stateless sessions

  • org.kie.api.runtime.StatelessKieSession createStateless(String sessionName) throws com.epam.fej.routing.drools.DroolsException

Creates new stateless session and returns it. 

Parameters:

  • sessionName - the name of the session

Returns created stateless Kie Session. 

Throws DroolsException if Drools Engine is not initialized.

  • org.drools.core.runtime.impl.ExecutionResults runStateless(String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Executes command for stateless session. 

Parameters:

  • sessionName - the name of the session

    • values - command arguments

Returns execution result. 

Throws DroolsException if Drools Engine is not initialized.

 

2.1.2. Methods to work with stateful sessions

2.1.2.1. Methods to create session

  • org.kie.api.runtime.KieSession createStateful(String id, String sessionName) throws com.epam.fej.routing.drools.DroolsException

Creates new stateful session and adds it to sessions cache. SessionName is used to create new session if a session is not found by id.

Please pay attention: When new Drools Config comes from FIXICC H2, the session will be disposed. A user should get session again.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

Returns created Kie Session. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession getOrCreateStateful(String id, String sessionName) throws com.epam.fej.routing.drools.DroolsException

Returns existing stateful session if it exists in sessions cache. Otherwise creates new stateful session, adds it to the sessions cache and returns. SessionName is used to create new session if a session is not found by id.

Please pay attention: When new Drools Config comes from FIXICC H2, the session will be disposed. A user should get session again.

Parameters:

  • id - the ID of the session in sessions cachet

    • sessionName - the name of the session

Returns Kie Session from the sessions cache. 

Throws DroolsException if Drools Engine is not initialized.

 

2.1.2.2. Methods to run session

  • org.kie.api.runtime.KieSession runStateful(String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session and fires all matches of the agenda for this session.  SessionName is used as session id.

Parameters:

  • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession runStatefulAndClean(String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session, fires all matches of the agenda for this session and retracts the facts. SessionName is used as session id.

Parameters:

  • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession runStateful(String id, String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session and fires all matches of the agenda for this session. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession runStatefulAndClean(String id, String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session, fires all matches of the agenda for this session and retracts the facts. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession fireAll(String id, String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session and fires all matches of the agenda for this session. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession fireAllUntilHalt(String id, String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session and keeps firing Matches until a halt is called for this session. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession fireAllAndClean(String id, String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session, fires all matches of the agenda for this session and retracts the facts. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession fireAllUntilHaltAndClean(String id, String sessionName, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session, keeps firing Matches until a halt is called for this session and retracts the facts. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • values - the facts to be inserted

Returns Kie Session the matches have been fired for. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession fireRules(String id, String sessionName, Consumer<org.kie.api.runtime.KieSession> method, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session and performs consumer operation on the session. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • method - operation performed on the session

    • values - the facts to be inserted

Returns Kie Session the operation has been performed on. 

Throws DroolsException if Drools Engine is not initialized.

  • org.kie.api.runtime.KieSession fireRulesAndClean(String id, String sessionName, Consumer<org.kie.api.runtime.KieSession> method, Object...values) throws com.epam.fej.routing.drools.DroolsException

Inserts new facts into the stateful session, performs consumer operation on the session and retracts the facts. SessionName is used to create new session if a session is not found by id.

Parameters:

  • id - the ID of the session in sessions cache

    • sessionName - the name of the session

    • method - operation performed on the session

    • values - the facts to be inserted

Returns Kie Session the operation has been performed on. 

Throws DroolsException if Drools Engine is not initialized.

  • void fireAllRules(org.kie.api.runtime.KieSession kieSession)

Fire all Matches of the agenda for a stateful session.

Parameters:

  • kieSession - stateful session

  • void fireUntilHalt(org.kie.api.runtime.KieSession kieSession)

Fire all Matches for a stateful session until a halt is called for this session.

Parameters:

  • kieSession - stateful session

2.1.2.3. Methods to dispose sessions

  • void dispose(String id) throws com.epam.fej.routing.drools.DroolsException

Releases all the current session resources, setting up the session for garbage collection.

Parameters:

  • id - the ID of the session in sessions cache

Throws DroolsException if Drools Engine is not initialized.

  • void disposeSessions()

Disposes all Kie stateful sessions.

 

2.1.3. Other methods

  • void reset()

Initializes Kie Container and Kie Container Sessions Pool.

  • void clear()

Disposes Kie Sessions and Kie Container, clear Kie Sessions cache, shutdowns Kie Container Sessions Pool.

  • org.kie.api.runtime.KieContainer getContatiner()

Returns Kie Container.

 

3. Drools Config Manager Listener documentation

If you need to create your own listener, you should implement DroolsConfigManagerListener interface and override it's methods. After this, the listener should be registered in fej-routing.xml

Example:

<bean id="droolsCfgListener" class="com.epam.fej.routing.drools.cfg.NoOpDroolsConfigManagerListener"/>

3.1.1. Listener methods

  • void onConfigChanged(com.epam.fej.routing.drools.cfg.DroolsConfig droolsConfig, Path pathInCache)

          Apply some actions if Drools configuration (kmodule.xml, Drools assets) has been changed. 

Parameters:

  • droolsConfig - Drools config (kmodule.xml, Drools assets)

    • pathInCache - path where Drools configuration is saved in cache

  • void onKModuleChanged(String kmodule)

           Apply some actions if kmodule.xml has been changed. 

Parameters:

  • kmodule - the content of kmodule.xml

  • void onAssetAdded(com.epam.fej.routing.drools.cfg.RuleSetConfig ruleSetConfig, Path pathInCache)

           Apply some actions if Drools asset has been added. 

Parameters:

  • ruleSetConfig - added Drools asset

    • pathInCache - path where Drools asset is saved in cache

  • void onAssetChanged(com.epam.fej.routing.drools.cfg.RuleSetConfig ruleSetConfig, Path pathInCache)

           Apply some actions if Drools asset has been changed. 

Parameters:

  • ruleSetConfig - changed Drools asset

    • pathInCache - path where Drools asset is saved in cache

  • void onAssetDeleted(com.epam.fej.routing.drools.cfg.RuleSetConfig ruleSetConfig, Path pathInCache)

           Apply some actions if Drools asset has been deleted. 

Parameters:

  • ruleSetConfig - deleted Drools asset

    • pathInCache - path where Drools asset is saved in cache

4.  Examples

 

4.1 This example describes how to work with Drools in FEJ with FIXICC-H2

Add the following business rules configuration:

import com.epam.fej.routing.drools.DroolsEngine import static dsl.CommonRulesDsl.rulesDSL   DroolsEngine dre = drools as DroolsEngine   rulesDSL(routingContext as RoutingContext) {     messageRules {         messageRule("Route FIX message by decision table in kbase1") {             action {                 custom {                     ctx ->                         dre.runStatefulAndClean("ksession1", ctx)                         routingContext.getDestinationById(ctx.messageEvent.getHeader("destination")).send(ctx.messageEvent)                 }                 context exit             }         }     } }

Then configure Drools. To do it, in FIXICC-H2 select "Edit kmodule.xml" menu item in Server View in Configuration menu and add the following content:

Then add new Drools component. Select "Drools components" menu item in Server View in Configuration menu, click "Add" popup button, choose "Decision table" and upload the following file:

 

<style><!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";}@page { mso-header-data:"&C&A"; mso-footer-data:"&CPage &P"; margin:1.025in 0.7875in 1.025in 0.7875in; mso-header-margin:0.7875in; mso-footer-margin:0.7875in; mso-page-numbers-start:1; mso-page-orientation:Portrait; }tr {mso-height-source:auto; mso-ruby-visibility:none;}col {mso-width-source:auto; mso-ruby-visibility:none;}br {mso-data-placement:same-cell;}ruby {ruby-align:left;}.style0 { mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border:none; mso-protection:locked visible; mso-style-name:Normal; mso-style-id:0;}.font0 { color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; }.font1 { color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; }.font2 { color:#000000; font-size:10pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; }.font3 { color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; }.font4 { color:#FFFFFF; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; }.font5 { color:#FFFFFF; font-size:10pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; }.font6 { color:#FFFFFF; font-size:12pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; }.font7 { color:#FFFFFF; font-size:12pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; }td {mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border:none; mso-protection:locked visible; mso-ignore:padding;}.style0 { text-align:general; vertical-align:bottom; white-space:nowrap; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; mso-style-name:"Normal"; }.style1 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style2 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style3 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style4 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style5 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style6 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style7 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style8 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style9 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style10 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style11 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style12 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style13 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.style14 { text-align:general; vertical-align:middle; white-space:nowrap; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x15 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x16 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x17 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x18 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x19 { mso-style-parent:style0; mso-number-format:General; text-align:center; vertical-align:middle; white-space:normal;word-wrap:break-word; background:#000000; mso-pattern:auto none; color:#FFFFFF; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x20 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:#008000; mso-pattern:auto none; color:#FFFFFF; font-size:10pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x21 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:#008000; mso-pattern:auto none; color:#FFFFFF; font-size:10pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x22 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:#008000; mso-pattern:auto none; color:#FFFFFF; font-size:12pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x23 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:center; vertical-align:middle; white-space:normal;word-wrap:break-word; background:#000000; mso-pattern:auto none; color:#FFFFFF; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x24 { mso-style-parent:style0; mso-number-format:"0"; text-align:center; vertical-align:middle; white-space:normal;word-wrap:break-word; background:#000000; mso-pattern:auto none; color:#FFFFFF; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x25 { mso-style-parent:style0; mso-number-format:General; text-align:left; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; border-top:none; border-right:none; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x26 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; background:#FFFF00; mso-pattern:auto none; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x27 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:none; border-bottom:1px dotted #000000; border-left:none; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x28 { mso-style-parent:style0; mso-number-format:"0"; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:#B9CDE5; mso-pattern:auto none; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x29 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:left; vertical-align:top; white-space:normal;word-wrap:break-word; background:#DDD9C3; mso-pattern:auto none; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x30 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:top; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x31 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:general; vertical-align:top; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:1px dotted #000000; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x32 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:top; white-space:nowrap; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x33 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:none; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x34 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:1px dotted #000000; border-right:none; border-bottom:1px dotted #000000; border-left:none; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x35 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:left; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:#008000; mso-pattern:auto none; color:#FFFFFF; font-size:12pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:none; border-right:none; border-bottom:none; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x36 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:left; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:#008000; mso-pattern:auto none; color:#FFFFFF; font-size:12pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x37 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }.x38 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:#008000; mso-pattern:auto none; color:#FFFFFF; font-size:12pt; font-weight:700; font-style:normal; font-family:"Arial","sans-serif"; border-top:none; border-right:none; border-bottom:1px dotted #000000; border-left:1px dotted #000000; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x39 { mso-style-parent:style0; mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; background:auto; mso-pattern:auto; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; border-top:none; border-right:none; border-bottom:1px dotted #000000; border-left:none; mso-diagonal-down:none; mso-diagonal-up:none; mso-protection:locked visible; }.x40 { mso-style-parent:style0; mso-number-format:"0\.00%"; text-align:left; vertical-align:bottom; white-space:normal;word-wrap:break-word; background:auto; mso-pattern:auto; color:#000000; font-size:10pt; font-weight:400; font-style:normal; font-family:"Arial","sans-serif"; mso-protection:locked visible; }--></style><div class="cells-worksheet" data-sheet-number="0" data-sheet-name="Sheet1"><table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;table-layout:fixed;width:1193pt"> <colgroup> <col class="x17" style="mso-width-source:userset;background:none;width:388px"></col> <col class="x18" style="mso-width-source:userset;background:none;width:405px"></col> <col class="x18" style="mso-width-source:userset;background:none;width:401px"></col> <col style="mso-width-source:userset;width:397px"></col> </colgroup> <tbody> <tr style="mso-height-source:userset;height:15.75pt" id="r0"> <td class="x22" style="height:14.25pt;width:291pt">RuleSet</td> <td colspan="3" class="x35">package1</td> </tr> <tr style="mso-height-source:userset;height:14.65pt" id="r1"> <td class="x25" style="height:13.15pt">Import</td> <td colspan="3" class="x40">com.epam.fej.routing.rules.RuleContext,com.epam.fej.routing.drools.GlobalContext</td> </tr> <tr style="mso-height-source:userset;height:14.65pt" id="r2"> <td class="x25" style="height:13.15pt">Variables</td> <td colspan="3" class="x40">GlobalContext gctx</td> </tr> <tr style="mso-height-source:userset;height:13.5pt" id="r3"> <td colspan="4" class="x38" style="border-bottom:1px dotted #000000;height:12pt">RuleTable Rules Routing</td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r4"> <td class="x21" style="height:11.25pt">NAME</td> <td class="x20">CONDITION</td> <td class="x20">CONDITION</td> <td class="x20">ACTION</td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r5"> <td class="x16" style="height:11.25pt"></td> <td class="x33">$event:RuleContext</td> <td class="x34"></td> <td class="x27"></td> </tr> <tr class="x32" style="mso-height-source:userset;height:15pt" id="r6"> <td class="x30" style="height:13.5pt"></td> <td class="x31">eval($event.getMessage().getTagValueAsString(49).equals("$param"))</td> <td class="x31">eval($event.getMessage().getTagValueAsString(35).equals("$param"))</td> <td class="x31">$event.getMessageEvent().setHeader("destination", "$param");</td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r7"> <td class="x19" style="height:11.25pt">NAME</td> <td class="x23">Sender Comp ID</td> <td class="x23">Message type</td> <td class="x24">Set destination</td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r8"> <td class="x26" style="height:12pt">test case 1</td> <td class="x28">sender1</td> <td class="x28">D</td> <td class="x29">session2</td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r9"> <td class="x26" style="height:12.75pt">test case 2</td> <td class="x28">sender2</td> <td class="x28">F</td> <td class="x29">session3</td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r10"> <td class="x26" style="height:12.75pt">test case 3</td> <td class="x28">sender3</td> <td class="x28">D</td> <td class="x29">session1</td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r11"> <td class="x26" style="height:12.75pt"></td> <td class="x28"></td> <td class="x28"></td> <td class="x29"></td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r12"> <td class="x26" style="height:12.75pt"></td> <td class="x28"></td> <td class="x28"></td> <td class="x29"></td> </tr> <tr style="mso-height-source:userset;height:12.75pt" id="r13"> <td class="x26" style="height:12.75pt"></td> <td class="x28"></td> <td class="x28"></td> <td class="x29"></td> </tr> <tr style="mso-height-source:userset;height:14.25pt" id="r14"> <td class="x26" style="height:14.25pt"></td> <td class="x28"></td> <td class="x28"></td> <td class="x29"></td> </tr> <tr style="mso-height-source:userset;height:15.75pt" id="r15"> <td class="x26" style="height:15.75pt"></td> <td class="x28"></td> <td class="x28"></td> <td class="x29"></td> </tr> <tr style="display:none"> <td style="width:291pt"></td> <td style="width:303.75pt"></td> <td style="width:300.75pt"></td> <td style="width:297.75pt"></td> </tr> </tbody></table></div>

Spreadsheet

Enter Package value, check Enabled checkbox and click OK button:

 

image-20240403-184827.png

 

Then add FIX sessions. There are 3 acceptor sessions in our example: session1 (target1-sender1), session2 (target2-sender2) and session3 (target3-session3):

 

image-20240403-184916.png

 

After this, connect to these sessions. Create initiator sessions session1 (sender1-target1), session2 (sender2-target2) and session3 (sender3-target3).

To test Drools, send some message to session1. As a result, session3 will receive this message.

4.2 This example describes mixed DSL/Drools calls.

Add the following business rules configuration:

  1. Routing- Other blocks besides messageRules can be called

  2. Rule1- General Routing based on message type

  3. Rule2- Custom Drools call