Best Practices and Variables in Aletyx Enterprise Build of Kogito and Drools 10.0.0¶
General Best Practices¶
A key rule of thumb when designing processes in Aletyx Enterprise Build of Kogito and Drools is: Don’t embed code in your process, except for debugging purposes.
- If you need to interact with code, use Service Tasks.
- For interactions with the Rule Engine, use the Business Rules Task node.
- Avoid embedding code directly in OnEntry, OnExit, or Script Tasks, as this makes testing and maintenance significantly more difficult.
Understanding Variables in Aletyx Enterprise Build of Kogito and Drools¶
Variables in Aletyx Enterprise Build of Kogito and Drools can be complex, and understanding their behavior is crucial to avoiding unexpected issues.
Key Considerations:¶
-
Copy vs. Direct Access: While you have direct access to variables in scripts, OnEntry, or OnExit actions, you're actually interacting with a copy of the variable, not the original. Any modifications you make here will not be reflected in the process.
-
Updating Variables Properly: To change a variable’s value effectively, use the kcontext system variable:
This ensures that the actual process variable is updated.
-
User Task Variable Synchronization: When interacting with User Tasks, variables are copied to the user task system. This means that until the user task is fully completed, the process variable and the corresponding user task variable might have different values.
-
Handling Null Variables: Variables may start in a
null
state, especially when used in gateways. This can lead to NullPointerException (NPE) issues. - One common cause is that a variable may not be updated until the process reaches a certain point.
-
To avoid NPEs, use null-safe condition checks, such as:
-
Keep Process Variables to a Minimum: A process is not a system of record—it should not store large amounts of data.
- If you need to process large data sets, store only IDs and retrieve the required data from an external database or system just before use.
- Once the data is no longer needed, release it to minimize memory usage and improve performance.
- Exception:
- In rules orchestration, which is typically stateless, loading all necessary data into the process for rule evaluation is acceptable and does not pose an issue.
Variable Tags in Aletyx Enterprise Build of Kogito and Drools¶
In the Aletyx Enterprise Build of Kogito and Drools, the concept of tags for variables is introduced, providing additional control over their behavior:
Tag | Description |
---|---|
internal | Hides the variable from the exposed REST model and is used only within a process instance. |
required | Ensures the variable is mandatory when starting a process instance. Missing this variable results in a VariableViolationException . |
readonly | Allows the variable to be set only once. Modifying it later causes a VariableViolationException . |
input | Marks the variable as an input-only value, preventing it from being returned in REST responses. |
output | Marks the variable as output-only, meaning it is not expected during process start but is included in REST responses. |
business-relevant | Indicates that the variable is relevant for business monitoring or external applications. |
tracked | Tracks changes to the variable and generates events, publishing them to the kogito-variables-events topic. (not working on 10.0.0) |
By following these best practices and understanding variable behaviors, you can build maintainable and testable projects with Aletyx Enterprise Build of Kogito and Drools.