diff --git a/.gitignore b/.gitignore index 0a1640e8..51659150 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/benchmark/lib/benchmark/application.ex b/benchmark/lib/benchmark/application.ex index 49e7a0d6..f665f02c 100644 --- a/benchmark/lib/benchmark/application.ex +++ b/benchmark/lib/benchmark/application.ex @@ -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) diff --git a/grpc_client/guides/advanced/load_balancing.md b/grpc_client/guides/advanced/load_balancing.md index 272470f6..a222ab20 100644 --- a/grpc_client/guides/advanced/load_balancing.md +++ b/grpc_client/guides/advanced/load_balancing.md @@ -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) diff --git a/grpc_client/guides/getting_started/client.md b/grpc_client/guides/getting_started/client.md index 1d748640..41810da4 100644 --- a/grpc_client/guides/getting_started/client.md +++ b/grpc_client/guides/getting_started/client.md @@ -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") diff --git a/grpc_client/lib/grpc/client/application.ex b/grpc_client/lib/grpc/client/application.ex new file mode 100644 index 00000000..24c2d306 --- /dev/null +++ b/grpc_client/lib/grpc/client/application.ex @@ -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 diff --git a/grpc_client/lib/grpc/client/connection.ex b/grpc_client/lib/grpc/client/connection.ex index d880929c..87d573a0 100644 --- a/grpc_client/lib/grpc/client/connection.ex +++ b/grpc_client/lib/grpc/client/connection.ex @@ -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 @@ -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} diff --git a/grpc_client/mix.exs b/grpc_client/mix.exs index 0fb4fcb6..7e01b3a3 100644 --- a/grpc_client/mix.exs +++ b/grpc_client/mix.exs @@ -22,6 +22,7 @@ defmodule GrpcClient.MixProject do def application do [ + mod: {GRPC.Client.Application, []}, extra_applications: [:logger] ] end diff --git a/grpc_client/test/test_helper.exs b/grpc_client/test/test_helper.exs index b98144e0..5d228d32 100644 --- a/grpc_client/test/test_helper.exs +++ b/grpc_client/test/test_helper.exs @@ -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) diff --git a/interop/lib/interop/app.ex b/interop/lib/interop/app.ex index 9e880ab5..f67a072e 100644 --- a/interop/lib/interop/app.ex +++ b/interop/lib/interop/app.ex @@ -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} ]