How to run some Lagom services instead of one or all

How to run some Lagom services instead of one or all

Currently, Lagom’s built-in tooling allows for running a single service via run or all of them via runAll. In some cases you may find it more convenient to run a specific subset of services. The simplest solution for this is to create a commandAlias for starting the appropriate services (including built-in ones):

  ";lagomServiceLocatorStart;lagomCassandraStart;all serviceA/run serviceB/run" 

If you are running a mixed Play/Lagom project, then this could result in port collisions. This can be worked around by binding to another port.

If, however, you have one or more Lagom services which enabled both the PlayScala and the LagomScala plugins, then a command collision on run may occur. This is because both define run, so using serviceA/run is ambiguous such that one implementation wins over the other. And the implementations differ quite a bit between the Play implementation and the Lagom one since in Lagom services must register and also expose call paths on the service gateway (plus handle port assignment as already mentioned). There’s no way to enforce one implementation over the other but you can provide your own:

lazy val `hello-world-impl` = (project in file("hello-world-impl"))
  .enablePlugins(LagomScala, PlayScala)
  .settings( in Compile := {
      val service = lagomRun.value
//... more settings

// more projects

  ";lagomServiceLocatorStart;lagomCassandraStart;lagomKafkaStart;all hello-world-impl/run hello-world-stream-impl/run "

The sbt code above overwrites run ensuring the invocation of hello-world-impl/run causes the lagomRun implementation to execute.

    • Related Articles

    • Should Kafka act as the source of truth in Lagom?

      > We are using Lagom with event sourcing and CQRS. Would you say that keeping the source of truth on the Kafka side is an option? Pragmatism always wins the day, and with that being said this idea has plenty of merit. The only concern we have with ...
    • Does Lagom support multitenancy?

      Our suggestion is to not go down this path. Multi-tenancy was very popular back in the time when people used to deploy one single application on a huge application server. In the era of cloud computing, it's much easier to have different deployments, ...
    • Can I customize error handling in Lagom?

      Yes, the best way to customize error handling in Lagom is to use a custom ExceptionSerializer.  This Knoldus blog post explains it well: That example, however, is more focused on how ...
    • How to implement versioning in Lagom microservices?

      Lagom doesn't provide any solution, plugin or feature that enables API versioning. However you can use the following to decide and pick what works best for you: When versioning you must keep in mind both the service endpoints and payloads and the ...
    • Can Lagom errors be handled using Play error handling?

      No, the Play error handler is not invoked from Lagom, because the Lagom exception serializer intercepts it first. Any exception thrown by application code will be wrapped in a transport exception, serialized to json and a response is built from it. ...