【问题标题】:Lightbend Lagom and Akka: Unable to hit rest endpoint of lagom servicesLightbend Lagom 和 Akka:无法访问 lagom 服务的休息端点
【发布时间】:2017-02-17 14:20:02
【问题描述】:

我正在创建 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。我想知道,为什么会出现这个错误,event all rest points are defined???

【问题讨论】:

  • 嗨@harmeet-singh-taara,您可以发布错误消息和您用来测试代码的curl 命令吗?
  • 当然,GET request http://localhost:9000/doWork。 @ignasi35 我正在使用 Postman,但未找到响应 404。
  • 当我使用GET request with http://localhost:57211/doWork url 时。我的请求过程很好。但是还是不明白,为什么9000 发帖不灵了?

标签: scala rest akka http-status-code-404 lagom


【解决方案1】:

您的服务在 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)
  }
}

如果您想更好地控制从服务网关转发到后端服务的路径,您可以调用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 Production Suite 的一部分),则服务描述符中的这些 ACL 配置也用于生成 ConductR ACL configuration

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-14
    • 2021-10-25
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多