Created
May 8, 2014 22:09
-
-
Save bhudgeons/78cc89fb6be47ff1c975 to your computer and use it in GitHub Desktop.
Demonstration of Akka Cluster Singleton Communication Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sample.cluster.simple | |
import com.typesafe.config.ConfigFactory | |
import akka.actor.ActorSystem | |
import akka.actor.Props | |
import akka.actor._ | |
import akka.contrib.pattern.ClusterSingletonManager | |
import akka.contrib.pattern.ClusterSingletonProxy | |
class MyClusterActor extends Actor { | |
def receive = { | |
case msg => { | |
println("MyClusterActor got *" + msg + "* from " + sender().path) | |
sender() ! "Here's a response from MyClusterActor" | |
} | |
} | |
} | |
case class Start(actor: ActorRef) | |
class MyRemoteActor extends Actor { | |
def receive = { | |
case Start(actor) => { | |
println("MyRemoteActor got Start with " + actor.path) | |
actor ! "Hello from RemoteActor" | |
} | |
case msg => { | |
println("MyRemoteActor got *" + msg + "* from " + sender().path) | |
} | |
} | |
} | |
object RemoteSystem { | |
val remoteConfig = ConfigFactory.parseString("akka.actor.provider=\"akka.remote.RemoteActorRefProvider\""). | |
withFallback(ConfigFactory.parseString("akka.remote.enabled-transports=[\"akka.remote.netty.tcp\"]")). | |
withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.hostname=\"127.0.0.1\"")). | |
withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.port=2551")) | |
val remoteSystem = ActorSystem("RemoteSystem", remoteConfig) | |
val remoteActor = remoteSystem.actorOf(Props[MyRemoteActor], "myremoteactor") | |
val clusterConfig = ConfigFactory.parseString("akka.actor.provider=\"akka.cluster.ClusterActorRefProvider\""). | |
withFallback(ConfigFactory.parseString("akka.remote.enabled-transports=[\"akka.remote.netty.tcp\"]")). | |
withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.hostname=\"127.0.0.1\"")). | |
withFallback(ConfigFactory.parseString("akka.cluster.seed-nodes=[\"akka.tcp://[email protected]:2553\"]")). | |
withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.port=2552")) | |
val clusterSystem = ActorSystem("ClusterSystem", clusterConfig) | |
val clusterActor = clusterSystem.actorOf(ClusterSingletonProxy.props( | |
singletonPath = "/user/myclusteractor/active", | |
role = None), | |
name = "MyClusterActor") | |
} | |
object ClusterSystem { | |
val clusterConfig = ConfigFactory.parseString("akka.actor.provider=\"akka.cluster.ClusterActorRefProvider\""). | |
withFallback(ConfigFactory.parseString("akka.remote.enabled-transports=[\"akka.remote.netty.tcp\"]")). | |
withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.hostname=\"127.0.0.1\"")). | |
withFallback(ConfigFactory.parseString("akka.cluster.seed-nodes=[\"akka.tcp://[email protected]:2553\"]")). | |
withFallback(ConfigFactory.parseString("akka.remote.netty.tcp.port=2553")) | |
val clusterSystem = ActorSystem("ClusterSystem", clusterConfig) | |
clusterSystem.actorOf(ClusterSingletonManager.props(Props(classOf[MyClusterActor]), "active", | |
PoisonPill, None), "myclusteractor") | |
def setup() = println("Setting up ClusterSystem") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tip: scala supports: