Configuring Scheduler
Background and business purpose
Exchanges have business hours and there cannot be possible to keep a session up all the time. We should use scheduling in the case when we need to start or stop our session by timetable.
Overview
FEJ supports two modes of managing sessions:
immediately on the start
postponed by using a cron expression
Managing the timetable can be defined in schedules.xml which is located in the configuration directory.
Deployment and Maintenance
Configuration
The configuration has the following skillet:
<?xml version="1.0" encoding="UTF-8"?>
<schedules xmlns="http://epam.com/fej/schedules">
<schedule id="...">
<task name="..." onLoad="..." timeZone="">
<event cron="..."/>
<properties>
<property key="..." value="..."/>
</properties>
</task>
<task name="..." >
..
</task>
</schedule>
</schedules>
schedule - a group of tasks, related to the schedule
id - ID of the schedule. Required. This parameter can be connected to the name of the endpoint. If it has the same name as an endpoint, then all tasks will be applied to that endpoint. Note that FIX session names are taken from their configuration files by the regexp - " s_fix_(.*)\.properties".
task - there can be several tasks. Possible task properties:
name - a name that defines the task type
Predefined values:
start - a task for starting endpoint
stop - a task for stopping endpointsonLoad - specifies whether a task should be executed during the FIXEdge Java server initialization.
timeZone - time zone for triggering events within this task. Valid values are below.
event - triggers for the task execution.
cron - a cron expression
property - additional properties for the task
Examples
Timetable for a session that should start right after FEJ initialization
The file with the session's parameters has the following name: s_fix_session1.properties
<?xml version="1.0" encoding="UTF-8"?>
<schedules xmlns="http://epam.com/fej/schedules">
<schedule id="session1">
<task name="start" onLoad="true"/>
</schedule>
</schedules>
Note
The attribute "onLoad" set to "true" allows the session to start even in the case when the session property "startOnload" is set to "false"
Timetable for a session that should start at 9 am and stop at 6 pm
The file with the session's parameters has the following name: s_fix_Exchange.properties
<?xml version="1.0" encoding="UTF-8"?>
<schedules xmlns="http://epam.com/fej/schedules">
<schedule id="Exchange">
<task name="start" timeZone="Europe/Samara">
<event cron="0 0 09 ? * *"/>
</task>
<task name="stop" timeZone="Europe/Samara">
<event cron="0 0 18 ? * *"/>
</task>
</schedule>
</schedules>
Triggering routing rules by the scheduler
Scheduler configuration:
<?xml version="1.0" encoding="UTF-8"?>
<schedule id="every10Seconds">
<task name="event" timeZone="Europe/Samara">
<event cron="*/10 * * ? * *"/>
</task>
</schedule>
Rule configuration:
eventRule("Catching scheduler events", SchedulerEvent.class, {
appEvent -> return true//does nothing but there can be additional logic
},
{
schedulerEvent ->
logger.info("I'm rule for schedule events, id - {}.", schedulerEvent.getId())
}
)