2017-12-27 6 views
0

프로그래밍 방식으로 원격 akka 액터를 만듭니다.원격 액터 만들기 프로그래밍 방식으로 작동하지 않습니다

package remoting.programatic.demo 

import akka.actor.{ActorSystem, Props} 
import com.typesafe.config.ConfigFactory 
import remoting.config.demo.RemoteActor 

object RemoteActorApp extends App { 

    val system = ActorSystem("RemoteNodeApp", ConfigFactory.load().getConfig("RemoteProgrammatically")) 
    val remoteActor = system.actorOf(Props[RemoteActor], name = "remoteActorAddr") 

    remoteActor ! "Hello!" 

    val actorSelection = system.actorSelection("akka.tcp://[email protected]:2553/user/remoteActorAddr") 
    Thread.sleep(4000L) 

    actorSelection ! "Hello!" 

} 

구성은 - -

RemoteProgrammatically { 
    akka { 
    actor { 
     provider = "akka.remote.RemoteActorRefProvider" 
     deployment { 
     /remoteActorAddr { 
      remote = "akka.tcp://[email protected]:2553" 
     } 
     } 
    } 
    remote { 
     enabled-transports = ["akka.remote.netty.tcp"] 
     netty.tcp { 
     hostname = "localhost" 
     port = 2553 
     } 
    } 
    } 
} 

프로그램을 실행 한 후 출력이됩니다 - 내가 배우로 보낸 메시지는 항상

[INFO] [12/27/2017 10:37:30.053] [main] [akka.remote.Remoting] Starting remoting 
[INFO] [12/27/2017 10:37:30.378] [main] [akka.remote.Remoting] Remoting started; listening on addresses :[akka.tcp://[email protected]:2553] 
[INFO] [12/27/2017 10:37:30.379] [main] [akka.remote.Remoting] Remoting now listens on addresses: [akka.tcp://[email protected]:2553] 
[INFO] [12/27/2017 10:37:30.418] [RemoteNodeApp-akka.actor.default-dispatcher-14] [akka://RemoteNodeApp/deadLetters] Message [java.lang.String] from Actor[akka://RemoteNodeApp/user/remoteActorAddr#-766312407] to Actor[akka://RemoteNodeApp/deadLetters] 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'. 
[INFO] [12/27/2017 10:37:34.419] [RemoteNodeApp-akka.actor.default-dispatcher-14] [akka://RemoteNodeApp/deadLetters] Message [java.lang.String] from Actor[akka://RemoteNodeApp/user/remoteActorAddr#-766312407] to Actor[akka://RemoteNodeApp/deadLetters] was not delivered. [2] 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'. 

아래

는 프로그램입니다 죽은 편지에 들어갔다. remoteActorAddr은 RemoteNodeApp 액터 시스템에서 성공적으로 생성되지 않았습니다. 액터가 만들어지지 않은 이유와 메시지가 항상 데드 레터에 들어가는 이유. 감사합니다. . 당신의 로그에서

답변

1
Message [java.lang.String] from Actor[akka://RemoteNodeApp/user/remoteActorAddr#-766312407] to Actor[akka://RemoteNodeApp/deadLetters] was not delivered. [1] dead letters encountered. 

위의 발췌 는 원격 배우에서 문자열 메시지 를 보낼 때 죽은 문자 사서함이 발생 말하고있다. 원격 액터가 sender()에게 메시지를 보낸 것으로 보입니다. 원격 액터가받은 메시지가 액터 외부에서 tell (!)으로 전송 되었기 때문에이 경우 데드 레터입니다. 로부터

remoteActor ! "Hello!" 
... 
actorSelection ! "Hello!" 

: 즉, 원격 배우 이 성공적으로 생성하지만, 다음과 같은 두 개의 메시지가 죽은 문자로 해결하기 위해 원격 배우에 sender()의 원인이 아닌 배우에서 보낸입니다 documentation (강조 광산) : 액터 내에서 호출하는 경우

actorRef ! message 

후 전송 배우 참조는 암시 적 메시지와 함께 전달 될 것이다 d 회원의 sender(): ActorRef 회원 메서드에서받는 액터에서 사용할 수 있습니다. 대상 액터는 이것을 사용하여 sender() ! replyMsg을 사용하여 원래 발신자에게 회신 할 수 있습니다.

액터가 아닌 인스턴스에서 호출 할 경우 보낸 사람은 기본적으로 액터 참조 deadLetters이됩니다.

다른 액터로부터 메시지를 보내거나 (응답을 처리하기 위해 내부 행위자를 생성)을 ask 패턴을 사용한다.

관련 문제