I have an akka grpc client, the code attempts to send a seq to remote python grpc server to get results:
package com.example.predict
import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.grpc.GrpcClientSettings
import org.apache.openwhisk.grpc.{PredictRequest, PredictServiceClient}
import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success}
object PredictClient {
def main(args: Array[String]): Unit = {
implicit val sys: ActorSystem[_] = ActorSystem(Behaviors.empty, "PredictClient")
implicit val ec: ExecutionContext = sys.executionContext
val clientSettings = GrpcClientSettings.connectToServiceAt("127.0.0.1", 9999).withTls(false)
val client = PredictServiceClient(clientSettings)
val reply = client.predict(PredictRequest(Seq(1,2,2,3,3,4)))
reply.onComplete{
case Success(msg) =>
println(s"the result is : ${msg.results}")
case Failure(e) =>
println(s"Error: $e")
}
}
}
I simply click run PredictClient in IntelliJ IDEA to run the main method, but after successfully getting the result and printing, the code kept running. Even when I added client.close() at the end of the main method still kept running and coundn't stop. How to successfully finish the main method after I getting the result? Is there something I missed?
The
ActorSystemtypically has to be manually terminated, e.g. with: