服务元数据,也称为ServiceInfo,包括一个名称和一个服务ACL集合。元数据在大多数情况下是自动计算的,您不需要检查它,甚至不需要提供它。
Lagom支持以下几种场景:
- 当您创建一个Lagom服务并将应用程序连接在一起时,Lagom将把
name和ACL绑定到一个ServiceInfo中。 - 当你使用Lagom服务并混合
LagomServiceClientComponents来绑定客户端时,Lagom并没有在背后注入一个ServiceInfo,你必须通过编程提供一个。 - 最后一种情况是,客户端应用程序不使用Guice,而是通过Lagom客户端工厂连接到Lagom。在这个场景中,Lagom还将为您创建元数据。
服务名称和服务ACL
服务之间进行交互。这种交互要求每个服务在充当另一个服务的客户端时标识自己。当需要这个标识时,默认情况下使用ServiceInfo的名称。例如HelloService: ```javascript import com.lightbend.lagom.scaladsl.api._
trait HelloService extends Service { def sayHello: ServiceCall[String, String]
override def descriptor = { import Service._ named(“hello”).withCalls( call(sayHello) ) } }
如果Greeting Service打包了`HelloService`,并且Greeting Service正在调用18n服务(不在代码片段中),那么这些调用将包括标识`hello`,因为这是`HelloService`的名称(参见`named("hello")`)。<br />服务可以在服务网关中发布ACL,以列出服务提供的端点。这些ACL将允许您通过服务网关开发[服务器端服务发现](https://www.yuque.com/liujin1203/lagom/cy8dwm)。```javascriptdef login: ServiceCall[String, String]def descriptor = {import Service._import com.lightbend.lagom.scaladsl.api.transport.Methodnamed("user-authentication").withCalls(restCall(Method.POST, "/api/users/login", login)).withAutoAcl(true)}
在本例中,UsersService的开发人员将withAutoAcl设置为true。这表明Lagom从每个调用的pathPattern中生成Service ACLs 。在本例中,将为/api/users/login创建一个ACL。在部署时,您的工具应该遵守这些规范,并确保正确设置了API 网关。
