Skip to content

Commit 9a810e8

Browse files
authored
Add example of using library with Ecto (#22)
1 parent 9c73a02 commit 9a810e8

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ config :libcluster,
6060
Then add it to your supervision tree:
6161

6262
```elixir
63-
defmodule MyApp do
63+
defmodule MyApp.Application do
6464
use Application
6565

6666
def start(_type, _args) do
@@ -74,6 +74,31 @@ defmodule MyApp do
7474
end
7575
end
7676
```
77+
78+
If you are using Ecto, you may want to reuse your existing repo
79+
configuration. For example:
80+
81+
```elixir
82+
defmodule MyApp.Application do
83+
use Application
84+
85+
def start(_type, _args) do
86+
topology = [
87+
strategy: LibclusterPostgres.Strategy,
88+
config: MyApp.Repo.config()
89+
]
90+
91+
children = [
92+
# ...
93+
{Cluster.Supervisor, [[app: topology]]},
94+
# ...
95+
]
96+
97+
Supervisor.start_link(children, strategy: :one_for_one)
98+
end
99+
end
100+
```
101+
77102
### Why do we need a distributed Erlang Cluster?
78103

79104
At Supabase, we use clustering in all of our Elixir projects which include [Logflare](https://github.com/Logflare/logflare), [Supavisor](https://github.com/supabase/supavisor) and [Realtime](https://github.com/supabase/realtime). With multiple servers connected we can load shed, create globally distributed services and provide the best service to our customers so we’re closer to them geographically and to their instances, reducing overall latency.

0 commit comments

Comments
 (0)