gpt4 book ai didi

scala - Lightbend Lagom 和 Akka : Unable to hit rest endpoint of lagom services

转载 作者:行者123 更新时间:2023-12-01 19:37:36 24 4
gpt4 key购买 nike

我正在创建 lagom 简单应用程序,定义一个休息端点并使用休息客户端 postman 命中端点。但作为回应,我收到了“未找到操作”错误。我正在将 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)
}
}

如果您想要更多地控制从服务网关转发到后端服务的路径,您可以调用 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 .

关于scala - Lightbend Lagom 和 Akka : Unable to hit rest endpoint of lagom services,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42281846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com