Skip to content

Commit 9baf871

Browse files
sleipnirAdriano Santospolvalente
authored
[Refactor]: GRPC client setup (#483)
* added elixir tools to .gitiignore * chore: start client supervisor in application * doc: remove supervisor * format * chore: remove dead code * Update grpc_client/lib/grpc/client/application.ex Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com> * Update .gitignore Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com> * Update grpc_client/lib/grpc/client/application.ex Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com> * remove bench application.ex * fix: remove client supervisor * remove supervisor from tests --------- Co-authored-by: Adriano Santos <adriano.santos@v3.com.br> Co-authored-by: Paulo Valente <16843419+polvalente@users.noreply.github.com>
1 parent 2a90af1 commit 9baf871

File tree

12 files changed

+15
-140
lines changed

12 files changed

+15
-140
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ erl_crash.dump
2424

2525
.elixir_ls
2626

27-
.elixir_tools
2827

2928
grpc-*.tar

benchmark/lib/benchmark/application.ex

Lines changed: 0 additions & 14 deletions
This file was deleted.

benchmark/mix.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ defmodule Benchmark.MixProject do
1515
def application do
1616
[
1717
extra_applications: [:logger],
18-
mod: {Benchmark.Application, []}
1918
]
2019
end
2120

grpc_client/guides/advanced/load_balancing.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ You can connect using `DNS`, `Unix Domain sockets`, and `IPv4/IPv6` for now.
2727
### DNS
2828

2929
```elixir
30-
iex> {:ok, _pid} = GRPC.Client.Supervisor.start_link()
3130
iex> {:ok, channel} = GRPC.Stub.connect("dns://orders.prod.svc.cluster.local:50051")
3231
iex> request = Orders.GetOrderRequest.new(id: "123")
3332
iex> {:ok, reply} = channel |> Orders.OrderService.Stub.get_order(request)

grpc_client/guides/getting_started/client.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,7 @@ This section demonstrates how to establish client connections and perform RPC ca
66

77
## Basic Connection and RPC
88

9-
Typically, you start this client supervisor as part of your application's supervision tree:
10-
11-
```elixir
12-
children = [
13-
GRPC.Client.Supervisor
14-
]
15-
16-
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
17-
Supervisor.start_link(children, opts)
18-
```
19-
20-
You can also start it manually in scripts or test environments:
21-
```elixir
22-
{:ok, _pid} = GRPC.Client.Supervisor.start_link()
23-
```
24-
25-
Then connect with gRPC server:
9+
Connect with gRPC server:
2610

2711
```elixir
2812
iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
defmodule GRPC.Client.Application do
2+
@moduledoc false
3+
use Application
4+
5+
def start(_type, _args) do
6+
children = [
7+
{DynamicSupervisor, [name: GRPC.Client.Supervisor]}
8+
]
9+
10+
opts = [strategy: :one_for_one, name: GRPC.Supervisor]
11+
Supervisor.start_link(children, opts)
12+
end
13+
end

grpc_client/lib/grpc/client/connection.ex

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,6 @@ defmodule GRPC.Client.Connection do
153153
"""
154154
@spec connect(String.t(), keyword()) :: {:ok, Channel.t()} | {:error, any()}
155155
def connect(target, opts \\ []) do
156-
supervisor_pid = Process.whereis(GRPC.Client.Supervisor)
157-
158-
if is_nil(supervisor_pid) or !Process.alive?(supervisor_pid) do
159-
raise """
160-
GRPC.Client.Supervisor is not running. Please ensure it is started as part of your
161-
application's supervision tree:
162-
163-
children = [
164-
{GRPC.Client.Supervisor, []}
165-
]
166-
167-
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
168-
Supervisor.start_link(children, opts)
169-
170-
You can also start it manually in scripts or test environments:
171-
172-
{:ok, _pid} = DynamicSupervisor.start_link(strategy: :one_for_one, name: GRPC.Client.Supervisor)
173-
"""
174-
end
175-
176156
ref = make_ref()
177157

178158
case build_initial_state(target, Keyword.merge(opts, ref: ref)) do
@@ -184,7 +164,6 @@ defmodule GRPC.Client.Connection do
184164
{:ok, ch}
185165

186166
{:error, {:already_started, _pid}} ->
187-
# race: someone else started it first, ask the running process for its current channel
188167
case pick_channel(opts) do
189168
{:ok, %Channel{} = channel} ->
190169
{:ok, channel}

grpc_client/lib/grpc/client/supervisor.ex

Lines changed: 0 additions & 63 deletions
This file was deleted.

grpc_client/mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ defmodule GrpcClient.MixProject do
2222

2323
def application do
2424
[
25+
mod: {GRPC.Client.Application, []},
2526
extra_applications: [:logger]
2627
]
2728
end

grpc_client/test/grpc/supervisor_test.exs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)