Skip to content
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

Server Streaming RPC support #14

Merged
merged 5 commits into from
Jan 1, 2018
Merged

Server Streaming RPC support #14

merged 5 commits into from
Jan 1, 2018

Conversation

Xorlev
Copy link
Owner

@Xorlev Xorlev commented Mar 11, 2017

Server streaming is implemented as a stream of newline-delimited
protojson entries. Messages are flushed to a ChunkedOutput (Jersey only,
StreamingOutput was giving me trouble) upon receipt from the server
stub. As HTTP/1.1 lacks wide support for trailers, the only realistic
way to signal mid-stream error is to emit an error struct (or hang up). On error, a
google.rpc.Status proto is emitted and the request is ended, e.x.

< HTTP/1.1 200 OK
< Date: Sat, 11 Mar 2017 20:59:01 GMT
< Vary: Accept
< Content-Type: application/json;charset=utf-8
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
<
{"request":{"s":"23","int3":40}}
{"code":15,"message":"HTTP 500 (gRPC: DATA_LOSS): Terribly sorry, a grue ate your data. :("}

Additionally, stream handlers support responding to the text/event-stream
MIMEType. When encountered, grpc-jersey emits data: {protojson}\n\n
for compatibility with general ServerSentEvents, allowing use by
EventStream in browser JavaScript.

All error handling is done through Jersey{Unary,Streaming}Observer now, which delegates error handling to an instance of GrpcJerseyErrorHandler. This instance can be statically set at runtime (ideally before requests begin) by calling ErrorHandler#setErrorHandler, e.g.:

GrpcJerseyErrorHandler errorHandler = new MyErrorHandler();
ErrorHandler.setErrorHandler(errorHandler);
// Go on with setup...

Punted to another PR:

  • Client streaming
  • Bidi streaming (or, at least what can be done without HTTP/2 or Websockets)

@Xorlev Xorlev force-pushed the streaming branch 4 times, most recently from 14253cf to a3ee803 Compare December 30, 2017 07:51
@Xorlev Xorlev changed the title [WIP] Streaming RPC support Server Streaming RPC support Dec 30, 2017
Server streaming is implemented as a stream of newline-delimited
protojson entries. Messages are flushed to a ChunkedOutput (Jersey only,
no alternative JAX-RS implementations) upon receipt from the server
stub. As HTTP/1.1 lacks wide support for trailers, the only realistic
way to signal mid-stream error is to emit an error struct. On error, a
google.rpc.Status proto is emitted and the request is ended.

Additionally, stream handlers support responding to the `text/event-stream`
MIMEType. When encountered, grpc-jersey emits "data: {protojson}\n\n"
for compatibility with general ServerSentEvents, allowing use by
EventStream in browser JavaScript.

All error handling is done through Jersey{Unary,Streaming}Observer now.
This simplifies generated code and provides a single point for
controlling behavior, even at runtime and without requiring regeneration
of code.

Unresolved:
- Trailers from gRPC handler don't seem to make it to
  JerseyStreamingObserver#onError. Might be a InProcessChannel artifact.
ErrorHandler now provides static (but settable) state to change the
error handler if the default is insufficient or undesirable.

Users can implement GrpcJerseyErrorHandler and set it as the error
handler using ErrorHandler#setErrorHandler.
JsonFormat.Printer instances can now be set JVM-global via
JsonHandler.setUnaryPrinter/.setStreamPrinter.
@Xorlev Xorlev merged commit 8a022db into master Jan 1, 2018
@Xorlev Xorlev deleted the streaming branch January 1, 2018 20:34
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.

1 participant