#Instructions to demo distributed Elixir capabilities #start 3 terminal windows # start 3 Elixir shells with naming the nodes node_a, node_b, node_c iex --sname node_a iex --sname node_b iex --sname node_c #you will have 3 Elixir nodes named "node_a@vbox" #the "vbox" can be different in your enviroment, it depends on the hostname #check none of the ELixir runtime connect to each other yet #with following function on either of Node.list #the output is a empty list -> [] #in the next two steps connect "node_a" to "node_b" and "node_c" #calling :net_kernel.connect :"node_b@vbox" :net_kernel.connect :"node_c@vbox" #explain and show that now all 3 nodes are connected and they are in full mesh #on "node_c" issue the following Node.list #it should return : [:node_a@vbox, :node_b@vbox] #now we will send a message from node_a to node_b #first we register the shell process on node_b with Process.register(self(), :shell) #then a receive block should be typed into node_b shell receive do {msg, othershell}-> IO.puts msg send(othershell, "Hey") end #this will wait until a node_a sends a message in the form of {msg, pid} form #on node_a call the following Process.send({:shell, :"node_b@vbox"}, {"Hello", self()}, [:noconnect]) #on node_b the shell will print "Hello", show it #on node_a call the following flush #the shell will print the "answer" to "Hello" -> "Hey" # explain that sending back the answer is somewhat simpler than first message # because the shell on node_b knows the pid of the shell on node_a #with the following we can call a function on another node :rpc.call :"node_a@vbox", Node, :list, [] #it will return: [:node_a@vbox, :node_c@vbox] #explain that node_a is in the list because the function was executed on node_b #issue the following function on node_a Node.monitor :"node_b@vbox", true #then quit from Elixir shell on node_b with pressing Ctrl+c twice # call flush on node_a flush #it will print {:nodedown, :node_b@vbox} # explain that message above is because node_a monitored node_b # and node_b went down