Reputation: 341
I've been looking at WSO2 task execution, and it seems one can set up simple schedules (e.g. using cron-like schedules) for task execution. However, how would I ensure in a cluster that the task gets scheduled once only per cluster, and not once on each node?
Upvotes: 0
Views: 1171
Reputation: 71
This is supported in wso2 ESB 4.9.0 (to be released). But for earlier versions you can use a workaround based on Hazelcast leader node.
<script language="js">
importPackage(Packages.com.hazelcast.core);
importPackage(Packages.java.util);
iter = Hazelcast.getAllHazelcastInstances().iterator();
if( iter.hasNext() ) {
instance = iter.next();
isLeader = instance.getCluster().getMembers().iterator().next().localMember();
mc.setProperty("isLeader", isLeader);
} else {
mc.setProperty("isLeader", "true");
}
</script>
More details can be found here
Within the proxy service or sequence, you can execute the task only in the leader node. Drop the message on other nodes. Scheduled task will be executed on all the nodes, but the actual task written in the sequence or proxy service will be executed only in one node. This method can handle node crashes new node additions and removals to the cluster.
Upvotes: 1
Reputation: 857
You can achieve this with the "pinnedServers" attribute of the WSO2 ESB Scheduled task.
In your scheduled task you will see the pinnedServers attribute when you are creating the Scheduled Task.
Purpose of this pinnedServers attribute is to limit the deployment of scheduled tasks in a clustered environment.
You can provide the list of hostnames of WSO2 ESB instances (separated by "," ) in your clustered environment you want to deploy your Scheduled task and the scheduled task will be deployed only on those WSO2 ESB instances.
Therefore in your case, you can specify the hostname of one of the WSO2 ESB instances in your clustered environment and scheduled task will only deployed in that WSO2 ESB instance and thus only once per your WSO2 ESB cluster.
Make sure to modify the "SynapseConfig.ServerName" parameter in the axis2.xml of your WSO2 ESB instances with their respective hostname.
E.g:
<parameter locked="false" name="SynapseConfig.ServerName">host1.wso2.org</parameter>
Thanks and Regards,
Harshana
Upvotes: 1