Is it possible set node name from configuration file?

Hi all.

I’m new in this technology, ours company planning use Elixir for rewrite .ge domain registrar platform. Also I think we will be active in this forum.

I already have a lot of questions. Help me if you have similar experience.

  1. We are planing use messaging for implement micro-service architecture, but I found very few resources about this experience. What you think? Whether the Elixir will cope in a highly loaded environment. And whether it is profitable to implement the micro-service architecture and messaging (ZeroMQ replacement) for solving these problems.

  2. I try set node name for one module, and i used two ways for solving this problem, but on my opinion this solutions not elegant.

  • adding this code, but i not understand what is best practice for this solution, and where add this line :net_kernel:start([foobar, short names]).
  • when start application add –sname flag (e.g. iex --sname foo)
  • use Node.start but when i try trowed exception and i can’t use this function.

However I think I’m doing something wrong. Is it possible to declare node name from configuration file or mix.exs file?

Regards, Khachatur!

Whether the Elixir will cope in a highly loaded environment.

Whats your definition of highly loaded? The BEAM (the VM elixir runs on) does cope very well with limited ressources, but as with every other language, its easy to write code that doesn’t cope well, while you need to take care of things when you expect strictly limited resources.

I try set node name for one module,

Node names are per node (an instance of the BEAM), not per module. So this doesn’t make much sense…

adding this code, but i not understand what is best practice for this solution, and where add this line :net_kernel:start([foobar, short names]).

That sets the name of the current Node to whatever is stored in the variable foobar, you’ll probably want to do :net_kernel.start([:foobar, :shortnames]). This has to be done anywhere, but starting your node with a name straight away makes often more sense and scales better.

when start application add --sname flag (e.g. iex --sname foo)

Yupp this starts the node with a name straight away.

use Node.start but when i try trowed exception and i can’t use this function

Which exception? Its prefered over :net_kernel.start/1 because it wraps a little bit more stuff.

Also please remember, when you use shortnames, you can’t connect to Nodes over the network!

2 Likes

I try set Node name from interactive mode.

iex(3)> Node.start( "alexa", :longnames )
{:error,
 {{:shutdown, {:failed_to_start_child, :net_kernel, {:EXIT, :nodistribution}}},
  {:child, :undefined, :net_sup_dynamic,
   {:erl_distribution, :start_link, [["alexa", :longnames, 15000], false]},
   :permanent, 1000, :supervisor, [:erl_distribution]}}}

And another question: if I want add Node.start to mix.exs file (To work as well as a “iex --sname foobar -S mix”). Where add add this code?

How have you started that iex session? And that snippet weren’t supposed in your mix.exs but in you applications start function.