commanded / commanded

Use Commanded to build Elixir CQRS/ES applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Should Commanded.Event.Handler support messages from swarm?

tomekowal opened this issue · comments

When I connect a new node to the cluster, I get a bunch of messages like this:

2023-05-12T13:32:44.260Z pid=<0.4030.0> [error] MySubscriber received unexpected message: {:swarm, :die}

I am using CommandedSwarmRegistry.
AFAIU, Subscribers start on both nodes, and when the nodes connect, Swarm kills half of the subscribers on one node and half on the other so that each subscriber runs only once.

However, when reading the code, I saw that this message is logged, but the Event.Handler is not terminated.
https://github.com/commanded/commanded/blob/master/lib/commanded/event/handler.ex#L826

Is the consensus that Swarm is an officially supported registry? Then I could add handling of this and potentially other swarm messages.

Might be related to #512

Only slightly: in the sense that it requires adding some more clauses to handle_info in the same place.
AFAIU, swarm does not send exit signals to other processes the same way as global registry does.
Instead, it sends messages and expects the process to be aware that it is managed by Swarm and react to those accordingly.
https://github.com/bitwalker/swarm#example

  def handle_info({:swarm, :die}, state) do
    {:stop, :shutdown, state}
  end

If Commanded wants to support swarm, we would need add handling of those messages to all process managed via the abstract Registry that can be resolved to either :global or :swarm