These are chat archives for akkadotnet/akka.net

27th
Dec 2017
Tomas Lautaro Lopez
@Sokal21
Dec 27 2017 12:38
Hi everyone, I have a cuestion about sharding in Akka.Cluster. How can EntityID are assing to an entity in a sharding region? Because I cannot understand how in this example https://github.com/akkadotnet/akka.net/blob/dev/src/examples/Cluster/ClusterSharding/ClusterSharding.Node/Program.cs messages are being send to an entity that I dont know when was created
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 13:22
@Sokal21 cluster sharding manages entity creation, if a message is send to an entity, that didn't exist, it will be created on demand.
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 13:36
@Horusiath I got StackOverflowException using actor CE (no try...finally or try..with were used). Now I removed all CEs and will wait for the exception to appear :( Can I be 200% sure that, using actorOf/actorOf2 exclusively, the stack wont overflow, never?
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 13:41
@vasily-kirichenko I can only say I've never managed to cause actorOf variants to stack overflow. I easy to miss what computation expressions actually build on output - that's why I've missed the case with try/with within an actor { }
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 13:47
@Horusiath I wrote a blog post about SO in CEs some time ago http://vaskir.blogspot.ru/2013/02/recursion-and-trywithfinally-blocks.html :)
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 13:53
good to know, thanks :)
Tomas Lautaro Lopez
@Sokal21
Dec 27 2017 14:25
@Horusiath okey, is imposible to set this ID? Anyway, shards are not being created or at least Im not being able to comunicate with it
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 14:27
@Sokal21 you're setting this ID when constructing the message (and later on when defining message extractors for ShardId and EntityId)
Usually you shouldn't communicate with shards directly (maybe only when you're actually querying them).
Tomas Lautaro Lopez
@Sokal21
Dec 27 2017 14:29
@Horusiath I'm folowing that example and it use shardRegion.Tell(new ShardEnvelope(message.UserID, message))
thats is not working for me, and actors are not automatically created by sharding
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 14:30
probably you're using the example where HashCodeMessageExtractor is used - in that case ShardId is computed, based on the hash code generated from entityId passed
if you're entities are not created automatically, what errors do you get?
Tomas Lautaro Lopez
@Sokal21
Dec 27 2017 14:32
yes im using HashCodeMessageExtractor

I dont get any error, and this is how Im startin the sharding region

IActorRef shardRegion = sharding.Start(
typeName: "SessionActor",
entityProps: Props.Create<SessionActor>(),
settings: ClusterShardingSettings.Create(ShardingInitiater),
messageExtractor: new MessageExtractor(20)
);

algo, SessionActor sould be created with an argument that is UserID
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 14:38

algo, SessionActor sould be created with an argument that is UserID

It won't be - all actors managed by sharding will always be created straight from the Props, you've passed to entityProps param. If you want to get their EntityId, you can use actor path for that - all sharded actors paths follows the pattern /user/sharding/<typeName>/<shardId>/<entityId>: so to get EntityId (in your case UserID), simply call Self.Path.Name.

If you want to know how sharding works in general, I've written two blog posts on that:
  1. Introduction
  2. Something more in-depth
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 19:26
@Horusiath do I understand correctly that the only way to have typed receiver is passing IActorRef<_> in the message?
a <! Request ("foo", replayTo)
I mean you can send anything to m.Sender() <! "bar"
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 19:27
@vasily-kirichenko you mean typed sender? Yes
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 19:27
yes
so, the same pattern as in MailboxProcessor
and in typed akka ;)
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 19:27
yes, and in Erlang ;)
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 19:27
just read that in the docs
;)))
Bartosz Sypytkowski
@Horusiath
Dec 27 2017 19:28
IMHO this is the right design decision (maybe there only should be some simplification for that for the sake of request/response pattern)
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 19:28
followed by your links above and discovered a lot of great blog posts. wow. thanks
I doubt about selection actors by path. Is it useful at all? In what scenarios (I guess for remoting/cluster only)?
Aaron Stannard
@Aaronontheweb
Dec 27 2017 19:30
@vasily-kirichenko can be useful when you're trying to probe an actor hierarchy from the outside
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 19:31
I mean the address is just a string and you can easily select not existing actor.
Aaron Stannard
@Aaronontheweb
Dec 27 2017 19:31
I use the wildcard actor selections to build the actor hierarchy visualizer here: https://cmd.petabridge.com/articles/commands/actor-commands.html#actor-hierarchy
i.e. akka://MySys/user/* will get all of the top-level children
and so forth
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 19:32
ah, I remember I've tried it.
I see.
Aaron Stannard
@Aaronontheweb
Dec 27 2017 19:32
yeah, so aside from remoting and clustering when you use the ActorSelection to fetch a reference to an actor
that wild-card actor selection is the other big use case
Vasily Kirichenko
@vasily-kirichenko
Dec 27 2017 19:33
ah. ok. so if all my actors are in a single node, I should always pass IActorRef explicitly, like DI?