Lightbend Lagom 和 Akka:无法访问 lagom 服务的其余端点

Lightbend Lagom and Akka: Unable to hit rest endpoint of lagom services

我正在创建 lagom 简单应用程序,定义一个休息端点并使用休息客户端邮递员命中终点。但作为回应,我收到了“找不到操作”错误。我正在将 Akka 与 lagom 集成,以下是我的代码:

服务:

trait TwitterSchedulerService extends Service {

  def doWork: ServiceCall[NotUsed, Done]

  override def descriptor: Descriptor = {
    import Service._
    named("scheduler").withCalls(
      call(doWork)
    )
  }
}

ServiceImpl

class TwitterSchedulerServiceImpl(system: ActorSystem) extends TwitterSchedulerService {

  override def doWork = ServiceCall { _ =>
    Future {
      println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ")
      Done
    }
  }
}

加载程序配置:

class TwitterLoader extends LagomApplicationLoader {

  override def load(context: LagomApplicationContext): LagomApplication =
    new TwitterApplication(context) {
      override def serviceLocator = NoServiceLocator
    }

}

object TwitterSerializerRegistry extends JsonSerializerRegistry {

  override val serializers = Vector(
    JsonSerializer[String]
  )
}

abstract class TwitterApplication(context: LagomApplicationContext) extends LagomApplication(context)
  with CassandraPersistenceComponents with AhcWSComponents {

  override lazy val lagomServer = LagomServer.forServices(
    bindService[TwitterSchedulerService].to(wire[TwitterSchedulerServiceImpl])
  )
  override lazy val jsonSerializerRegistry = TwitterSerializerRegistry
}

我正在关注 lagom 文档 http://www.lagomframework.com/documentation/1.3.x/scala/Akka.html。我想知道,为什么会出现这个错误,事件中所有的休息点都被定义了???

您的服务 运行 http://localhost:57211

http://localhost:9000 是 运行 服务网关服务器,充当您项目中所有服务 运行 的反向代理。

服务网关可以配置为将服务调用转发到您的服务,但默认情况下不会。您可以通过在服务描述符中定义 ACL(访问控制列表)来配置它。

最常见的情况是,您将调用 withAutoAcl(true) 自动将所有服务调用路径转发到您的服务:

trait TwitterSchedulerService extends Service {

  def doWork: ServiceCall[NotUsed, Done]

  override def descriptor: Descriptor = {
    import Service._
    named("scheduler").withCalls(
      call(doWork)
    ).withAutoAcl(true)
  }
}

如果您想更好地控制哪些路径从服务网关转发到 back-end 服务,您可以调用 withAcls 来传递一个显式方法列表和路径正则表达式,它们应该是从服务网关转发:

trait TwitterSchedulerService extends Service {

  def doWork: ServiceCall[NotUsed, Done]

  override def descriptor: Descriptor = {
    import Service._
    named("scheduler").withCalls(
      call(doWork)
    ).withAcls(
      ServiceAcl.forPathRegex("/doWork")
    )
  }
}

如果您部署到 ConductR(Lightbend 生产套件的一部分),您服务描述符中的这些 ACL 配置也用于生成 ConductR ACL configuration