Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running akka scheduler only once in a cluster

Tags:

I have configured a Akka scheduler in my play application. It works fine but now the problem is I have two instances of same application running in a cluster. So scheduler is also running twice. I want it to run only once for the overall application. Is there some provision in akka to achieve this. Also java related help will be appreciable.

like image 599
CodeGuru Avatar asked Jun 23 '16 10:06

CodeGuru


1 Answers

For this you will need to use the module Akka Cluster Singleton: http://doc.akka.io/docs/akka/snapshot/java/cluster-singleton.html

This module provides the capability to have only one actor within a whole cluster. The following code explains how to do it in Scala, I think for Java it should be pretty similar:

context.actorOf(ClusterSingletonManager.props(YourScheduler.props, PoisonPill, ClusterSingletonManagerSettings(context.system)), "singletonScheduler")
val singletonScheduler = system.actorOf(ClusterSingletonProxy.props(
  singletonManagerPath = "/user/app/singletonScheduler",
  settings = ClusterSingletonProxySettings(system)),
  name = "singletonSchedulerProxy")
like image 183
hveiga Avatar answered Sep 28 '22 03:09

hveiga