-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Horde's `process_redistribution` flag to enable automatic sharding (and resharding) of processes on cluster events. This allows for almost seamless autoscaling, as processes will be terminated and restarted on different Erlang nodes. Use the grain-like nature of AMQPDataConsumers to support spawining (re-)sharded consumers both on single and multi node Erlang clusters. Based on #15. Signed-off-by: Arnaldo Cesco <arnaldo.cesco@secomind.com>
- Loading branch information
Showing
6 changed files
with
77 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule NodeListener do | ||
@moduledoc false | ||
use GenServer | ||
|
||
alias Mississippi.Consumer.AMQPDataConsumer | ||
|
||
require Logger | ||
|
||
def start_link(args), do: GenServer.start_link(__MODULE__, args) | ||
|
||
def init(queues_config) do | ||
:net_kernel.monitor_nodes(true, node_type: :visible) | ||
{:ok, queues_config} | ||
end | ||
|
||
def handle_info({:nodeup, node, node_type}, queues_config) do | ||
_ = Logger.info("Node #{inspect(node)} of type #{inspect(node_type)} is up") | ||
_ = AMQPDataConsumer.Supervisor.start_consumers(queues_config) | ||
{:noreply, queues_config} | ||
end | ||
|
||
def handle_info({:nodedown, node, node_type}, queues_config) do | ||
_ = Logger.info("Node #{inspect(node)} of type #{inspect(node_type)} is down") | ||
_ = AMQPDataConsumer.Supervisor.start_consumers(queues_config) | ||
{:noreply, queues_config} | ||
end | ||
end |