Skip to content

Conversation

@vasu-dasari
Copy link

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:

Point = #'Point'{
    latitude = 409146138,
    longitude = -746188906
},
Return = route_guide_client:'GetFeature'(Connection, Point, [{msgs_as_records,route_guide_pb}]).

Return will also be presented to caller as 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">>}}}

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">>}}}
@vasu-dasari vasu-dasari mentioned this pull request Oct 27, 2017
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.
@vasu-dasari vasu-dasari changed the title Issue 1: Add ability to specify protocol buffer messages as records Fixes for Issue 1 and Issue 3 Nov 26, 2017
Copy link
Member

@cmullaparthi cmullaparthi left a 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.

%% @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) ->
Copy link
Member

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?

end, Headers, maps:to_list(Metadata)).

info_response(Response, #{async_notification := Client} = Stream) when is_pid(Client) ->
Client ! {notification,Response},
Copy link
Member

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}
@vasu-dasari
Copy link
Author

@cmullaparthi Updated the code as recommended. Let me know if more needs to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants