Authors:
Ankit Mehta, Cille Schliebitz, Anita Gu
Changed on:
4 Feb 2025
Workflow Framework Rules are written using Java and contain a specific structure and metadata for describing and validating the Rule. In this lesson, you will learn how to write Rules by adding customised business logic.
Rules, which are written in Java, contain specific structure and metadata for describing and validating the Rule. The steps below should be used to write a Rule:
💡 Let's take a look at an example of a Rule.
For a Java class to be defined, as a Rule, it must implement the com.fluentretail.rubix.v2.rule.Rule interface which defines a class as a Rubix compatible executable Rule. The com.fluentretail.rubix.v2.rule.Rule provides access to the GraphQL API Client.
The Rule interface declares a run method that takes in a Context. To learn more read Rule Development Guidelines & Recommended Practices and the Write your first custom Rule using the Fluent Rules SDK (Hello World) guide.
Context parameter provides access to :
Rules have Actions as an output. These Actions are provided by the Rubix SDK, and handled in a very specific way by the Workflow engine. Actions are not immediately executed synchronously within the Rule's run method. They are simply queued, and executed at the end of the execution context.
context.action().<ActionName> method returns the ActionFactory which provides the supported output actions for a rule.
There are four possible Actions available to your Rules, examples for each Action are provided in the next section:
To learn more read Rule Actions.
To learn more read Rule Actions, Designing Rules, and Event Context.
In this lesson, you will learn about Rule Annotations and different types of Annotations.
Annotations are used to provide additional information. It can be viewed as a tag that represents metadata like Rule class details, params, event attributes, etc.
Describes the metadata for the Rule. It is important to annotate the Rule as accurately as possible.
The information in the Rule Info is used in the following ways:
The Rule Info includes the following properties:
Note: The description property is also used by the Modeller to display form fields for Parameter values. It is important that all parameters defined for the rule via the @Param<Type> annotations are reflected in the description. To learn more read Rule Info Annotation.
An Example is given below:
The EventInfo Annotation describes the Event-specific metadata applicable to either the incoming event (Rule Info accepts property) or the outgoing action event (Rule Info produces property).
The Event Info includes the following properties:
If the Event produced by the Rule should inherit the parent event context, you can set the produces RuleInfo property to the following, and the Rubix Engine will automatically inherit the parent event values at runtime
An Example is given below:
Declaring Event Attributes Required by the Rule:
The Event Attribute type is used to provide configuration guidance to the Workflow, which is used to drive User Actions on the front end. When using a complex event attribute type such as a JSON object, it is helpful to provide a meaningful name for that type to the workflow configurators and frontend developers. Event Attributes are also considered "optional" in that the Rule should validate and handle it if they are not present
The EventAttribute Annotation declares the Event Attributes the Rule requires from the Event.
It contains 2 properties:
An example :
@EventAttribute(name = "EventAttribute1", type = "STRING")
Declaring Rule Parameters Required by the Rule
Parameters are not Event Attributes. Parameters are the configuration of a specific Rule instance within a Ruleset.
For example, the SendEvent Rule contains a string parameter named eventName, which is set during the configuration of the Rule within a Ruleset within a Workflow.
The ParamString annotation:
The ParamString Annotation defines a Parameter for the Rule of type String.
It contains 3 properties:
An example :
@ParamString(name = "ParamString1", description = "Parameter String 1", defaultValue = "PS1")
To learn more read Rules SDK - Event Attributes and Rule Parameters.
An Example is given below:
💡 Let's see an example which illustrates annotations.
The run method is the entry point of the Rule. This is the method where you write the functionality of your Rule. It also provides an instance of the current context into the method to write your rule logic in there.
Below you will find five stages (or phases) that we recommend for you to consider in your run method.
⚠️ You will learn about each run method stage with an example in the following section.
Below is an example of a run method configured with the required stages:
To learn more read The run Method.
Copyright © 2025 Fluent Retail Pty Ltd (trading as Fluent Commerce). All rights reserved. No materials on this docs.fluentcommerce.com site may be used in any way and/or for any purpose without prior written authorisation from Fluent Commerce. Current customers and partners shall use these materials strictly in accordance with the terms and conditions of their written agreements with Fluent Commerce or its affiliates.