【问题标题】:Scala Play HTTP and gRPCScala Play HTTP 和 gRPC
【发布时间】:2020-09-11 04:40:15
【问题描述】:

我有一个带有 Scala Play 的 HTTP 后端。工作正常。 现在我想在它上面设置一个 gRPC-API(理论上应该可以)。

要设置 gRPC,我基本上遵循 akka-quickstart

我可以运行 sbt compile 并在 target/../ dic 中获取我生成的 Scala 类。 但是如果我尝试运行 sbt run 我会得到

--- (Running the application, auto-reloading is enabled) ---

[warn] a.u.ManifestInfo - You are using version 2.6.5 of Akka, but it appears you (perhaps indirectly) also depend on older versions of related artifacts. You can solve this by adding an explicit dependency on version 2.6.5 of the [akka-discovery] artifacts to your project. See also: https://doc.akka.io/docs/akka/current/common/binary-compatibility-rules.html#mixed-versioning-is-not-allowed
[error] java.lang.IllegalStateException: You are using version 2.6.5 of Akka, but it appears you (perhaps indirectly) also depend on older versions of related artifacts. You can solve this by adding an explicit dependency on version 2.6.5 of the [akka-discovery] artifacts to your project. See also: https://doc.akka.io/docs/akka/current/common/binary-compatibility-rules.html#mixed-versioning-is-not-allowed

所以我知道我使用的一些库对于 Akka 2.6.5 来说太旧了,但我不明白如何在较低的 Akka 版本上设置我的服务。

我的插件.sbt

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.2")
addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.11.0")
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "1.0.0-M1")
resolvers += Resolver.bintrayRepo("playframework", "maven")
libraryDependencies += "com.lightbend.play" %% "play-grpc-generators" % "0.8.2"

我的 build.sbt


name := "smartmarkt"
version := "1.0-SNAPSHOT"
scalaVersion := "2.13.2"

lazy val root = (project in file("."))
  .enablePlugins(PlayScala, PlayAkkaHttp2Support, AkkaGrpcPlugin)

import play.grpc.gen.scaladsl.PlayScalaServerCodeGenerator
akkaGrpcExtraGenerators += PlayScalaServerCodeGenerator
libraryDependencies += "com.lightbend.play" %% "play-grpc-runtime" % "0.8.2"

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test

【问题讨论】:

    标签: scala playframework akka akka-http akka-grpc


    【解决方案1】:

    查看您的直接依赖项:

    "com.lightbend.play" %% "play-grpc-runtime" % "0.8.2" 依赖于 akka-discovery 2.6.4。

    您正在使用取决于 Akka 2.6.5 版本的 Play 2.8.2。

    只需将 akka-discovery 2.6.5 的依赖添加到您的依赖项中:

    libraryDependencies += "com.typesafe.akka" %% "akka-discovery" % "2.6.5"
    

    【讨论】:

    • 工作正常。谢谢^^
    猜你喜欢
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 2016-07-08
    • 2017-03-27
    • 1970-01-01
    • 2020-04-16
    • 1970-01-01
    相关资源
    最近更新 更多