This project demonstrates how to organize your project with custom rules for th2-sim.
This project implemented gRPC API, which is described in th2-grpc-sim-template
Fork this project and follow instructions to start your custom project
- Fork th2-grpc-sim-template project and edit proto files if needed.
- Edit dependencies in
build.gradle
file to include all the required libraries with generated gRPC sources. - Edit
rootProject.name
variable insettings.gradle
file. - Edit services classes and their methods
- Edit services file in
META-INF
if needed
Rules consists of two methods:
checkTriggered
- it is used for checking if rule will generate the messageshandle
orhandleTriggered
- it is used for generating outgoing messages
Rules can also use arguments. In order to do this you should use constructor in your custom class.
The rules are divided into 3 types and the only difference between them is the login method for checkTriggered
:
This type contains the most simple logic for check. The rules of this type will be triggered only if the message type and the fields from the incoming message are equals to the values that we had set in the rule.
This type contains the most flexible check conditions. The rules of this type will only be triggered if the message type and the message fields logical functions, which are set in rule, return a true value. The logical functions of the fields in this rule are isolated between each other.
This type contains the most flexible check conditions. The rules of this type will be triggered if your custom logic in method checkTriggered
will return a value equal to true.
If you want to add the possibility of creating a rule via gRPC you should edit th2-grpc-sim-template and class TemplateService.
For adding a rule to simulator you can use the utility method ServiceUtils.addRule
or the method from Simulator
class with the name addRule
. On the gRPC request you should return RuleID
.
On the picture is presented an example of simulator work with the rule TemplateFixRule
enabled. This rule sends an ExecutionReport
message if the income message is a NewOrderSingle
.
If the income message is wrong (not NewOrderSingle
), the rule in simulator will not generate an outgoing message.
If the income message is correct (NewOrderSingle
), the rule will generate one ExecutionReport
.
- Update th2-common to version 3.44.0
- Update bom to version 4.1.0
- Update
kotlin.jvm
to1.6.21
- Updated th2-sim to version 5.2.3
- Update th2-common to version 3.41.1
- Update bom to version 4.0.2
- Add tests examples
- Add Gradle plugin for proto descriptors creation
- Update libraries version
- Update th2-sim to version 3.7.0
- Added
IRuleContext.removeRule()
method which allows a rule to remove itself - Added ability to schedule execution of arbitrary actions via
IRuleContext.execute
methods
- Added
- Update th2-common to version 3.19.0
- Update
th2-grpc-common
andth2-grpc-service-generator
versions to3.2.0
and3.1.12
respectively - Disable waiting for connection recovery when closing the
SubscribeMonitor
- Change the way channels are stored (they mapped to the pin instead of the thread). It might increase the average number of channels used by the box, but it also limits the max number of channels to the number of pins
- Added the property
workers
, which changes the count of gRPC server's threads - Added
session alias
anddirection
labels to incoming metrics - Rework logging for incoming and outgoing messages
- Resets embedded
log4j
configuration before configuring it from a file - Fixed a bug with message filtering by
message_type
- Update