Implemented using cluster sharding also. same problem everything seems to 
work for first request on any node in cluster as i hit second request on 
any node in the cluster it starts fetching data independently. is there a 
different way to get existing actorref in clustered enviornment than from 
normal actorsystem.

On Wednesday, April 12, 2017 at 6:35:30 PM UTC+5:30, Justin du coeur wrote:
>
> Hmm -- I'm not quite sure what you're expecting this to do, but it sounds 
> to me like you're using the wrong tool.  Have you looked into Akka Cluster 
> Sharding yet?  From your problem description, I suspect it's what you 
> should be using...
>
> On Wed, Apr 12, 2017 at 12:38 AM, <jatinde...@spineor.com <javascript:>> 
> wrote:
>
>> It is first time I am implementing akka clustering so I have no prior 
>> experience with that. What We want to acheive with akka clustering is that 
>> when request goes to each node in cluster each node return same instance of 
>> actor (Or actor consist of same data which should just be sum of response 
>> to all requests to all nodes). But what we all getting is all nodes 
>> returning different response containing different data as if they are 
>> working independently. 
>>
>>
>> Here I am sharing some code and configuration and exceptions we are 
>> getting
>>
>> def getOrCreateCartActor(cart_id: UUID): ActorRef = {
>>   var cartActor: ActorRef = null
>>   implicit val timeout = Timeout(50 seconds)
>>   val name = "/user/" + cart_id.toString
>>   val roundRobinPool = RoundRobinPool( nrOfInstances =  4)
>>
>>   val clusterRouterPoolSettings = ClusterRouterPoolSettings( totalInstances 
>> = 4, maxInstancesPerNode = 2,
>>       allowLocalRoutees = true, useRole = None)
>>
>>   val clusterRouterPool = ClusterRouterPool(roundRobinPool, 
>> clusterRouterPoolSettings)
>>
>>   val future = actorSystem.actorSelection("/user/" + 
>> cart_id.toString).resolveOne()
>>
>>
>>   try{
>>   /*try {
>>     println("Everything Ok.")
>>     cartActor = actorSystem.actorOf(ClusterSingletonProxy.props(
>>       singletonManagerPath = "/user/" + cart_id.toString,
>>       settings = ClusterSingletonProxySettings(actorSystem)),
>>       name = cart_id.toString+"Proxy"
>>     )
>>   }catch {
>>     case ex: InvalidActorNameException =>
>>       if(cartActor == null){
>>       println("Everything Not Ok.")
>>       cartActor = actorSystem.actorOf(
>>         ClusterSingletonManager.props(
>>           singletonProps = Props(classOf[CartActor]),
>>           terminationMessage = PoisonPill,
>>           settings = ClusterSingletonManagerSettings(actorSystem)),
>>         //Props[CartActor],
>>         cart_id.toString)
>>     }
>>   }*/
>>     val actorResult = Await.result(future, 50 seconds)
>>     cartActor = 
>> actorSystem.actorOf(clusterRouterPool.props(Props[CartActor]), 
>> cart_id.toString)
>>
>>   }
>>   catch {
>>     case ex: ActorNotFound => {
>>
>>
>>
>>       cartActor = 
>> actorSystem.actorOf(clusterRouterPool.props(Props[CartActor]), 
>> cart_id.toString)
>>     }
>>   }
>>
>>   /*future onComplete {
>>     case Success(v) => {
>>       cartActor = v
>>
>>
>>     }
>>     case Failure(e) => {
>>       //The cart actor no longer exists and must be recreated
>>       cartActor = system.actorOf(Props[CartActor], cart_id.toString)
>>
>>
>>     }
>>   }*/
>>   //Sleep for Actor to be created
>>   cartActor
>>
>>
>> }
>>
>>
>>  As in comments in code you can see I also tried ClusterSingleton and 
>> Cluster Pooling using round robin.
>>
>> Here is configuration :
>>
>> akka {
>>   # "akka.log-config-on-start" is extraordinarly useful because it log the 
>> complete
>>   # configuration at INFO level, including defaults and overrides, so it s 
>> worth
>>   # putting at the very top.
>>   #
>>   # Put the following in your conf/logback.xml file:
>>   #
>>   # <logger name="akka.actor" level="INFO" />
>>   #
>>   # And then uncomment this line to debug the configuration.
>>   #
>>   #log-config-on-start = true
>>
>>   loglevel = DEBUG
>>   loggers = ["akka.event.slf4j.Slf4jLogger"]
>>   logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
>>
>>   actor {
>>     provider = "akka.cluster.ClusterActorRefProvider"
>>     debug {
>>       receive = on
>>       lifecycle = on
>>     }
>>     serializers {
>>       java = "akka.serialization.JavaSerializer"
>>     }
>>
>>   }
>> //  remote {
>> //    log-remote-lifecycle-events = off
>> //    netty.tcp {
>> //      hostname = "127.0.0.1"
>> //      port = 0
>> //    }
>> //  }
>>
>>   remote {
>>     enabled-transports = ["akka.remote.netty.tcp"]
>>     netty.tcp {
>>       hostname = "127.0.0.1"
>>       port = 0
>>     }
>>   }
>>
>>   cluster {
>>     seed-nodes = [
>>       "akka.tcp://application@127.0.0.1:2551",
>>       "akka.tcp://application@127.0.0.1:2552"]
>>
>>
>>
>>
>>     #//#snippet
>>     # excluded from snippet
>>     //auto-down-unreachable-after = 10s
>>     #//#snippet
>>     # auto downing is NOT safe for production deployments.
>>     # you may want to use it during development, read more about it in the 
>> docs.
>>     #
>>     //auto-down-unreachable-after = 10s
>>
>> //    distributed-data {
>> //      # Actor name of the Replicator actor, /system/ddataReplicator
>> //      name = ddataReplicator
>> //    }
>>   }
>>
>>   //akka.extensions = ["akka.cluster.pubsub.DistributedPubSub"]
>>
>> }
>>
>>
>> Then i started nodes using:
>>
>> sbt "run -Dhttp.port=9001 -Dakka.remote.netty.tcp.port=2551"
>> sbt "run -Dhttp.port=9002 -Dakka.remote.netty.tcp.port=2552"
>> *and main server with*
>> sbt run
>>
>> and then the exception i am getting is:
>>
>> [error] application - 
>>
>> ! @73ji7p2o9 - Internal server error, for (POST) [/addToCart] ->
>>  
>> play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution 
>> exception[[InvalidActorNameException: actor name 
>> [1876845a-01d5-4f15-b7f7-abe49ba6e689] is not unique!]]
>>         at 
>> play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293)
>>         at 
>> play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220)
>>         at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
>>         at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
>>         at 
>> play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:100)
>>         at 
>> play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
>>         at 
>> play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
>>         at 
>> scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344)
>>         at 
>> scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343)
>>         at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
>> Caused by: akka.actor.InvalidActorNameException: actor name 
>> [1876845a-01d5-4f15-b7f7-abe49ba6e689] is not unique!
>>         at 
>> akka.actor.dungeon.ChildrenContainer$NormalChildrenContainer.reserve(ChildrenContainer.scala:129)
>>         at 
>> akka.actor.dungeon.Children$class.reserveChild(Children.scala:130)
>>         at akka.actor.ActorCell.reserveChild(ActorCell.scala:374)
>>         at akka.actor.dungeon.Children$class.makeChild(Children.scala:268)
>>         at 
>> akka.actor.dungeon.Children$class.attachChild(Children.scala:46)
>>         at akka.actor.ActorCell.attachChild(ActorCell.scala:374)
>>         at akka.actor.ActorSystemImpl.actorOf(ActorSystem.scala:729)
>>         at 
>> services.CartService.getOrCreateCartActor(CartService.scala:179)
>>         at services.CartService.routeMessagesToCart(CartService.scala:82)
>>         at services.CartService.getCart(CartService.scala:42)
>>
>> Please let me know if i am missing something.
>>
>>
>> -- 
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to akka-user+...@googlegroups.com <javascript:>.
>> To post to this group, send email to akka...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to