【发布时间】:2017-01-28 01:02:38
【问题描述】:
我的用例如下。机器上的应用程序连接到远程机器,在它们上执行脚本并返回结果。我正在使用 Akka 框架进行远程处理,并为客户端应用程序使用 Play 框架。在我的远程机器上运行的服务器代码如下:
public static void main(String[] args)
{
OnCallServer app = new OnCallServer();
app.executeServer();
}
private void executeServer() {
ActorSystem system = ActorSystem.create("OnCallServer");
}
(只是在远程机器上启动一个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 = ""
}
}
此设置完美运行,但有时远程计算机无法访问。我注意到这发生在两种情况下:
- 我重新启动客户端应用程序
- 远程机器上长时间没有执行脚本时
现在让我感到困惑的是:
- 在远程机器上,netstat 显示端口 10175 仍处于打开状态并正在侦听
- 在我重新启动客户端应用程序并尝试执行actor后,当我检查远程机器的日志时,它显示actor已在机器上成功执行,但我的客户端应用程序没有收到响应,因此导致超时。
我尝试在客户端参与者中添加一个 supervisorStrategy,但它没有任何效果。难道我做错了什么 ?如果 TCP 连接有问题,有没有办法在每次执行后终止连接?如果问题是演员系统如果长时间不触摸就会关闭,是否有配置可以更改此设置?请询问您是否需要更多代码或信息。
更新
当我在本地机器上测试时尝试重新启动客户端时,它不会出现任何问题。远程服务器只是抛出 akka.remote.EndpointAssociationException 消息但重新连接并能够发送回复。只有在生产模式下,当应用程序部署在不同的机器上时才会出现此问题。我认为我的客户在重新启动时会被隔离,并且 akka.remote.quarantine-systems-for 已在新的 Akka 版本中被删除。
【问题讨论】: