我有一个akka流,该流连续不断地使用kafka主题中的数据。 我从未关闭过actorsystem,我不希望我的应用程序关闭是正确的方法吗?处理actorySystem关闭的正确方法是什么?
implicit val actorSystem: ActorSystem = ActorSystem("mytest")
implicit val materializer: ActorMaterializer =
ActorMaterializer(ActorMaterializerSettings(actorSystem).withSupervisionStrategy(decider))
val actorConfig = actorSystem.settings.config.getConfig("akka.kafka.consumer")
val consumerSettings =
ConsumerSettings(actorConfig, new StringDeserializer, new StringDeserializer)
.withBootstrapServers(config.getString("kafka.hosts"))
.withGroupId("mytestgrp")
val flow = Consumer
.atMostOnceSource(consumerSettings, Subscriptions.topics(config.getString("kafka.topic")))
.grouped(500)
.map(Pipeline.process)
.withAttributes(supervisionStrategy(decider))
flow.runWith(Sink.ignore)
答案 0 :(得分:0)
流完成后,您可以关闭actor系统
flow.runWith(Sink.ignore).onComplete {
case _ => actorSystem.shutdown
}