-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transient subscription event mapping function
- Loading branch information
1 parent
5a73f7c
commit 5de99ce
Showing
10 changed files
with
134 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule EventStore.Registration.DistributedForwarder do | ||
use GenServer | ||
|
||
alias EventStore.Registration.LocalRegistry | ||
|
||
def start_link(args) do | ||
GenServer.start_link(__MODULE__, args, name: __MODULE__) | ||
end | ||
|
||
@doc """ | ||
Broadcast the message on the topic to all connected nodes. | ||
""" | ||
def broadcast(topic, message) do | ||
for node <- Node.list() do | ||
send({__MODULE__, node}, {topic, message}) | ||
end | ||
|
||
:ok | ||
end | ||
|
||
def init(_args) do | ||
{:ok, []} | ||
end | ||
|
||
def handle_info({topic, message}, state) do | ||
LocalRegistry.broadcast(topic, message) | ||
|
||
{:noreply, state} | ||
end | ||
end |
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,43 @@ | ||
defmodule EventStore.Registration.DistributedRegistry do | ||
@moduledoc """ | ||
Pub/sub using a local registry and broadcasting messages to all connected | ||
nodes. | ||
""" | ||
|
||
@behaviour EventStore.Registration | ||
|
||
require Logger | ||
|
||
alias EventStore.Registration.{DistributedForwarder, LocalRegistry} | ||
|
||
@doc """ | ||
Return an optional supervisor spec for the registry. | ||
""" | ||
@spec child_spec() :: [:supervisor.child_spec()] | ||
@impl EventStore.Registration | ||
def child_spec do | ||
LocalRegistry.child_spec() ++ | ||
[ | ||
DistributedForwarder.child_spec([]) | ||
] | ||
end | ||
|
||
@doc """ | ||
Subscribes the caller to the given topic. | ||
""" | ||
@spec subscribe(binary, mapper: (RecordedEvent.t() -> any())) :: :ok | {:error, term} | ||
@impl EventStore.Registration | ||
def subscribe(topic, opts) do | ||
LocalRegistry.subscribe(topic, opts) | ||
end | ||
|
||
@doc """ | ||
Broadcasts message on given topic. | ||
""" | ||
@spec broadcast(binary, term) :: :ok | {:error, term} | ||
@impl EventStore.Registration | ||
def broadcast(topic, message) do | ||
:ok = LocalRegistry.broadcast(topic, message) | ||
:ok = DistributedForwarder.broadcast(topic, message) | ||
end | ||
end |
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 was deleted.
Oops, something went wrong.
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