我的用例如下。计算机上的应用程序连接到远程机器,在它们上执行脚本并返回结果。我使用Akka框架进行远程处理,对客户端应用程序使用Play Framework。在我的远程计算机上运行的服务器的代码如下:
public static void main(String[] args)
{
OnCallServer app = new OnCallServer();
app.executeServer();
}
private void executeServer() {
ActorSystem system = ActorSystem.create("OnCallServer");
}(只需在远程计算机上启动参与者系统的一个实例)
现在,当客户端应用程序想在远程机器上运行脚本时,它会在这个执行脚本的远程系统上部署一个参与者。
被部署的参与者的代码如下:
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());
}
}
}
}(获取脚本参数,执行所需的函数,返回结果)
我正在使用TCP连接通过SSL进行远程处理。配置如下:
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 = ""
}
}此设置工作非常完美,但有时远程计算机无法到达。我注意到有两种情况发生:
现在让我困惑的是:
我尝试过在客户端参与者中添加一个supervisorStrategy,但是它没有任何效果。我做错什么了吗?如果TCP连接是问题所在,是否有办法在每次执行之后终止连接?如果问题是Actor系统在很长一段时间内不被触及而关闭,那么是否有一个配置来更改此设置?请询问您是否需要更多的代码或信息。
更新
在本地机器上测试时,当我尝试重新启动客户机时,它不会出现任何问题。远程服务器只是抛出akka.remote.EndpointAssociationException消息,但重新连接并能够发送回复。只有在生产模式下,当应用程序部署在不同的机器上时,才会出现这个问题。我认为我的客户在重新启动和akka.遥控器上被隔离,隔离系统已经在新的Akka版本中被删除了。
发布于 2014-04-30 19:01:55
好吧,我发现了问题。对于其他可能面临这一问题的人:在远程计算机的配置文件中,在配置的netty.ssl部分,我常常给出它们各自的主机名,就像我在客户端应用程序中用于连接时一样。但是在客户端应用程序配置中,我常常将主机名命名为"localhost“,因为我认为我在任何地方都不需要这个名称。
现在,在检查调试模式下的日志时,我发现在建立初始连接时,关联如下:
2014-05-01 18:35:38.503 2014 DEBUGOnCallServer-akka.actor.default-dispatcher-3 Remoting -关联akka.ssl.tcp://OnCallServer@sp-cms-backend4.nm.flipkart.com:10175 <- akka.ssl.tcp://application@localhost:10174
即使客户端应用程序不在本地主机上。现在这个会话没有出现任何错误。但是在连接丢失之后(在重新启动客户端应用程序之后),并且我尝试重新执行脚本,我得到了日志:
2014-05-01 18:36:12.045 with ERROROnCallServer-akka.actor.default-dispatcher-2 a.r.EndpointWriter - AssociationError -> akka.ssl.tcp://application@localhost:10174:错误[联系失败与akka.ssl.tcp://application@localhost:10174] [ akka.remote.EndpointAssociationException:联系失败与akka.ssl.tcp://application@localhost:10174* akka.remote.transport.netty.NettyTransport$$anonfun$associate$1$$anon$2:连接被拒绝: localhost/127.0.0.1:10174
服务器应用程序出于某种原因试图将这条消息发送回它的本地主机。
将客户端配置中的主机名更改为其实际主机名解决了问题。
https://stackoverflow.com/questions/23388361
复制相似问题