Implementing services in Java

The Akka Serverless Java SDK offers an idiomatic, annotation-based Java support library for writing stateful services. Before you attempt to write your first service in Java, we recommend that you read about best design practices and understand the development process.

Prerequisites

The following are required to start writing services in Java:

Java version

Akka Serverless requires at least Java 8, though we recommend using Java 11, which has better support for running in containers. While it is possible to build a GraalVM native image for Java service implementations, at this stage the SDK offers no specific assistance or configuration to aid in doing that.

Build tool

Akka Serverless does not require any particular build tool, you can select your own.

protoc

Since Akka Serverless is based on gRPC, you need a protoc compiler to compile gRPC protobuf descriptors. While this can be done by downloading, installing and running protoc manually, most popular build tools have a protoc plugin which will automatically compile protobuf descriptors during your build.

Docker

Akka Serverless runs in Kubernetes using Docker. You will need Docker to build container images that you can deploy to Kubernetes. Most popular build tools have plugins that assist in building Docker images.

Java support library

See the instructions in Install the SDK library.

Install the SDK library

As mentioned, you can use the build tool of your choice. The following examples show how to install the Java library for Gradle, Maven, and sbt.

Gradle

In your build.gradle file, add the following:

compile group: 'io.cloudstate', name: 'cloudstate-java-support', version: '0.5.2'
Maven

In your .pom file, add the following:

<dependency>
  <groupId>io.cloudstate</groupId>
  <artifactId>cloudstate-java-support</artifactId>
  <version>0.5.2</version>
</dependency>
sbt

In your dependencies file, add the following:

libraryDependencies += "io.cloudstate" % "cloudstate-java-support" % "0.5.2"

What’s next