我正在 lagom 项目中创建一个模块。我的模块只有 kafka 消费者用于在 cassandra 中消费消息和存储消息事件。谢谢为什么,在我LagomApplicationLoader
没有定义任何服务并lagomServer
用LagomServer.forServices()
. 但是每当我开始我的应用程序时,我都会遇到以下异常:
java.lang.IllegalArgumentException
at com.lightbend.lagom.scaladsl.server.LagomServer$$anon$2.<init>(LagomServer.scala:35)
at com.lightbend.lagom.scaladsl.server.LagomServer$.forServices(LagomServer.scala:31)
at com.knoldus.consumer.impl.TwitterConsumerApplication.lagomServer$lzycompute(TwitterConsumerLoader.scala:33)
at com.knoldus.consumer.impl.TwitterConsumerApplication.lagomServer(TwitterConsumerLoader.scala:33)
at com.lightbend.lagom.scaladsl.server.LagomApplication.<init>(LagomApplicationLoader.scala:187)
at com.knoldus.consumer.impl.TwitterConsumerApplication.<init>(TwitterConsumerLoader.scala:28)
at com.knoldus.consumer.impl.TwitterConsumerLoader$$anon$1.<init>(TwitterConsumerLoader.scala:25)
at com.knoldus.consumer.impl.TwitterConsumerLoader.loadDevMode(TwitterConsumerLoader.scala:25)
at com.lightbend.lagom.scaladsl.server.LagomApplicationLoader.load(LagomApplicationLoader.scala:54)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2$$anonfun$3.apply(LagomReloadableDevServerStart.scala:151)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2$$anonfun$3.apply(LagomReloadableDevServerStart.scala:148)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2.apply(LagomReloadableDevServerStart.scala:148)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1$$anonfun$2.apply(LagomReloadableDevServerStart.scala:124)
at scala.Option.map(Option.scala:146)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1.apply(LagomReloadableDevServerStart.scala:124)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1$$anonfun$apply$1.apply(LagomReloadableDevServerStart.scala:122)
at scala.util.Success.flatMap(Try.scala:231)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1.apply(LagomReloadableDevServerStart.scala:122)
at play.core.server.LagomReloadableDevServerStart$$anonfun$mainDev$1$$anon$2$$anonfun$get$1.apply(LagomReloadableDevServerStart.scala:114)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
我的代码:
class TwitterConsumerLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new TwitterConsumerApplication(context) {
override def serviceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new TwitterConsumerApplication(context) with LagomDevModeComponents
}
abstract class TwitterConsumerApplication(context: LagomApplicationContext) extends LagomApplication(context)
with CassandraPersistenceComponents with AhcWSComponents with LagomKafkaComponents {
lazy val twitterService = serviceClient.implement[TwitterProducerService]
override lazy val lagomServer = LagomServer.forServices()
override lazy val jsonSerializerRegistry = TwitterSerializerRegistry
persistentEntityRegistry.register(wire[TweetEntity])
wire[TwitterProducerSubscriber]
}
如何在 lagom 中声明空服务。如果这是不可能的,还有什么其他的选择?因为可能在将来,它可能需要在这个模块中创建一些服务。我该如何解决这个问题?