Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@ erl_crash.dump
.elixir_ls

.elixir_tools
grpc_client/.elixir-tools/
grpc_core/.elixir-tools/
grpc_server/.elixir-tools/

grpc-*.tar
4 changes: 1 addition & 3 deletions benchmark/lib/benchmark/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ defmodule Benchmark.Application do

@impl true
def start(_type, _args) do
children = [
{GRPC.Client.Supervisor, []}
]
children = []

opts = [strategy: :one_for_one, name: Benchmark.Supervisor]
Supervisor.start_link(children, opts)
Expand Down
1 change: 0 additions & 1 deletion grpc_client/guides/advanced/load_balancing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ You can connect using `DNS`, `Unix Domain sockets`, and `IPv4/IPv6` for now.
### DNS

```elixir
iex> {:ok, _pid} = GRPC.Client.Supervisor.start_link()
iex> {:ok, channel} = GRPC.Stub.connect("dns://orders.prod.svc.cluster.local:50051")
iex> request = Orders.GetOrderRequest.new(id: "123")
iex> {:ok, reply} = channel |> Orders.OrderService.Stub.get_order(request)
Expand Down
18 changes: 1 addition & 17 deletions grpc_client/guides/getting_started/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@ This section demonstrates how to establish client connections and perform RPC ca

## Basic Connection and RPC

Typically, you start this client supervisor as part of your application's supervision tree:

```elixir
children = [
GRPC.Client.Supervisor
]

opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
```

You can also start it manually in scripts or test environments:
```elixir
{:ok, _pid} = GRPC.Client.Supervisor.start_link()
```

Then connect with gRPC server:
Connect with gRPC server:

```elixir
iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051")
Expand Down
13 changes: 13 additions & 0 deletions grpc_client/lib/grpc/client/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule GRPC.Client.Application do
@moduledoc false
use Application

def start(_type, _args) do
children = [
{GRPC.Client.Supervisor, [name: GRPC.Client.Supervisor]}
]

opts = [strategy: :one_for_one, name: Grpc.Supervisor]
Supervisor.start_link(children, opts)
end
end
21 changes: 0 additions & 21 deletions grpc_client/lib/grpc/client/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,6 @@ defmodule GRPC.Client.Connection do
"""
@spec connect(String.t(), keyword()) :: {:ok, Channel.t()} | {:error, any()}
def connect(target, opts \\ []) do
supervisor_pid = Process.whereis(GRPC.Client.Supervisor)

if is_nil(supervisor_pid) or !Process.alive?(supervisor_pid) do
raise """
GRPC.Client.Supervisor is not running. Please ensure it is started as part of your
application's supervision tree:

children = [
{GRPC.Client.Supervisor, []}
]

opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)

You can also start it manually in scripts or test environments:

{:ok, _pid} = DynamicSupervisor.start_link(strategy: :one_for_one, name: GRPC.Client.Supervisor)
"""
end

ref = make_ref()

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

{:error, {:already_started, _pid}} ->
# race: someone else started it first, ask the running process for its current channel
case pick_channel(opts) do
{:ok, %Channel{} = channel} ->
{:ok, channel}
Expand Down
1 change: 1 addition & 0 deletions grpc_client/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule GrpcClient.MixProject do

def application do
[
mod: {GRPC.Client.Application, []},
extra_applications: [:logger]
]
end
Expand Down
7 changes: 0 additions & 7 deletions grpc_client/test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,4 @@ Mox.defmock(GRPC.Client.Resolver.DNS.MockAdapter,
for: GRPC.Client.Resolver.DNS.Adapter
)

# Start client supervisor for integration tests
{:ok, _pid} =
DynamicSupervisor.start_link(
strategy: :one_for_one,
name: GRPC.Client.Supervisor
)

ExUnit.start(capture_log: true)
1 change: 0 additions & 1 deletion interop/lib/interop/app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule Interop.App do

def start(_type, _args) do
children = [
GRPC.Client.Supervisor,
{GRPC.Server.Supervisor, endpoint: Interop.Endpoint, port: 10000}
]

Expand Down
Loading