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

feat: http transcoding grpc #1583

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,17 @@ object @{serviceName}Handler {
.recoverWith(GrpcExceptionHandler.from(eHandler(system.classicSystem))(system, writer))
).getOrElse(unsupportedMediaType)

Function.unlift((req: model.HttpRequest) => req.uri.path match {


val httpHandler = akka.grpc.HttpApi.serve(@{service.name}.descriptor, handle _)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effectively elevates HttpApi.serve to stable API: if a project uses code generated by this version, and updates the Akka gRPC runtime library, we'll have to make sure these new versions of the runtime library still provide that serve function with the same signature and behavior. I'm not sure I'm comfortable with that yet.

I wonder if it would be possible to use this HttpApi from the main client code, so the user can optionally enable it, and we can mark it ApiMayChange to leave room for evolving the API further later?


val grpcHandler = Function.unlift((req: model.HttpRequest) => req.uri.path match {
case model.Uri.Path.Slash(model.Uri.Path.Segment(`prefix`, model.Uri.Path.Slash(model.Uri.Path.Segment(method, model.Uri.Path.Empty)))) =>
Some(handle(spi.onRequest(prefix, method, req), method))
case _ =>
None
})
httpHandler orElse grpcHandler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems potentially tricky: some high-throughput use cases might only care about the gRPC protocol, and hard-coding the HTTP transcoding support here might impact that hot path.

}
}
}
3 changes: 3 additions & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ object Dependencies {

object Protobuf {
val protobufJava = "com.google.protobuf" % "protobuf-java" % Versions.googleProtobuf
val protobufJavaUtil = "com.google.protobuf" % "protobuf-java-util" % Versions.googleProtobuf
val googleCommonProtos = "com.google.protobuf" % "protobuf-java" % Versions.googleProtobuf % "protobuf"
}

Expand All @@ -100,6 +101,8 @@ object Dependencies {
val runtime = l ++= Seq(
Compile.scalapbRuntime,
Protobuf.protobufJava, // or else scalapb pulls older version in transitively
Protobuf.protobufJavaUtil,
Protobuf.googleCommonProtos,
Compile.grpcCore,
Compile.grpcStub % "provided", // comes from the generators
Compile.grpcNettyShaded,
Expand Down
32 changes: 32 additions & 0 deletions runtime/src/main/protobuf/google/api/annotations.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2015, Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package google.api;

import "google/api/http.proto";
import "google/protobuf/descriptor.proto";

option csharp_namespace = "Google.Protobuf";
option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations";
option java_multiple_files = true;
option java_outer_classname = "AnnotationsProto";
option java_package = "com.google.api";
option objc_class_prefix = "GAPI";

extend google.protobuf.MethodOptions {
// See `HttpRule`.
HttpRule http = 72295728;
}
Loading