I finally found the solution. There is hardly any documentation or examples 
out there for this scenario. I have the checked in a sample on my github 
location, feel free to check out the solution. I have used the user role 
approach to resolve this issue.

https://github.com/sdab75/microservices-akka-cluster-sharding


Thanks,
SD

On Monday, November 16, 2015 at 3:39:36 PM UTC-5, sd d wrote:
>
>
> Hello,
>
> I found a solution but it won't work for microservice kind of setup. But 
> it might useful, for others who are trying to use Akka sharding in 
> monolothic applications. Please let me know if you guys find any other 
> alternatives.
>
> Essentially, the only way sharding between multiple services work if I 
> start sharding regions of all services that are participating in the 
> services communication. And the service that has the start of all regions 
> should start as seed-0-node otherwise your shard regions won't get stored.
>
> In other words, my Abc service has to start not only its own set of 
> sharding entities and supervisors but also the sharding entities and 
> supervisors of Def service.
>
> To prove this, I wrote another simplified example (my earlier example was 
> with spring-boot). I shared the POC in github.
>
> https://github.com/sdab75/multi-services-cluster-sharding
>
> If you run the above code you will be to re-create the problem. However if 
> you want to see successful service communication then you have to start all 
> shard regions.
>
> In other words, both AbcService and DefService must start all 4 regions. 
> Since my AbcServic runs on 2550 (seed-0) it will start all 4 regions.
>
>             // Create an Akka system
>             ActorSystem system = ActorSystem.create("ClusterSystem", 
> config);
>             ClusterShardingSettings settings = 
> ClusterShardingSettings.create(system);
>             ClusterSharding.get(system).start("AbcEventStoreSupervisor", 
> Props.create(AbcEventStoreSupervisor.class), settings,messageExtractor);
>             ClusterSharding.get(system).start("AbcEventStore", 
> Props.create(AbcEventStore.class), settings,messageExtractor);
>             ClusterSharding.get(system).start("DefEventStoreSupervisor", 
> Props.create(DefEventStoreSupervisor.class), settings, messageExtractor);
>             ClusterSharding.get(system).start("DefEventStore", 
> Props.create(DefEventStore.class), settings, messageExtractor);
>
> If you don't do the aforementioned way, then the other service will never 
> find the shard regions of service and complains with the following error.
>
> [WARN] [11/15/2015 14:24:46.816] 
> [ClusterSystem-akka.actor.default-dispatcher-25] [akka.tcp://
> ClusterSystem@127.0.0.1:2552/system/sharding/defEventStoreSupervisor] 
> Trying to register to coordinator at
>  [Some(ActorSelection[Anchor(akka.tcp://ClusterSystem@127.0.0.1:2550/), 
> Path(/system/sharding/defEventStoreSupervisorCoordinator/singleton/coordinator)])],
>  
> but no acknowledgement. Total [1] buffered m
> essages.
>  
>
> If this how akka cluster sharding works, then it will not work in 
> microservices kind of project because in microservices world one service 
> should never know the other service persistent actors or sharding regions.
>
> Event persistence is very fundamental aspect of our project and does any 
> of think there is another way to solve this issue.
>
> Thanks,
> SD
>
> On Sunday, November 15, 2015 at 2:08:54 PM UTC-5, sd d wrote:
>>
>> *Hello,*
>>
>>
>> *Source Code:*
>>
>> https://github.com/sdab75/spring-boot-akka-cluster-sharding
>>
>>
>> *Scenario:*
>>
>>
>>    1. Abc and Def are 2 micro services and they communicates with each 
>>    other through their respective Async Event Listeners ( these are 2 
>> services 
>>    are in the same cluster because they need to communicate with each other).
>>    2. Each microservice set up the following way.
>>    - Akka-PubSub-Listener to consume event topic.
>>       - And the Listener uses EventStoreSupervisor sharded region to 
>>       hand over the request to the  respective EventStoreActor which stores 
>> the 
>>       validated event and further publish event for other microservice.
>>       
>> *Issue:*
>>
>>
>>    1. Since these micro services (Abc and Def) does different things I 
>>    need to have to corresponding message extractors and sharded regions. But 
>>    when I start these micro services in the same cluster, only the first 
>> seed 
>>    node corresponding sharded region and coordinator gets created and 
>> started.
>>    - Example:
>>          - If Abc service is on 2550 and Def on 2551. I only see sharded 
>>          region and coordinator created for Abc microservice.
>>          - If I put Def on 2550 then I can see Def corresponding 
>>          coordinator and region created.
>>       
>> The only way to create different sharded regions and coordinators is to 
>> put them on different clusters (i.e) each microservice will have its own 
>> cluster setup. If I do this then microsevice’s can’t communicate with each 
>> because they are not part of the same cluster.
>>
>>
>> How do I resolve this issue? I need persistence for my received events. 
>> What is recommended paradigms in akka for this scenario. I am relatively 
>> new to the akka world, please let me know if my understanding is incorrect 
>> on akka cluster sharding.
>>
>>
>> Thanks,
>>
>> SD
>>
>>
>>

-- 
>>>>>>>>>>      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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to