Search code examples
lagom

what is purpose of 'named' in Lagom


In the following code, I think that the services are given a name hello. Who uses this information? ServiceLocator?

named("hello")
      .withCalls(
        pathCall("/api/hello/:id", hello _),
        pathCall("/api/hello/:id", useGreeting _),
      )

Solution

  • This name hello is name of the service used by service locator.

    Note, to register with the service locator, you would need to set withAutoAcl:

    named("hello")
          .withCalls(
            pathCall("/api/hello/:id", hello _),
            pathCall("/api/hello/:id", useGreeting _),
          ).withAutoAcl(true)
    

    Without providing withAutoAcl(true), the service would start but will not be registered with the service locator. And hence you would need to make a call directly to it (on its port), rather than via the service gateway (which by default is 9000).

    By marking it true, service gateway gets configured automatically, to forward the hello related service calls to your implementaion.