[关闭]
@xtccc 2017-01-17T06:52:27.000000Z 字数 1860 阅读 3291

Akka Cluster

给我写信
GitHub

此处输入图片的描述


Akka



参考链接:


目录:



1. Remoting


Akka remoting告诉actor system:

a). 我希望你在一个remote host上创建一个actor

  1. val ref = system.actorOf(FooActor.props.withDeploy(Deploy(scope = RemoteScope(address))))

或者

b). 我希望得到一个remote host上已有actor的reference:

  1. val remoteFooActor = context.actorSelection("akka.tcp://actorSystemName@10.0.0.1:2552/user/fooActor")



Akka remoting实在是太具体的一个操作了,因为你得指定remote host的IP,但是我们一般并不太关心在哪个remote host上创建actora —— 我们希望能在云中创建一个actor就行了。

Clustering则允许你在一个cluster中创建actor,而不需要指定该actor到底在哪个node上运行(该cluster中的所有nodes都共享同一个actor system)。




2. 加入cluster


参考 :

2.1 通过Seed Nodes加入集群

在启动actor之前,在配置文件application.conf里面填入akka.cluster.seed-nodes,然后该actor启动之后,就会自动加入到对应的nodes中。当然,前提是这些seed nodes要已经在运行(特别是第一个seed node必须在运行)。


2.2 Join a given seed node

当某个actor启动之后,也可以通过代码来加入到一个指定的node:

  1. Cluster(context.system).join(Address("akka.tcp", systemName, ip, port)
  2. 或者加入若干个nodes
  3. Cluster(context.system).joinSeedNodes(nodes_list)



如果某个actor在启动时没有为它配置seed-node,那么它首先要加入自己,然后才能加入指定的seed node。

2.3 Join New seed nodes

如果当前actor已经加入了某个node a,但是这时它想加入到另外一个node b(例如a挂掉了):

  1. Cluster(context.system).join(Address("akka.tcp", systemName, b-ip, b-port)

此时,actor会脱离node a(即使node a 仍然在正常运行),然后加入到node b。




3. Seed nodes崩溃与恢复


3.1 如果seed nodes挂了 ...

假设Actor X 加入了2个seed nodes: A和B。

那么,当A挂掉时,X会收到有限的几条消息:

Association with remote system [akka.tcp://XiaoTao@127.0.0.1:3100] has failed

虽然A挂掉了,但是B还在运行,所以X仍然在cluster中正常运行。
但是如果此时B也挂掉了,那么X就会一直收到消息:

Association with remote system [akka.tcp://XiaoTao@127.0.0.1:3200] has failed

因为最后一个seed node也挂了,X此时就不能在集群中了。

3.2 如果挂掉的seed node恢复了 ...

现在,A和B这两个seed nodes都挂了,actor X也会不断地收到错误消息。
如果A恢复呢?一旦A恢复,就会看到X的错误消息就停止输出,X也能正常与A进行通信。并且,在A崩溃期间内如果X在给A发送消息的话,那么当A恢复后,这些积累的消息并不会被A收到。




4. 退出Cluster





添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注