LoginSignup
3
3

More than 5 years have passed since last update.

Elixir二つのノードで通信

Last updated at Posted at 2015-05-30

二つのインスタンスを立ち上げ、rabbit1とrabbit2
スクリーンショット 2015-05-30 18.18.27.png

二つのノードが通信できるように同じクッキを設定します。名前はそれぞれnode_onenode_twoとします。Node.selfでノード名を確認します

[root@rabbit1 ~]# iex --sname node_one --cookie chocolate-chip
[root@rabbit2 ~]# iex --sname node_two --cookie chocolate-chip

iex(node_one@rabbit1)1> Node.self
:node_one@rabbit1

iex(node_two@rabbit2)1> Node.self
:node_two@rabbit2

スクリーンショット 2015-05-30 18.21.40.png

Node.connect :"node_two@rabbit2コマンドで二つのノードをつなげると
Node.listコマンドでお互いを確認することができます。

スクリーンショット 2015-05-30 18.29.22.png

node_oneで定義した無名関数をNode.spawn関数でnode_twoにプロセスを作成して実行します。

iex(node_one@rabbit1)5> func = fn -> IO.inspect Node.self end
#Function<20.90072148/0 in :erl_eval.expr/5>

iex(node_one@rabbit1)6> Node.spawn(:"node_two@rabbit2", func)
:node_two@rabbit2
#PID<9000.70.0>

スクリーンショット 2015-05-30 18.37.01.png

ElixirのNodeモジュールのマニアル

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3