我有两项服务:一项发送流数据,另一项使用akka-grpc进行通信。提供源数据后,将调用服务1处理并通过grpc客户端将其发送给服务2。在同时提供多个源数据的情况下,可能同时运行一个服务器的多个实例。在我的应用程序的长期运行测试中。我在服务一中看到以下错误:
ERROR i.a.g.application.actors.DbActor - GraphStage [akka.grpc.internal.AkkaNettyGrpcClientGraphStage$$anon$1@59d40805] terminated abruptly, caused by for example materializer or act
akka.stream.AbruptStageTerminationException: GraphStage [akka.grpc.internal.AkkaNettyGrpcClientGraphStage$$anon$1@59d40805] terminated abruptly, caused by for example materializer or actor system termination.
我从来没有关闭过演员系统,只有在完成工作后才杀死演员。另外,我使用proto3
和http2
进行请求绑定。这是我在使用中的一段代码:
////////////////////server http binding /////////
val service: HttpRequest => Future[HttpResponse] =
ServiceOneServiceHandler(new ServiceOneServiceImpl(system))
val bound = Http().bindAndHandleAsync(
service,
interface = config.getString("akka.grpc.server.interface"),
port = config.getString("akka.grpc.server.default-http-port").toInt,
connectionContext = HttpConnectionContext(http2 = Always))
bound.foreach { binding =>
logger.info(s"gRPC server bound to: ${binding.localAddress}")
}
////////////////////client /////////
def send2Server[A](data: ListBuffer[A]): Future[ResponseDTO] = {
val reply = {
val thisClient = interface.initialize()
interface.call(client = thisClient, req = data.asInstanceOf[ListBuffer[StoreRequest]].toList)
}
reply
}
///////////////// grpc communication //////////
def send2GrpcServer[A](data: ListBuffer[A]): Unit = {
val reply = send2Server(data)
Await.ready(reply, Duration.Inf) onComplete {
case util.Success(response: ResponseDTO) =>
logger.info(s"got reply message: ${res.description}")
//////check response content and stop application if desired result not found in response
}
case util.Failure(exp) =>
//////stop application
throw exp.getCause
}
}
在等待服务2响应后恰好发生了错误:
Await.ready(reply, Duration.Inf)
我找不到原因。
更新
我发现错过了某个流,因此服务一发送一个流无限期地等待响应,而服务二没有收到任何要回复服务一的东西,但仍然不知道为什么错过了流 我还更新了akka grpc插件,但没有任何意义:
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "0.6.1")
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.4")