Thanks Patrik, I would change it to the example you mentioned without the 
parent. The uniqueness is still only guaranteed to be within a node. For 
any reason if a restart happens for the actor then the id value will be 
different from the original value and I hope that is ok.

Ajmal

On Monday, October 24, 2016 at 11:03:26 AM UTC-5, Patrik Nordwall wrote:
>
> It must be unique. I'd recommend something like this 
> http://doc.akka.io/docs/akka/2.4/scala/cluster-sharding.html#An_Example 
> instead of complicating it with parent.
>
> I think the template needs an update.
>
> /Patrik
> mån 24 okt. 2016 kl. 16:41 skrev Ajmal Babu <[email protected] 
> <javascript:>>:
>
>> What is the right way to define persistenceId in AKKA persistence with 
>> cluster sharding? The activator example provides the below option to create 
>> a persistenceId and I like this option (explained later). 
>>
>>  
>>
>> override def persistenceId: String = self.path.parent.name + "-" + 
>> self.path.name
>>
>>  
>>
>> But, when you refer to akka.persistence.PersistenceIdentity trait the 
>> documentation says below and it concerns me a little bit.
>>
>>  
>>
>> *trait PersistenceIdentity {*
>>
>>  
>>
>> *  /***
>>
>> *   * Id of the persistent entity for which messages should be replayed.*
>>
>> *   */*
>>
>> *  def persistenceId: String*
>>
>>   
>>
>> *  ....*
>>
>>   
>>
>> *}*
>>
>>  
>>
>>  
>>
>> The way I read the above documentations it feels like the ID has to be 
>> really unique including when shard failure and restart of the entity 
>> happens across another node. But if you see the lightbend activator example 
>> it generates unique value which includes a hashed memory address of the 
>> actor. But if the actor gets recreated on another node because of a node 
>> failure the above Id would be still unique within that node, but will have 
>> a different id from the original id, because the hashed portion is 
>> different in the restarted node. Would that be ok? Will the actor gets 
>> restarted and event replayed correctly?
>>
>>  
>>
>> The reason I am asking this question is that I would like to use this 
>> activator style persistenceId definition because when I start the cluster 
>> shard regions in each node during the nodes start up. I would not know 
>> unique persistenceIds of all shard entities. I would only know the shardId 
>> and entityId at runtime from the messages which gets passed into while 
>> accessing the sharded actor. 
>>
>>  
>>
>> The light-bend examples are working correctly with replay of event 
>> sourced data on node failure/restarts. Please advise if it is ok to define 
>> the persistenceId as shown in the light-bend example code?
>>
>>  
>>
>> Note - If that is the case then what would be the significance of the 
>> abstract method persistenceId can’t there be a default implementation that 
>> guarantees uniqueness as shown in light-bend example?
>>
>>  
>>
>> -- 
>> >>>>>>>>>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <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 [email protected].
To post to this group, send email to [email protected].
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