Registering a process using pid

I’m using SMPPEX library that requires SMPPEX.ESME.start_link to create a session, it returns {:ok, pid}. As part of the parameters to start_link, it takes a module name, however unlike a GenServer etc, there’s no way AFAIK to associate the module name with the pid

I was wondering if I could store associate the pid with the module using something like Registry so I can subsequently do a lookup for the pid. Some library functions requires the pid to work and attempt to pass the module name fails.

How do I associate a name with pid using Registry.

I’m also aware of the Process dictionary, I’m not sure if it’s the right thing to do by using put or register and retrieving it later.

You can manually register it with Registry.register(MyRegistry, "this_key", pid). Then normally lookup with Registry.lookup(MyRegistry, "this_key")


Thank you, I got a bit confused, from the output of the lookup function, there were two process id.

If you just want to register a pid with a name in one node, you can use Process — Elixir v1.11.3, specifically register/2 and whereis/1 function. They are the functions used in OTP, e.g. GenServer. Registry is a more general solution, but for just registering names they should be enough.