Search code examples
javalagom

Lagom lagomServiceLocatorStart not working - Connection refused


I have created a sample Lagom project called hello-lagom and everything seems to work fine. However, when I try to run the the helloworld-impl project by first starting the service locator and then running the project like so:

activator lagomServiceLocatorStart
activator helloworld-impl/run

The console shows that the service locator is running:

[info] Service locator is running at http://localhost:8000
[info] Service gateway is running at http://localhost:9000
[success]

However Lagom throws a connection refused exception when starting the helloworld-impl service:

c.l.l.j.p.InitServiceLocatorHolder - Cassandra server name=[cas_native]
couldn't be registered to the service locator.
java.net.ConnectException: Connection refused: localhost/127.0.0.1:8000

Starting embedded cassandra with lagomCassandraStart does not help. Not only cassandra service but helloworld-impl fails to register to the service locator. I tried to telnet the port but it returns connection refused.

Could this be a bug only happening when trying to run a service standalone or there could be something I am missing?


Solution

  • The issue is that your first command, activator lagomServiceLocatorStart, starts the embedded service locator, but the service locator is also stopped right after the command is executed (because your activator session has ended). The reason we automatically stop the embedded service locator at the end of the activator session is to avoid leaking resources.

    You have three solutions here:

    1) Concatenate the two tasks, so that they will be executed within the same activator session: activator lagomServiceLocatorStart helloworld-impl/run

    2) First enter an activator session, and then executes the tasks (I'd definitely reccomend this over 1, as you don't pay a time penalty for starting activator each time):

    $ activator
    > lagomServiceLocatorStart
    > helloworld-impl/run
    

    3) Use the Lagom runAll task instead of manually starting the service locator and your services, as it takes care of that for you (use this unless you have good reasons for doing otherwise):

    $ activator
    > runAll