Generic rule executer receives a message from the Event-Director and determines a result for a rule in a typology.
- PostgresQL: Database Management
- NATS: Message queue
- Redis: Redis
You also need NodeJS to be installed in your system. The current LTS should be suitable. Please open an issue if the application fails to build on the current LTS version. Unix platforms, you should be able to find nodejs in your package manager's repositories.
git clone https://github.com/tazama-lf/rule-executer
cd rule-executerYou then need to configure your environment: a sample configuration file has been provided and you may adapt that to your environment. Copy it to .env and modify as needed:
cp .env.template .envA registry of environment variables is provided to provide more context for what each variable is used for.
npm i
npm run build
npm run startA message received from CRSP:
{
metaData: { traceParent: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" }, // https://www.w3.org/TR/trace-context/#examples-of-http-traceparent-headers
transaction: { TxTp: "pacs.002.001.12", "FIToFIPmtSts": { /* Pacs002 */ } },
networkMap: { /* Network Map */ },
DataCache: { /* cached data relevant to the transaction */ }
};sequenceDiagram
participant A as TMS API
participant B as NATS<br>(event-director)
participant C as EVENT<br>DIRECTOR
participant D as NATS<br>(sub-rule-*)
A->>B: Publish message
B->>+C: Read message
C->>C: handleTransaction()
C->>-D: Publish message/s
graph TD;
start[Start] -->|Start| parseRequest;
parseRequest -->|Success| startTransaction;
parseRequest -->|Failure| logError1[Log Error];
startTransaction -->|Success| getRuleConfig;
startTransaction -->|Failure| logError2[Log Error];
getRuleConfig -->|Success| executeRuleLogic;
getRuleConfig -->|Failure| handleErrorResponse[Handle Error Response];
executeRuleLogic -->|Success| sendResponse;
executeRuleLogic -->|Failure| handleErrorResponse;
handleErrorResponse -->|Success| End[End];
handleErrorResponse -->|Failure| End;
sendResponse -->|Success| End;
sendResponse -->|Failure| handleErrorResponse;
The output is the input with an added RuleResult:
{
metaData: { traceParent: "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01" }, // https://www.w3.org/TR/trace-context/#examples-of-http-traceparent-headers
transaction: { TxTp: "pacs.002.001.12", "FIToFIPmtSts": { /* Pacs002 */ } },
networkMap: { /* Network Map */ },
DataCache: { /* cached data relevant to the transaction */ },
ruleResult: { /* rule result */ }
};
```Z
## publishing your rule as a library
Make sure you have a index.ts in the root of your rule that is exporting your `handleTransaction` method:
`export { handleTransaction }`
Ensure the "name" property in your package.json starts with your organization name, eg: `"name": "@tazama-lf/rule-901",`
Ensure the Package.json has the following:
```json
"publishConfig": {
"@tazama-lf:registry": "https://npm.pkg.github.com/"
},To test a rule in the executer will be a two-step process. Firstly, pack your rule's code to a library on your machine, then install the Rule in the executor.
- From Rule-xxx run:
npm run buildto make sure you've got the latest code built to publish Followed bynpm packto create a tarball with the library artifacts. This will make a file with the extension.tgzcontaining the package version in the name - From Rule Executer run (
rule-xxxneeds to be the name as specified in the above rule's package.json). An example:npm i rule@file:../rule-901/tazama-lf-rule-901-1.2.0.tgz
Now you can run your rule engine and it will call the handleTransaction method from your desired Rule Processor. You'll be able to step into the method call while debugging.
The Jenkins job will have to call a packaged library. So the rule in the package.json will have to be installed as follows:
- Firstly remove the current
rulereference:npm uninstall rule - Then install the expected release version of the
rule-processorlib:npm i rule@npm:@tazama-lf/rule-901@latest
Furthermore, from Jenkins we'll also need to modify the rule-executer-deploy.yml file, to give the processor the correct name, as well as make sure it points to your library (note the above install / uninstall SED functions also in below script):
// Modify below lines to give the correct name for your Rule:
sh 'sed -i \'s/off-rule-executer/off-rule-901/g\' rule-executer-deploy.yml'
sh 'sed -i \'s/RULE_NAME="901"/RULE_NAME="901"/g\' Dockerfile'
withNPM(npmrcConfig: 'guid') {
// Modify below line to give the correct library for your Rule (eg, change rule-901 to whatever your rule package is called):
sh 'sed -i \'s/RUN npm install/COPY .npmrc .npmrc\\nRUN npm uninstall rule\\nRUN npm i rule@npm:@tazama-lf\\/rule-901@latest\\nRUN npm install/g\' Dockerfile'
}
- Application will not build when a rule is added as a dependency
- Ensure
frms-coe-libis on the same version on therule-executorand therule-lib
- Ensure