我创建了一个名为hello-lagom的示例Lagom项目,一切似乎都运行正常 . 但是,当我尝试通过首先启动服务定位器然后像这样运行项目来运行helloworld-impl项目时:
activator lagomServiceLocatorStart
activator helloworld-impl/run
控制台显示服务定位器正在运行:
[info] Service locator is running at http://localhost:8000
[info] Service gateway is running at http://localhost:9000
[success]
但是,在启动helloworld-impl服务时,Lagom会抛出连接拒绝异常:
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
使用lagomCassandraStart启动嵌入式cassandra无济于事 . 不仅cassandra服务,而且helloworld-impl无法注册到服务定位器 . 我试图telnet端口,但它返回拒绝连接 .
这可能是一个只在尝试独立运行服务时发生的错误,或者可能有我遗漏的东西?
1 回答
问题是您的第一个命令
activator lagomServiceLocatorStart
启动嵌入式服务定位器,但服务定位器也在命令执行后立即停止(因为您的激活器会话已结束) . 我们在激活器会话结束时自动停止嵌入式服务定位器的原因是为了避免资源泄漏 .你有三个解决方案:
1)连接两个任务,以便它们将在同一个激活器会话中执行:
activator lagomServiceLocatorStart helloworld-impl/run
2)首先进入一个激活器会话,然后执行任务(我肯定会推荐这个任务超过1,因为你不会为每次启动激活器支付时间罚款):
3)使用Lagom
runAll
任务而不是手动启动服务定位器和服务,因为它会照顾你(除非你有充分的理由否则):