首页 > 解决方案 > Akka gRPC/HTTP Interop 给出 404

问题描述

我有一个运行 gRPC 服务的应用程序以及一个简单的 Akka HTTP 端点。我正在关注本指南:https ://doc.akka.io/docs/akka-grpc/current/server/akka-http.html 。问题:当卷曲 HTTP 端点时,我得到 404 未找到。我知道它找到了服务器,因为 Akka-HTTP/10.2.5 是响应标头的服务器。

一些代码:

object Server extends App {
        val conf = ConfigFactory
            .parseString("akka.http.server.preview.enable-http2 = on")
            .withFallback(ConfigFactory.defaultApplication())
        val system = ActorSystem("Interop", conf)
        new Server(system).run()
}

class Server(system: ActorSystem) {
    def run() = {
        // implicit sys, ec...
        val grpcService: HttpRequest => Future[HttpResponse] = ServiceHandler(new Service())
        val greeter = get {
            pathEndOrSingleSlash {
                complete("I am alive")
            }
        }
        // lifted this line straight out of the guide
        val grpcRoute = { ctx => grpcService(ctx.request).map(RouteResult.Complete) }
        val route = concat(greeter, grpcRoute)
        val binding = Http().newServerAt("127.0.0.1", 8080).bind(route)
        binding
    }
}

当我取出 gRPC 路由时,greeter 端点按预期工作。否则,当我curl http://localhost:8080,我得到

*Mark bundle as not supporting multiuser
<HTTP/1.1 404 Not Found
<Server: akka-http/10.2.5
<other-stuff

我正在使用 akka-gRPC 2.0.0

我应该怎么做才能确保两条路由之间的互操作?

标签: scalaakkahttp2akka-httpakka-grpc

解决方案


gRPC 使用 HTTP/2,所以试试

curl --http2 http://localhost:8080

它还应该摆脱最初的“标记捆绑...”消息。


推荐阅读