A basic example of building a Lagom project to run standalone, without the use of ConductR, Kubernetes, or another managed platform.
Warning: this is outdated and not suitable for use in production. See Caveats below for more information.
This was initially created from the Lagom Java Maven archetype (mvn archetype:generate -DarchetypeGroupId=com.lightbend.lagom -DarchetypeArtifactId=maven-archetype-lagom-java -DarchetypeVersion=1.2.2), with the following changes:
- Removed ConductR-specific configuration
- Added basic start scripts, based on the template provided in Lagom's "Using ConductR with Maven" documentation
- Modified the assembly descriptors to create a simplified layout, with the start script directly in
binand all library dependencies inlib - Added
ConfigurationServiceLocatorto Guice modules in each implementation project, as described in the Lagom documentation - Added static port bindings to each service (
hello-impl: 8001,stream-impl: 8002) - Added a static service location to
hello-implforcas_native(the Cassandra server) - Added a static service location to
stream-implforhello
To test this:
- Open a terminal and clone the repository to your workstation (
git clone https://github.com/TimMoore/lagom-mvn-standalone.git) cd lagom-mvn-standalonemvn packageto create distribution packages- Start a Cassandra server on port 4000. There are a few ways to do this:
-
Get an sbt-based Lagom project (such as
lagom-sbt-standalone) and runsbt lagomCassandraStartin its root directory -
Run Cassandra in Docker:
docker run --rm --name cassandra -p4000:9042 -d cassandra:latest -
Download and run Cassandra standalone as described in the Cassandra Getting Started guide
Note that you'll need to either configure Cassandra to run on port 4000, or change the
cas_nativeservice locator configuration inhello-impl/src/main/resources/application.conf
-
- Open two more terminals in the
lagom-mvn-standalonedirectory - In one terminal:
cd hello-impl/target/unzip hello-impl-1.0-SNAPSHOT-standalone-bundle.zip(or, if you don't have theunzipcommand, use any tool to unzip the file into the same directory)cd hello-impl-1.0-SNAPSHOTbin/hello-impl(the equivalent on Windows is left as an exercise for the reader ๐)
- In the other terminal:
cd stream-impl/target/unzip stream-impl-1.0-SNAPSHOT-standalone-bundle.zipcd stream-impl-1.0-SNAPSHOTbin/stream-impl
This runs each of the services on the configured port, as single-node clusters.
You can press control-C to exit the services.
This configuration is not suitable for production deployments, it's just intended as a starting point. Here are some of the limitations to be aware of.
- Static service locator configuration is difficult to manage in practice, as it requires configuration to be duplicated across all services, and configuring additional services requires a restart.
- The provided
ConfigurationServiceLocatoronly supports a single endpoint per service, which reduces resilience and elasticity. - These start scripts use
-Dlagom.cluster.join-self=on, which restricts each service to run on a single node. Creating a multi-node cluster requires configuring seed nodes as described in the Lagom Cluster documentation. Running more than one instance of this service will cause data corruption. - The provided launcher scripts do not attempt to handle process supervision or health monitoring