Skip to content
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

Can't get simple setup (Lighthouse, WebAPI, and CommandLine Project) working #3757

Closed
OmniAsetty opened this issue Apr 15, 2019 · 3 comments
Closed

Comments

@OmniAsetty
Copy link

OmniAsetty commented Apr 15, 2019

I am trying from past one week to get a simple setup working. I have installed the LightHouse as windows service (running on 127.0.0.1:4053) and updated the Actor system name to match other. I have command line tool 'MessageGateway' which starts up the ActorSystem (DeviceMessageProcessor) and here is hocon config of MessageGateway,
akka { loglevel = DEBUG loggers = ["Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog"] actor { provider = cluster deployment { /pingreport { router = round-robin-pool nr-of-instances = 2 } } } remote { log-remote-lifecycle-events = DEBUG dot-netty.tcp { port = 0 hostname = "127.0.0.1" } } cluster { seed-nodes = ["akka.tcp://DeviceMessageProcessor@127.0.0.1:4053"] } }

And I have MessageGatewayAPI VS Project, which creates the actor to send a message to actor '/user/pingreport', here is the hocon config of MessageGatewayAPI,
akka { loglevel = DEBUG loggers = ["Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog"] actor { provider = cluster } remote { log-remote-lifecycle-events = DEBUG dot-netty.tcp { port = 0 hostname = "127.0.0.1" } } cluster { seed-nodes = ["akka.tcp://DeviceMessageProcessor@127.0.0.1:4053"] } }

Every time I send message from MessageGatewayAPI actor to MessageGateway actor ('/user/pingreport'), it goes to DeadLetters. I have not seeing any logs which is helpful to debug this issue. Please please, try to help us here. I have been pouring ton of time and I am not moving forward.

Akka.Net Version: 1.3.12
ASP.NET CORE 2.0

Below is the code which tries to send a message,

public class MessageGatewayApiActor: ReceiveActor
    {
        private readonly ILoggingAdapter _logger = Context.GetLogger();
        private readonly ActorSelection _gateway = Context.ActorSelection("/user/pingreport");

        public MessageGatewayApiActor()
        {
            Receive<GatewayPingReport>(req =>
            {
                _logger.Info("Sending PingReport request with message '{PingMessage}'", req.PingMessage);
                _gateway.Tell(new PingReport(req.PingMessage));
            });
        }
    }
@Horusiath
Copy link
Contributor

If you're using a relative path ("/user/pingreport") in your actor selection, it will assume, that the base path you want to use, is the address of your current node. This means that pingreport actor must live on the same node as MessageGatewayApiActor.

If you want to send to send a message to an actor living on another node, you first need to specify what node are you interested in. Also it's bad practice to use ActorSelection if all you need is to address the same actor every time.

The usual practice is to distinguish the nodes presenting different behaviors by assigning them different roles - this can be done by akka.cluster.roles = [ "role1", "role2" ] in HOCON config. All nodes having the same role should expose the same capability.

Now you can interact with the cluster using Akka.Cluster.Cluster class. Example:

var cluster = Cluster.Get(actorSystem);
var nodes = cluster.State.Members.Where(member => member.Roles.Contains("role1"));
foreach (var node in nodes)
    var actorSelection = actorSystem.ActorSelection(node.Address.ToString() + "/user/pingreport");
    // check if actor is alive under given selection
    var actorRef = await actorSelection.ResolveOne(timeout: TimeSpan.FromSeconds(10));

You can also subscribe to Cluster to get information about the changes in of a cluster membership. You can also use Context.Watch(actorRef) to get notified about the situation when actor has terminated.

@IgorFedchenko
Copy link
Contributor

@OmniAsetty so, is the issue resolved now?
I believe the recommendations @Horusiath gave above, especially the fact that you need to specify actor's node address to be able to use it's relative path, should help.

@IgorFedchenko IgorFedchenko moved this from To do to In progress in Oct 26 - Nov 6 Sprint Oct 27, 2020
@IgorFedchenko
Copy link
Contributor

I will close this issue, since most likely it is resolved - but feel free to reopen / ask any questions here 👍

Oct 26 - Nov 6 Sprint automation moved this from In progress to Done Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

4 participants