Radio Active
Radio Active

Reputation: 497

Unique agents across application instances and BEAM

My requirement is to use named agents. Basically one agent per record with a custom id. Can we query the Agent's name across application instances and BEAM ? I mean that if we have 2 instances of an app on 2 different BEAM machines we need to make sure that we have only one agent per record. Not more. How can I achieve this?

Upvotes: 0

Views: 56

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

Agent is basically a GenServer. The latter has three options to register it’s name. Both {:global, term} and {:via, module, term} register the name globally.

Of course, all the nodes should be connected for this to work.

To make it easier to address globally registered processes, one might use Registry, although in this particular case {:global, name} should be fine enough.

Upvotes: 1

Related Questions