-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] - RemoteActorRef.lookup_or_spawn #94
Comments
This sounds like it implies that you want the actor to be running on all nodes in the swarm? Currently, there's no way of spawning an actor on a specific remote node as I haven't found much of a reason to add this into the core of kameo, and could be accomplished in user land via messaging. Is what you're suggesting any different to the following? let actor_ref = match RemoteActorRef::<MyActor>::lookup("my-actor").await? {
Some(actor_ref) => actor_ref,
None => {
let actor_ref = kameo::actor::spawn(MyActor);
actor_ref.register("my-actor").await?;
actor_ref
}
}; The code snippet above returns |
This is probably fine. It's what I ended up doing. I wrote this ticket after a long week at work and realized afterwards that I was being stupid while working on my own stuff. But thank you for taking the time to reply :) |
No worries! I also have just made a PR which should be of use for this use case: #100 |
Feature Description
Instead of performing a lookup and receiving a result or Some/None, I should be able to call lookup_or_spawn which will lookup the given actor or force that actor to spawn (either locally or on a remote node) and give back the RemoteActorRef to the newly spawned actor.
Motivation
Let's suppose we have a order management system where a Shop is represented as an actor and can force an Order (represented by an actor) to spawn on another service that manages these order actors. I should be able to either get an existing Order actor already running or spawn a new actor (with a specific id/name).
Proposed Solution
If you have an idea of how to implement this feature, please provide a high-level overview of the solution.
There should be a message (not sure if it should be broadcast with a lease/claim type setup) propagated over libp2p to connected peers to spawn the actor if it isn't registered in the cluster already. Potentially that occurs based on the initial lookup message?
Alternatives Considered
Have you considered any alternative solutions? If so, please describe them.
I could, on failure to lookup (doesn't exist), send a message out of a band (via either gRPC/message broker/etc.) to have a remote actor spawn the desired actor (or use a local function if trying to spawn locally).
Additional Context
Add any other context, screenshots, or examples that would help illustrate the feature.
The text was updated successfully, but these errors were encountered: