Generating a development project

Akka Serverless provides code generation tools as a way to quickly get started writing a service using either Java or JavaScript:

  • For Java development—​a maven archetype that creates a POM-based project and a service containing an Event Sourced Entity.

  • For JavaScript development—​an npm module, that creates the code base for a service containing an Event Sourced Entity.

These tools generate a project structure, unit tests, and a helpful README.md that explains what was created and how to work with the newly created service. Modify the .proto files as needed for your service, and the tools will generate code stubs for the elements you changed or added.

The term "project" used in connection with code generation is a development project that contains your service implementation. This differs from an Akka Serverless project, which is a unit of deployment that contains one or more packaged services.

Generate a Java service with Maven

Prerequisites:

  • JDK 8 or higher

  • Apache Maven

  • curl

  • Docker 19.03 or higher (to run locally)

  • Linux, MacOS or Windows 10+

Issue the commands below from a command or terminal window:

Linux or macOS
curl \
"https://bintray.com/repo/downloadMavenRepoSettingsFile/downloadSettings?repoPath=%2Flightbend%2Fakkaserverless" > \
 /tmp/maven-archetype-akkasls-settings.xml && \
mvn \
--settings /tmp/maven-archetype-akkasls-settings.xml \
archetype:generate \
-DarchetypeGroupId=com.lightbend \
-DarchetypeArtifactId=maven-archetype-akkasls \
-DarchetypeVersion=0.15.0
Windows 10+
curl ^
"https://bintray.com/repo/downloadMavenRepoSettingsFile/downloadSettings?repoPath=%2Flightbend%2Fakkaserverless" ^
 > %Temp%\maven-archetype-akkasls-settings.xml && ^
mvn ^
--settings %Temp%\maven-archetype-akkasls-settings.xml ^
archetype:generate ^
-DarchetypeGroupId=com.lightbend ^
-DarchetypeArtifactId=maven-archetype-akkasls ^
-DarchetypeVersion=0.15.0
Other Operating Systems

To use on other operating systems:

  1. Download the maven-archetype-akkasls-settings.xml from https://bintray.com/repo/downloadMavenRepoSettingsFile/downloadSettings?repoPath=%2Flightbend%2Fakkaserverless to a temporary location.

  2. Run the commands shown for macOS or Windows, but in the mvn command, use the --settings option to reference the location where you downloaded maven-archetype-akkasls-settings.xml.

This will generate a proper POM-based project structure, initial code, unit tests and a helpful README.md that explains what was created and how to work with your newly created service.

Run mvn compile to generate and compile the sources.

As you develop your own logic, you can change the .proto file definitions and build again. The build will generate classes and tests for your additions if they do not exist, but will not overwrite existing classes or tests.

Generate a JavaScript service with npm or Yarn

Prerequisites:

  • npm or yarn

  • Docker 19.03 (to run locally)

To create the initial codebase for a new Event Sourced Entity with the name my-entity:

npm
npx @lightbend/create-akkasls-entity my-entity
cd my-entity
npm install
npm run build
yarn
yarn create @lightbend/akkasls-entity my-entity
cd my-entity
yarn
yarn build

This will generate a proper npm-based project structure, initial code, unit tests and a helpful README.md that explains what was created and how to work with the newly created service.

As you develop your own logic, you can change the .proto file definitions and build again. The build will generate classes and tests for your additions if they do not exist, but will not overwrite existing classes or tests.