-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for Issue 1 and Issue 3 #2
base: master
Are you sure you want to change the base?
Conversation
Module which deals with records needs to be given as input to unary RPC call. This can be presented as a tuple to the Options list that is passed to grpc_client:unary(). {msgs_as_records,ModuleName}. And user is expeced to generate records based header file using gpb. This can be out of the scope of grpc_client API. For example for our route_guide example: Point = #'Point'{ latitude = 409146138, longitude = -746188906 }, Return = route_guide_client:'GetFeature'(Connection, Point, [{msgs_as_records,route_guide_pb}]). API Return will also include a record: {ok,#{grpc_status => 0, headers => #{<<":status">> => <<"200">>}, http_status => 200, result => {'Feature',<<"Berkshire Valley Management Area Trail, Jefferson, NJ, USA">>, {'Point',409146138,-746188906}}, status_message => <<>>, trailers => #{<<"grpc-status">> => <<"0">>}}}
Details of this request in "Issue 3". With this code, user can create a streaming RPC connection by specifying how messages have to be deliverd. {ok, Stream} = grpc_client:new_stream(Connection, 'RouteGuide', 'RouteChat', route_guide, [{async_notification, self()}]). And when a notification arrives on the stream, a message of the following form {notification,Response} will be delivered to the calling process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @vasu-dasari thanks for this pull request and many apologies for the long delay. I have just a couple of minor comments. Could you please address them and then I can merge.
src/grpc_client.erl
Outdated
@@ -180,16 +180,14 @@ new_stream(Connection, Service, Rpc, DecoderModule, Options) -> | |||
|
|||
-spec send(Stream::client_stream(), Msg::map()) -> ok. | |||
%% @doc Send a message from the client to the server. | |||
send(Stream, Msg) when is_pid(Stream), | |||
is_map(Msg) -> | |||
send(Stream, Msg) when is_pid(Stream) -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update the function spec here?
src/grpc_client_stream.erl
Outdated
@@ -314,6 +318,9 @@ add_metadata(Headers, Metadata) -> | |||
lists:keystore(K, 1, Acc, {K,V}) | |||
end, Headers, maps:to_list(Metadata)). | |||
|
|||
info_response(Response, #{async_notification := Client} = Stream) when is_pid(Client) -> | |||
Client ! {notification,Response}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether it would be better to have the notification message as something like {grpc_notification, Response}
. Using the atom notification
seems too generic.
Specs to reflect message to be of type tuple (records) or map
As per code review comment, update notification sent to registered clients as {grpc_notification,Response}
@cmullaparthi Updated the code as recommended. Let me know if more needs to be done. |
The module which deals with records needs to be given as input to unary RPC call. This can be presented as a tuple to the Options list that is passed to grpc_client:unary().
{msgs_as_records,ModuleName}.
And the user is expected to generate records based header file using gpb. This can be out of the scope of grpc_client API.
For example for our route_guide example:
Return will also be presented to caller as a record: