Page tree
Skip to end of metadata
Go to start of metadata

Overview

FIX Edge Java provides an RoutingRule unit as an abstraction for internal message routing element. FEJ supports pure Java and Groovy implementations for routing rules.

Groovy routing rules are flexible mechanism that allows to implement custom logic for messages transformation. 

The rules of routing and transformation can be embedded in a rules.groovy file:

rules.groovy
[
        new RoutingRule(
                // rule description
                "some Rule",
                //source filter - ignore for this rule
                null,
                // context filter - apply this rule for New Order - Single (D) messages
                { ctx -> ctx.getMessage().getTagValueAsString(35) == "D" } as RuleCondition,
                // action for rule - resend message to all session within same group
                // and stop message processing
                { ctx ->
                    rc.getDestinationsByGroup(ctx.sourceParams.groups).each { adapter ->
                        adapter.send(ctx.message)
                        ctx.exit()
                    }
                } as RuleAction),

        // append system rejection rules for not processed messages
        getRejectionRule(routingContext)
]

Groovy routing rules syntax

RoutingRule requires few components for its instantiation:

public RoutingRule(java.lang.String description, SourceCondition sourceFilter, RuleCondition contectFilter, RuleAction action)
  • description - String with free test description of rule

  • source filter - check if this rule should be applied to messages from certain source. This filter was added as a separate with propose of optimization process. Such filter can by applied on static basis without addition affect in runtime. Source filter is SourceCondition implementation and can be null if you’d like to ignore it.

  • context filter - dynamic filter, which can check in the same time appliance of this rule depends on message content and source attributes. Context filter is RuleCondition implementation and can be null if you’d like to ignore it.

  • action - implementation of RuleAction which describes the main goal of this rule. It can be transformation, modification or just resending to required destination.


RuleDescription

Free text description of rule.

			// rule description
                "some Rule",


SourceCondition

It returns True or False.

 			//source filter - ignore for this rule
                null,


Possible values:

ParameterType
getId()String
getSource();Object
getTargetCompId()String
getTargetLocationId()String
getTargetSubId()String
getSenderCompId()String
getSenderLocationId()String
getSenderSubId()String


RuleCondition

It returnes True or False

Example:

If MsgType = 'D' i.e. New Order - Single (MsgType=D), then the condition will return true, otherwise false.

			// context filter - apply this rule for New Order - Single (D) messages
                { ctx -> ctx.getMessage().getTagValueAsString(35) == "D" } as RuleCondition,
  1. The variable msgCtx used to access to the content in this case. 

    Possible methods:

    Methods

    public FIXFieldList getMessage() {
    return event.getMessage();
    }

    public MessageEvent getMessageEvent() {
    return event;
    }

    public EndpointParams getSourceParams() {
    return sourceParams;
    }

    public void exit() {
    this.exit = true;
    }

    public boolean isExit() {
    return exit;
    }

    public StorageManager getContextManager() {
    return contextManager;
    }

  2. The variable msg using getMessage () method will receive a FIX message.
  3. The variable Header is used to handle the header of FIX message. The MsgType attribute contains values from a FIX tag 35=MsgType. The getTagValueAsString() method is used to get a FIX field value by FIX tag number.

RuleAction

Defines the actions that will apply to the messages that correspondes to the SourceCondition and RuleCondition filters. 

Example:

			// action for rule - resend message to all session within same group
            // and stop message processing
                { ctx ->
                    rc.getDestinationsByGroup(ctx.sourceParams.groups).each { adapter ->
                        adapter.send(ctx.message)
                        ctx.exit()
                    }
                } as RuleAction),

Groovy routing rules "helpers" methods

NameDefinitionDescriptionExample
generateUniqueIdString generateUniqueId()returns UUID that is generated using a cryptographically strong pseudo random number generator.

def id = generateUniqueId()

stringValueString stringValue(FIXFieldList msg, int tag)returns string representation of value by provided tag

def destination = stringValue(msg, Header.DeliverToCompID)

rule

RoutingRule rule(String description, SourceCondition sourceCondition, RuleCondition condition, RuleAction action)

short version for creating RoutingRule


rule

RoutingRuleBuilder rule(String description)


rule builder for creating RoutingRule

rule(description)
.sourceCondition(params -> {....})
.condition(msgCtx -> {....})
.action(msgCtx -> {....})
.build()


removeRepGroupvoid removeRepGroup(FIXFieldList msg, int leadingTag, int groupTags[])removes the list of tags that corresponds to the repeating group. 

removeRepGroup(msg, 453, [452, 448, 447])

sendvoid send(RoutingContext rc, RuleContext ruleContext, String targetCompId)sends a message to the session by provided targetCompId

send(routingContext, msgCtx, destination)

sendvoid send(RoutingContext rc, RuleContext ruleContext, String targetCompId, String qualifier)sends a message to the session by provided targetCompId and sessionQualifier

send(routingContext, ctx, destination, qualifier)

Import of the classes

It is not necessary to import classes directly in the groovy.rules file. The classes are described in the fej-routing.xml.

fej-routing.xml
    <util:list id="imports" value-type="java.lang.String">
        <value>com.epam.fej.context.Storage</value>
        <value>com.epam.fej.context.StorageManager</value>
        <value>com.epam.fej.routing.RoutingContext</value>
        <value>com.epam.fej.routing.rules.RoutingRule</value>
        <value>com.epam.fej.routing.rules.RuleAction</value>
        <value>com.epam.fej.routing.rules.RuleCondition</value>
    </util:list> 
  • No labels