Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka Remote - Messages are not delivering (Java)

Tags:

java

akka

Trying to use Akka for parallel computing but facing a problem while communicating actors. I have two different actors (whose names are sender and receiver) which works on two different systems working on different ports on same ip address (whose names are SenderSystem and Receiver System). What I want to do is send message from sender actor to receiver actor. But on console I see a message like this

[INFO] [08/15/2015 12:36:51.645] [SenderSystem-akka.actor.default-dispatcher-4] [akka://SenderSystem/sender] Message [com.aliyesilkanat.akkadeneme.Messages$1] from Actor[akka://SenderSystem/deadLetters] to Actor[akka://SenderSystem/sender] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.

Here is application.conf

akka {
  loglevel = "INFO"
  actor {
    provider = "akka.remote.RemoteActorRefProvider"
  }
  remote {
  untrusted-mode = off
    enabled-transports = ["akka.remote.netty.tcp"]
    netty.tcp {
      hostname = "127.0.0.1"
    } 

 }
}

sender.conf

include "application"
akka { 
    actor {
        deployment {
          /receiver {
            remote = "akka://[email protected]:8091"
          }
        }
      }
    remote.netty.tcp.port = 8090
}

receiver.conf

include "application"
akka {
    remote.netty.tcp.port = 8091
}

Receiver.java

package com.aliyesilkanat.akkadeneme.receiver;

import com.aliyesilkanat.akkadeneme.Messages;

import akka.actor.UntypedActor;

public class Receiver extends UntypedActor {

    @Override
    public void onReceive(Object msg) throws Exception {
        if (msg.equals(Messages.RECEIVE)) {
            System.out.println("receiver receives");
        }
    }

}

ReceiverApplication.java

package com.aliyesilkanat.akkadeneme.receiver;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

import com.typesafe.config.ConfigFactory;

public class ReceiverApplication {
    public static void main(String[] args) {
        startRecieverSystem();
    }

    private static void startRecieverSystem() {
        final ActorSystem system = ActorSystem.create("ReceiverSystem",
                ConfigFactory.load("receiver"));
        ActorRef actorOf = system.actorOf(Props.create(Receiver.class),
                "receiverActor");
        System.out.println("created receiver actor: " + actorOf.toString());
    }
}

Sender.java

package com.aliyesilkanat.akkadeneme.sender;

import akka.actor.ActorSelection;
import akka.actor.UntypedActor;

import com.aliyesilkanat.akkadeneme.Messages;

public class Sender extends UntypedActor {

    public Sender() {
    }

    @Override
    public void onReceive(Object msg) throws Exception {
        if (msg.equals(Messages.SEND)) {
            System.out.println(getSender() + " sends");
            ActorSelection receiverActor = getContext().actorSelection(
                    "akka.tcp://[email protected]:8091/user/receiver"); // I am not sure about this one
            receiverActor.tell(Messages.RECEIVE, getSelf());
        }
    }

}

SenderApplication.java

package com.aliyesilkanat.akkadeneme.sender;

import com.typesafe.config.ConfigFactory;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;

public class SenderApplication {
    private static ActorSystem system;

    public static void main(String[] args) {
        startSenderApp();
    }

    private static void startSenderApp() {
        setSystem(ActorSystem.create("SenderSystem",
                ConfigFactory.load("sender")));
        ActorRef actorOf = getSystem().actorOf(Props.create(Sender.class),
                "senderActor");
        System.out.println("created sender actor: " + actorOf.toString());
    }

    public static ActorSystem getSystem() {
        return system;
    }

    public static void setSystem(ActorSystem system) {
        SenderApplication.system = system;
    }
}

And lastly, main method

public static void main(String[] args) {
    ReceiverApplication.main(null);
    SenderApplication.main(null);
    ActorSystem system = SenderApplication.getSystem();
    ActorSelection ref = system.actorSelection("sender");
    ref.tell(Messages.SEND, ActorRef.noSender());
}

entire console output

[INFO] [08/15/2015 12:48:12.220] [main] [Remoting] Starting remoting
[INFO] [08/15/2015 12:48:12.451] [main] [Remoting] Remoting started; listening on addresses :[akka.tcp://[email protected]:8091]
[INFO] [08/15/2015 12:48:12.451] [main] [Remoting] Remoting now listens on addresses: [akka.tcp://[email protected]:8091]
created receiver actor: Actor[akka://ReceiverSystem/user/receiverActor#2084584126]
[INFO] [08/15/2015 12:48:12.481] [main] [Remoting] Starting remoting
[INFO] [08/15/2015 12:48:12.491] [main] [Remoting] Remoting started; listening on addresses :[akka.tcp://[email protected]:8090]
[INFO] [08/15/2015 12:48:12.491] [main] [Remoting] Remoting now listens on addresses: [akka.tcp://[email protected]:8090]
created sender actor: Actor[akka://SenderSystem/user/senderActor#-2012370784]
[INFO] [08/15/2015 12:48:12.491] [SenderSystem-akka.actor.default-dispatcher-3] [akka://SenderSystem/sender] Message [com.aliyesilkanat.akkadeneme.Messages$1] from Actor[akka://SenderSystem/deadLetters] to Actor[akka://SenderSystem/sender] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
like image 904
Ali Yeşilkanat Avatar asked Feb 11 '26 09:02

Ali Yeşilkanat


1 Answers

You have in sender conf , remote deployment, so you can create Receiver actor remotly from Sender actor

ActorRef actor = system.actorOf(Props.create(Receiver.class), "receiver");
actor.tell(Messages.SEND, ActorRef.noSender());
like image 106
gaston Avatar answered Feb 13 '26 08:02

gaston



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!