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.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With