Skip to content

Commit

Permalink
addressing comment
Browse files Browse the repository at this point in the history
- Removing builder reference
  • Loading branch information
franciscolopezsancho committed Sep 11, 2024
1 parent 8fde275 commit 9c0a203
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
12 changes: 7 additions & 5 deletions docs/src/modules/java-protobuf/pages/call-another-service.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ include::example$scala-protobuf-doc-snippets/src/main/scala/com/example/Delegati

To pass headers to this client you need to `lift` (by casting) the service interface to the specific client.
In this example, casting the service interface `com.example.CounterService` to the client class `com.example.CounterServiceClient`.
Once this is done you can call the desired method to create a request builder, add the headers, and then `invoke` the builder with the desired input.
Once this is done you can build the desired method, add the headers, and then `invoke` the method with the desired input.

In our delegating implementation:

Expand All @@ -84,8 +84,9 @@ Java::
include::java-protobuf:example$java-protobuf-doc-snippets/src/main/java/com/example/DelegatingServiceAction.java[tag=delegating-action-lifted]
----
+
<1> Casting, creating the request builder with `increase()`, and adding the headers to it.
<2> Invoke the builder with the desired `increaseValue` parameter.
<1> Casting and building the `increase()` method
<2> Add the headers to it.
<3> Invoke the method with the desired `increaseValue` parameter.

Scala::
+
Expand All @@ -95,8 +96,9 @@ Scala::
include::example$scala-protobuf-doc-snippets/src/main/scala/com/example/DelegatingServiceAction.scala[tag=delegating-action-lifted]
----
+
<1> Casting, creating the request builder with `increase()`, and adding the headers to it.
<2> Invoke the builder with the desired `increaseValue` parameter.
<1> Casting and building the `increase()` method
<2> Add the headers to it.
<3> Invoke the method with the desired `increaseValue` parameter.

For additional documentation about Akka gRPC see the https://doc.akka.io/docs/akka-grpc/current/index.html[Akka gRPC documentation].

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ public Effect<DelegatingServiceApi.Result> addAndReturn(DelegatingServiceApi.Req
public Effect<DelegatingServiceApi.Result> addAndReturnLifted(DelegatingServiceApi.Request request) {
CounterService counterService = actionContext().getGrpcClient(CounterService.class, "counter");
// tag::delegating-action-lifted[]
SingleResponseRequestBuilder<CounterApi.IncreaseValue, Empty> counterServiceClientBuilder
= ((CounterServiceClient) counterService).increase().addHeader("key", "value"); // <1>


CounterApi.IncreaseValue increaseValue = CounterApi.IncreaseValue.newBuilder()
.setCounterId(request.getCounterId())
.setValue(1)
.build();
CompletionStage<Empty> increaseCompleted = counterServiceClientBuilder.invoke(increaseValue); // <2>
CompletionStage<Empty> increaseCompleted = ((CounterServiceClient) counterService).increase() // <1>
.addHeader("key", "value") // <2>
.invoke(increaseValue); // <3>
// end::delegating-action-lifted[]
CompletionStage<CounterApi.CurrentCounter> currentCounterValueAfter = increaseCompleted.thenCompose((empty) ->
// once increase completed successfully, ask for the current state after
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class DelegatingServiceAction(creationContext: ActionCreationContext) extends Ab

val counterService = actionContext.getGrpcClient(classOf[CounterService], "counter")
// tag::delegating-action-lifted[]
val counterServiceClientBuilder: SingleResponseRequestBuilder[IncreaseValue, Empty] =
counterService.asInstanceOf[CounterServiceClient].increase().addHeader("key","value") // <1>
val increaseValue = IncreaseValue(counterId = request.counterId, value = 1)
val increaseCompleted = counterServiceClientBuilder.invoke(increaseValue) // <2>
val increaseCompleted = counterService.asInstanceOf[CounterServiceClient].increase() // <1>
.addHeader("key","value") // <2>
.invoke(increaseValue) // <3>
// end::delegating-action-lifted[]

val currentCounterValueAfter = increaseCompleted.flatMap(_ =>
Expand Down

0 comments on commit 9c0a203

Please sign in to comment.