What and Why of the Groovy Scripts
The groovy scripts are Groovy files that contain logic and codes to interact with the backend servers. These interactions can be reading and updating records into the backend storage systems.
Execution
The scripts are executed on IntegrationM server, and there are two ways in which the scripts are triggered for execution, they are:
- Message Handler Scripts
- Direct invocation through url endpoints
Message Handler Scripts
Some scripts are only executed when an event occurs on the IntegrationM backend server. When a record is created/deleted/updated in the COB frontend application, the IntegrationM server receives a message informing the creation of the record, and then the IntegrationM runs a set of scripts that are configured to be run upon the arrival of a new message, documentation.
Configuration
In order to configure the groovy scripts to be executed upon the arrival of new events, the developer must include the scritpts in the folder: /server_name/integration/scripts
URL Based Scripts
Some scripts can be executed by the IntegrationM server when a user on the frontend calls specific url endpoints with HTTP/POST method.
The invoked url must be on the format /integrationm/concurrent/<script_name>
Configuration
In order to configure the groovy scripts to be invoked by url, the developer must include them in the folder /server_name/integration/concurrent of the project directory. These scripts are also called concurrent.
Note: the scripts are only different in terms of the situation in which they are called for execution, other than that they behave like any normal groovy file.
Best Practices
A single script should respond to changes in a Definition. Otherwise, it makes it more difficult to reason about the concurrency of the operations.
Be aware of infinite script executions . A script that always changes a value in the instance will generate a new update message every time it runs and will run indefinitely if the initial check conditions are not properly set. Example: if the script always updates a “last update date” field whenever someone changes the instance, then the script should have an initial condition that prevents it from responding to changes made by user integrationm.
GroovyScriptEngine
The IntegrationM server uses the GroovyScriptEngine class to execute the scripts. This is the groovy class which dynamically compiles and loads the groovy files for execution.
