Now this is a bit confusing because you say:
I want to run myapp_api on 3 nodes, I want the whole application (myapp_api + myapp) to work with only one node at a time.
and you add:
The main application (myapp_api) works as expected: only with one node with rollback and capture. But for some reason, myapp dependency always started with every node.
In the first paragraph, you say that myapp_api should work everywhere, in the second quote that you say, it works as expected when loading on one node at a time.
I assume that you want the whole setup to be fault tolerant, and not just for a top-level application, and I just got confused in the first paragraph.
The configuration file used shows what is happening:
[{kernel, [{distributed, [{myapp_api, 1000, [' n1@myhost ', {' n2@myhost ', ' n3@myhost '}]}]}, {sync_nodes_optional, [' n2@myhost ', ' n3@myhost ']}, {sync_nodes_timeout, 5000} ]}].
An important bit is that myapp_api has the nodes [' n1@myhost ', {' n2@myhost ', ' n3@myhost '}] . This order means that it works on n1@myhost in the highest priority, and then on other nodes with equal priority if there is a transition to another resource.
The fact is that not one of the dependencies is distributed equally, and therefore they can be expected everywhere.
You only need to expand this configuration file for it to work. Here I did this and re-indexed it to show its structure better:
[{kernel, [{distributed, [ {myapp_api, 1000, [' n1@myhost ', {' n2@myhost ', ' n3@myhost '}]}, {myapp, 1000, [' n1@myhost ', {' n2@myhost ', ' n3@myhost '}]}, ]}, {sync_nodes_optional, [' n2@myhost ', ' n3@myhost ']}, {sync_nodes_timeout, 5000} ]}].
I have not tested it directly, but I am sure it will work.
If you want myapp_api be everywhere, but for myapp to run in one place, you can use global registration , give the name myapp public process, get myapp_api to call them. myapp_api will be able to route traffic to where myapp will be supported with the following configuration:
[{kernel, [{distributed, [ {myapp, 1000, [' n1@myhost ', {' n2@myhost ', ' n3@myhost '}]}, ]}, {sync_nodes_optional, [' n2@myhost ', ' n3@myhost ']}, {sync_nodes_timeout, 5000} ]}].
(See how myapp is the only application that gets the distribution profile? Other applications will run on all nodes)