scala - Scala Play HTTP 和 gRPC
问题描述
我有一个带有 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
解决方案
查看您的直接依赖项:
"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"
推荐阅读
- swift - 为什么 Swift 编译器不能推断带有关联项的协议的返回类型?
- python - Django:按模型参数和计数分组
- encryption - OpenSSL:在 RSA 中使用私钥加密并使用公钥解密
- python - 按 2 个计数过滤 Pandas 数据框
- c# - 使用带有 HTTPWEBREQUEST 的 JSON 字符串发送文件时获取 System.Security.SecurityException
- javascript - 我如何以及何时在 React 组件中使用 useReducer?
- java - 房间数据库架构更新
- android - 有没有办法在 Android Zebra TC520K 上以编程方式扫描 ITF-14 条码?
- javascript - 如何使用ajax控制套件从当前日期选择三个日期之后的日期
- python - 通过 API 调用获取信息并进行身份验证