簡體   English   中英

重新啟動客戶端后重新連接到遠程Akka系統

[英]Reconnecting to Remote Akka System after Restarting the Client

我的用例如下。 計算機上的應用程序連接到遠程計算機,在其上執行腳本並返回結果。 我正在使用Akka Framework進行遠程處理,並為客戶端應用程序使用Play Framework。 在我的遠程計算機上運行的服務器的代碼如下:

public static void main(String[] args)
{
    OnCallServer app = new OnCallServer();
    app.executeServer();
}

private void executeServer() {
    ActorSystem system = ActorSystem.create("OnCallServer");
}

(只是在遠程機器上啟動actor系統的一個實例)

現在,當客戶端應用程序想要在遠程計算機上運行腳本時,它會在此遠程系統上部署一個執行該腳本的actor。

部署的actor的代碼如下:

public static class RemoteActor extends UntypedActor implements Serializable {
    private static final long serialVersionUID = 1L;

    @Override
    public void onReceive(Object message) throws Exception {
        Config config = context().system().settings().config();
        String host = config.getConfig("akka.remote.netty.ssl").getString("machineName");
        String sysDesc = host;
        if (message instanceof ScriptExecutionParams) {
            System.out.println("scriptParam");
            ScriptExecutionParams scriptParams = (ScriptExecutionParams) message;

            if (scriptParams.function == ScriptFunction.EXECUTE) {
                getSender().tell(executeScript(scriptParams.getName(), scriptParams.getArgument(), sysDesc), getSelf());
            } else if (scriptParams.function == ScriptFunction.DEPLOY) {
                getSender().tell(deployScript(scriptParams.getName(), scriptParams.getContent(), sysDesc), getSelf());
            } else if (scriptParams.function == ScriptFunction.REMOVE) {
                getSender().tell(removeScript(scriptParams.getName(), sysDesc), getSelf());
            }
        }
    }
}

(獲取腳本參數,執行所需的功能,返回結果)

我正在使用SSL上的TCP連接進行遠程處理。 配置如下:

remote {
        enabled-transports = ["akka.remote.netty.ssl"]
        netty.ssl {
            hostname = "localhost" (for client) and hostname (for remote servers)
            port = 10174 (for client) and 10175 ( for server )
            enable-ssl = true
        }
        netty.ssl.security {
            key-store = "clientKeystore.jks"
            trust-store = "clientTruststore.jks"
            key-store-password = "xxx"
            key-password = "xxx"
            trust-store-password = "xxx"
            protocol = "SSLv3"
            enabled-algorithms = [SSL_RSA_WITH_NULL_SHA]
            random-number-generator = ""
        }
    }

此設置工作正常,但有時遠程機器無法訪問。 我注意到這種情況發生在兩種情況:

  1. 我重啟我的客戶端應用程序
  2. 長時間沒有在遠程計算機上執行腳本時

現在令我困惑的是:

  1. 在遠程計算機上,netstat顯示端口10175仍處於打開和監聽狀態
  2. 在我重新啟動客戶端應用程序並嘗試執行actor之后,當我檢查遠程計算機的日志時,它顯示該actor已在計算機上成功執行,但我的客戶端應用程序未收到響應,因此導致超時。

我嘗試在客戶端actor中添加supervisorStrategy,但它沒有任何效果。 難道我做錯了什么 ? 如果TCP連接是問題,有沒有辦法在每次執行后終止連接? 如果問題是如果長時間未觸摸Actor系統關閉,是否有配置更改此設置? 請詢問您是否需要更多代碼或信息。

更新

當我在本地計算機上進行測試時嘗試重新啟動客戶端時,它不會產生任何問題。 遠程服務器只是拋出akka.remote.EndpointAssociationException消息但重新連接並能夠發送回復。 只有在生產模式下,當應用程序部署在不同的計算機上時才會出現此問題。 我認為我的客戶端在重新啟動時被隔離,並且在新的Akka版本中刪除了akka.remote.quarantine-systems-for。

好的,我發現了問題。 對於可能遇到此問題的任何其他人:在遠程計算機的配置文件中,在配置的netty.ssl部分中,我曾經提供了各自的主機名,因為我在客戶端應用程序中使用它來進行連接。 但在客戶端應用程序配置中,我曾經將主機名稱為“localhost”,因為我認為我不會在任何地方需要它。

現在,在DEBUG模式下檢查日志,我發現在建立初始連接時,關聯如下:

2014-05-01 18:35:38.503UTC DEBUG [OnCallServer-akka.actor.default-dispatcher-3] Remoting - Associated [akka.ssl.tcp://OnCallServer@sp-cms-backend4.nm.flipkart.com :10175] < - [akka.ssl.tcp:// application @ localhost:10174]

即使客戶端應用程序不在機器localhost上..現在這個會話沒有給出任何錯誤。 但在連接丟失后(重新啟動客戶端應用程序后),我嘗試重新執行腳本,我得到了日志:

2014-05-01 18:36:12.045UTC錯誤[OnCallServer-akka.actor.default-dispatcher-2] arEndpointWriter - AssociationError [akka.ssl.tcp://OnCallServer@sp-cms-backend4.nm.flipkart.com :[10175] - > [akka.ssl.tcp:// application @ localhost:10174]:錯誤[關聯失敗[akka.ssl.tcp:// application @ localhost:10174]] [akka.remote.EndpointAssociationException:Association失敗了[akka.ssl.tcp:// application @ localhost:10174]引起:akka.remote.transport.netty.NettyTransport $$ anonfun $ associate $ 1 $$ anon $ 2:連接被拒絕:localhost / 127.0.0.1:10174

服務器應用程序出於某種原因試圖將此消息發送回它的localhost。

將客戶端配置中的主機名更改為其實際主機名解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM