Skip to content
Merged
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
8 changes: 3 additions & 5 deletions grpc_client/lib/grpc/client/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ defmodule GRPC.Client.Connection do
"""
@spec connect(String.t(), keyword()) :: {:ok, Channel.t()} | {:error, any()}
def connect(target, opts \\ []) do
ref = make_ref()

case build_initial_state(target, Keyword.merge(opts, ref: ref)) do
case build_initial_state(target, opts) do
{:ok, initial_state} ->
ch = initial_state.virtual_channel

Expand Down Expand Up @@ -321,7 +319,7 @@ defmodule GRPC.Client.Connection do
opts =
Keyword.validate!(opts,
cred: nil,
ref: nil,
name: make_ref(),
adapter: GRPC.Client.Adapters.Gun,
adapter_opts: [],
interceptors: [],
Expand All @@ -347,7 +345,7 @@ defmodule GRPC.Client.Connection do
virtual_channel = %Channel{
scheme: scheme,
cred: cred,
ref: opts[:ref],
ref: opts[:name],
adapter: adapter,
interceptors: interceptors,
codec: norm_opts[:codec],
Expand Down
15 changes: 15 additions & 0 deletions grpc_client/test/grpc/integration/stub_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ defmodule GRPC.Integration.StubTest do
end)
end

test "use a channel name to send a message" do
run_server(HelloServer, fn port ->
{:ok, _channel} =
GRPC.Client.Connection.connect("localhost:#{port}",
interceptors: [GRPC.Client.Interceptors.Logger],
name: :my_channel
)

name = "GRPC user!"
req = %Helloworld.HelloRequest{name: name}
{:ok, reply} = %GRPC.Channel{ref: :my_channel} |> Helloworld.Greeter.Stub.say_hello(req)
assert reply.message == "Hello, #{name}"
end)
end

test "invalid channel function clause error" do
req = %Helloworld.HelloRequest{name: "GRPC"}

Expand Down
Loading