Skip to content

Commit

Permalink
Enhance servicetalk-examples-grpc-observer (#2172)
Browse files Browse the repository at this point in the history
Motivation:

Demonstrate two different ways how to configure `GrpcLifecycleObserver`.

Modifications:

- Add more comments and option 2 in `LifecycleObserverServer`;

Result:

Users can see how to configure `GrpcLifecycleObserver` in 2 different
ways.
  • Loading branch information
idelpivnitskiy authored Apr 8, 2022
1 parent fce6b3e commit 6620b3c
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@
*/
public final class LifecycleObserverServer {
public static void main(String... args) throws Exception {
GrpcLifecycleObserver observer =
GrpcLifecycleObservers.logging("servicetalk-examples-grpc-observer-logger", TRACE);
GrpcServers.forPort(8080)
.lifecycleObserver(GrpcLifecycleObservers.logging("servicetalk-examples-grpc-observer-logger", TRACE))
// Option 1: apply an observer for entire server to capture processing by all filters:
.lifecycleObserver(observer)
// Option 2: apply an observer using a filter to move it later in a filter chain (before/after tracing
// info is available or retry/timeout/authentication/exception-mapping filters applied), or to apply it
// conditionally:
// .initializeHttp(builder -> builder
// .appendNonOffloadingServiceFilter(tracingFilter)
// .appendNonOffloadingServiceFilter(new GrpcLifecycleObserverServiceFilter(observer)))
.listenAndAwait((GreeterService) (ctx, request) ->
succeeded(HelloReply.newBuilder().setMessage("Hello " + request.getName()).build()))
.awaitShutdown();
Expand Down

0 comments on commit 6620b3c

Please sign in to comment.