add Role to SingletonManagerFactory
Closed this issue · 0 comments
AndreyLadniy commented
I try use scenario: start simple cluster seed (cluster monitor) and after join nodes with business logic. But Receptor in Headquarters did not receive messages, because of "The singleton actor is always running on the oldest member with specified role." (first node have no implementation for ClusterSingletonManager
). One of the way is ClusterSingletonManagerSettings.withRole
use (like in ShardingSupport
)
trait SingletonSupport {
implicit def singletonManagerFactory[A <: BusinessEntity : LocalOfficeId](implicit as: ActorSystem): SingletonManagerFactory =
new SingletonManagerFactory(implicitly[LocalOfficeId[A]].department)
}
class SingletonManagerFactory(role: String)(implicit system: ActorSystem) extends CreationSupport {
override def getChild(name: String): Option[ActorRef] = throw new UnsupportedOperationException
override def createChild(props: Props, name: String): ActorRef = {
val singletonManagerName: String = s"singletonOf$name"
val managerSettings = ClusterSingletonManagerSettings(system).withSingletonName(name).withRole(role)
system.actorOf(
ClusterSingletonManager.props(
singletonProps = props,
terminationMessage = PoisonPill,
managerSettings
),
name = singletonManagerName)
val proxySettings = ClusterSingletonProxySettings(system).withSingletonName(name)
system.actorOf(
ClusterSingletonProxy.props(
singletonManagerPath = s"/user/$singletonManagerName",
proxySettings),
name = s"${name}Proxy")
}
}