Closed minghu6 closed 6 years ago
Ah, sorry, I hadn't merged the plugin client branch to master.
I've pushed to master now so upgrading the plugin should result in the client being generated.
en, I edit rebar.config {grpcbox_plugin, {git, "https://github.com/tsloughter/grpcbox.git", {branch, "master"}}}
, unlock and recompile, but it seems that no new version to upgrade?
It is {grpcbox_plugin, {git, "https://github.com/tsloughter/grpcbox_plugin.git", {branch, "master"}}}
But also plugins aren't locked, you want rebar3 plugins upgrade grpcbox_plugin
or just blow away the _build/default/plugins
dir.
When I run rebar3 plugins upgrade grpcbox_plugin
, it prints:
===> Fetching chatterbox ({git,
"https://github.com/tsloughter/chatterbox",
{ref,
"0d8c06bf23ec65a6a500337d25e856b850a7d711"}})
But where is commit 0d8c06bf23ec65a6a500337d25e856b850a7d711
?
No reason it shouldn't find that, it is definitely there: https://github.com/tsloughter/chatterbox/commit/0d8c06bf23ec65a6a500337d25e856b850a7d711
Because I haven't got the chatterbox changes merged to master and pushed to hex this was in a sort of state of flux. Once that is done I'll publish new releases known to work together.
Though from master for both grpcbox and the plugin they should work together.
Yes, i only seach the master branch...
After upgrade the plugin, rebar3 grpc gen
did generate *_client.erl
file!
but another issue is
===> Compiling src/hellostreamingworld_multi_greeter_client.erl failed
src/hellostreamingworld_multi_greeter_client.erl:13: can't find include file "grpcbox.hrl"
when rebar3 compile
(I can found this hrl file in the ./_build/default/lib/grpcbox/include)
If i skip the can't find "grpcbox.hrl" file issue
(by copy the grpcbox.hrl into the project's include folder)
I run rebar3 shell
1> hellostreamingworld_multi_greeter_client:say_hello(ctx:new(), #{name => "Woc", num_greetings => 3}, #{}).
** exception error: bad argument
in function ets:lookup/2
called as ets:lookup(gproc,{{p,l,{gproc_pool,default_channel}},shared})
in call from gproc:get_value1/2 (/home/johnzhuang/coding/erl-repos/myapp/_build/default/lib/gproc/src/gproc.erl, line 1602)
in call from gproc:get_value/2 (/home/johnzhuang/coding/erl-repos/myapp/_build/default/lib/gproc/src/gproc.erl, line 1584)
in call from gproc_pool:pick_worker/1 (/home/johnzhuang/coding/erl-repos/myapp/_build/default/lib/gproc/src/gproc_pool.erl, line 314)
in call from grpcbox_channel:pick/2 (/home/johnzhuang/coding/erl-repos/myapp/_build/default/lib/grpcbox/src/grpcbox_channel.erl, line 47)
in call from grpcbox_client:stream/5 (/home/johnzhuang/coding/erl-repos/myapp/_build/default/lib/grpcbox/src/grpcbox_client.erl, line 121)
syntax = "proto3";
package hellostreamingworld;
// The greeting service definition.
service MultiGreeter {
// Sends multiple greetings
rpc sayHello (HelloRequest) returns (stream HelloReply) {}
}
// The request message containing the user's name and how many greetings
// they want.
message HelloRequest {
string name = 1;
string num_greetings = 2;
}
// A response message containing a greeting
message HelloReply {
string message = 1;
}
And there is a sys.config
in config
folder of project, with
[
{ myapp, [{client, #{channels => [{default_channel, [{http, "localhost", 50051, []}], #{}}]}}]}
].
What's the problem ?
Hm, that error (I should make it better and will) is that the channel isn't found.
Are you sure the server is listening?
Yes, the server is listening, I am using google grpc python demo server, and I have tested it with grpc_client.
Maybe I have mistake on setting channel?
If I set channel manually like below
helloworld_greeter_client:say_hello(ctx:new(), #{name => "Joe"}, #{channel => [{http, "localhost", 50051, []}]}).
That's OK?
Na, the channel needs to be started and is references an atom
that represents the channel's pool and is used to pick a subchannel:
gproc_pool:pick_worker(Name)
Though first i'd verify that in the shell application:get_env(grpcbox, client)
returns what you'd expect based on your config.
Maybe your config isn't being used? Or grpcbox isn't being started when you run shell
? You can do rebar3 shell --config config/sys.config
or set that in your rebar.config
under the {shell, [...]}
Very interesting, when I first application:get_env(grpcbox, client)
, it returns undefined. Then I add grpcbox
onto the apps, now my
{erl_opts, [debug_info]}.
{deps, [{grpcbox, {git, "https://github.com/tsloughter/grpcbox.git", {branch, "master"}}}]}.
{grpc, [{protos, "priv/protos"},
{gpb_opts, [{module_name_suffix, "_pb"}]}]}.
{plugins, [{grpcbox_plugin, {git, "https://github.com/tsloughter/grpcbox_plugin.git", {branch, "master"}}}]}.
{shell, [
{config, "config/sys.config"},
{apps, [myapp, grpcbox]}
]}.
But when i re-run application:get_env(grpcbox, client)
(in rebar3 shell --config config/sys.config
), It returns {ok,#{channels => []}}
[
{ myapp,
[
{client, #{channels => [{default_channel, [{http, "localhost", 50051, []}], #{}}]}},
{pool_opts, #{size => 10}},
{grpc_opts, #{service_protos => [helloworld_pb, hellostreamingworld_pb]}}
]
}
].
It seems like not load client config, and why
Oooh, I should have noticed this the first time you posted your sys config.
You need to put the options for grpc under grpcbox
, so:
[
{ grpcbox,
[
{client, #{channels => [{default_channel, [{http, "localhost", 50051, []}], #{}}]}},
{pool_opts, #{size => 10}},
{grpc_opts, #{service_protos => [helloworld_pb, hellostreamingworld_pb]}}
]
}
].
That's it! I mistakenly think the options is for myapp... After recorrected it, I can get channel config, and get response from grpc server. Thank you very much!
Great!
I have read the README about https://github.com/tsloughter/grpcbox#using-a-service-client. However, When I run
rebar3 gprc gen
on the root of my project, it only creates*_pb.erl
and*_bhvr.erl
. So, there is any other steps to generate<service>_client.erl
?