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

This section describes Groovy message routing and event processing rules.


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

The Groovy routing rules are a flexible mechanism that allows implementing custom logic for message transformation and handling events. 

The rules can be embedded in the rules.groovy file:

                // rule description
                "some Rule",
                //source filter - ignore for this rule
                // 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 ->
                    routingContext.getDestinationsByGroup(ctx.sourceParams.groups).each { adapter ->
                } as RuleAction),
		eventRule("Catching session events", FIXSessionStateEvent.class, {
                appEvent ->
                    return true //do nothing but there can be additional logic
                	sessionStateEvent ->
                    	def sessionName = sessionStateEvent.getSessionId()
           "Session '{}' has been started.", sessionName)

The example represents two different types of rules, namely, the MessageRoutingRule and the EventRoutingRule.

"Helpers" methods for routing rules

There is a static class with methods that are named "helpers". These methods help an end-user make logic shorter by encapsulating details inside the methods.

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 a string representation of the value provided by the tag


def destination = stringValue(msg, Header.DeliverToCompID)


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

Short version for creating MessageRoutingRule


RoutingRuleBuilder messageRule(String description)

Rule builder for creating MessageRoutingRule

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


EventRoutingRuleBuilder eventRule(String description)

Rule builder for creating EventRoutingRule

.condition(event -> {....})
.action(event -> {....})

eventRuleRoutingRule eventRule(String description, Class<AppEvent> eventType,
Predicate<AppEvent> ruleCondition, Consumer<AppEvent> ruleAction)

Short version for creating EventRoutingRule

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 the 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. Imported classes are described in the fej-routing.xml. The values below are predefined and can be extended by custom ones so not to specify imports in the rules.

	<util:list id="imports" value-type="java.lang.String">

Injected properties

These beans are available for use in the Groovy rule.

<property name="additionalProperties">
	<map key-type="java.lang.String">
    	<entry key="routingContext" value-ref="routingContext"/>
        <entry key="storageManager" value-ref="storageManager"/>
        <entry key="storageManager" value-ref="messageEventPool"/>

Additional info

  • No labels