Book Image

Elixir Cookbook

By : Paulo Pereira
Book Image

Elixir Cookbook

By: Paulo Pereira

Overview of this book

Table of Contents (16 chapters)
Elixir Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Connecting nodes


In this recipe, we will start two different terminal sessions that will be our nodes, and we will connect them.

Getting ready

We will need two terminal windows opened and in each of them, we will create a node.

How to do it…

  1. Start a named node in terminal window one:

    > iex --name [email protected]
    Interactive Elixir (1.0.2) - press Ctrl+C to exit (type h() ENTER for help)
    iex([email protected])1>
    
  2. Start another named node in terminal window two:

    > iex --name [email protected]
    Interactive Elixir (1.0.2) - press Ctrl+C to exit (type h() ENTER for help)
    iex([email protected]
    )1>
    
  3. Verify the list of nodes that each of our newly created nodes is aware of:

    iex([email protected])1> Node.list
    []
    iex([email protected])1> Node.list
    []
    
  4. To connect the two nodes, we will just need to instruct one of them to perform the connection:

    iex([email protected])2> Node.connect :"[email protected]"
    true
    
  5. Now, confirm that both nodes are connected and aware of each other:

    iex([email protected])3> Node.list
    [:"two...