Hi Steve,
have you looked 
at http://doc.akka.io/docs/akka/2.4/scala/cluster-sharding.html? It seems 
well suited to your use case if I understood it correctly.

Cheers,
Rafał

W dniu poniedziałek, 28 listopada 2016 18:24:23 UTC+1 użytkownik Steve 
Winfield napisał:
>
> Hey,
>
> I'm currently programming a room service application which gets a room 
> actor reference from a map (given an id) or creates a new room actor if 
> there is no reference existent. Right now, it works fine because there is 
> only one service. Nevertheless, I want to create a cluster of room services 
> and this is where it begins to get tricky for me.
>
> *I want to ensure that there is only one instance of a room among the 
> services.*
>
> My first attempt:
>
> (Starting up)
> 1. When started, it waits for the CurrentClusterState and sends a 
> "register" message to all given nodes.
> 2. It creates a counter for expected "register" responses to make sure 
> that it doesn't look for existent rooms across the services until it knows 
> about all.
> 3. After getting all responses, it is ready for "get this room" input.
>
> (Fetching rooms)
> 4. When it receives a "get room with id 1" message, it looks for an entry 
> in the local map.
> 5. If it founds one, it's done.
> 6. If it doesn't find it, it sends a "get room with id 1 or avoid creation 
> of it" message across the cluster (the "avoid creation of it" message is 
> sent in order to avoid that another service creates the same room after it 
> was made sure that the room doesn't exist globally).
> 7. Now, it waits for all responses. If there is a room, it sends a "make 
> the room creatable again" message to all services and it's done.
> 8. If it doesn't find it again, it creates the room, adds it to the local 
> map and sends a "make the room creatable again" message to all services.
> 9. (Sends result to requestor)
>
> In my opinion, this solution is way too complicated and it depends too 
> much on the availability of all nodes.
>
> *Is Redis (especially the command https://redis.io/commands/setnx 
> <https://redis.io/commands/setnx>) a good alternative (my second approach)? 
> How would you guys solve this "problem"?*
>
> Thanks!
>
> Cheers,
> Steve Winfield
>

-- 
>>>>>>>>>>      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