GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com β€” GitHub - restatedev/sdk-java: Restate SDK for JVM Languages

BranchesTags
Open more actions menu

Latest commit

 

History

592 Commits
592 Commits

Folders and files

NameName
Last commit message
Last commit date
.claude/skills
.claude/skills
 
 
.github
.github
 
 
.junie
.junie
 
 
.tools
.tools
 
 
admin-client
admin-client
 
 
buildSrc
buildSrc
 
 
bytebuddy-proxy-support
bytebuddy-proxy-support
 
 
client-kotlin
client-kotlin
 
 
client
client
 
 
common-kotlin
common-kotlin
 
 
common
common
 
 
config
config
 
 
development
development
 
 
examples
examples
 
 
gradle
gradle
 
 
integration-client
integration-client
 
 
sdk-aggregated-javadocs
sdk-aggregated-javadocs
 
 
sdk-api-gen-common
sdk-api-gen-common
 
 
sdk-api-gen
sdk-api-gen
 
 
sdk-api-kotlin-gen
sdk-api-kotlin-gen
 
 
sdk-api-kotlin
sdk-api-kotlin
 
 
sdk-api
sdk-api
 
 
sdk-common
sdk-common
 
 
sdk-core
sdk-core
 
 
sdk-fake-api
sdk-fake-api
 
 
sdk-http-vertx
sdk-http-vertx
 
 
sdk-interceptor-micrometer
sdk-interceptor-micrometer
 
 
sdk-interceptor-opentelemetry
sdk-interceptor-opentelemetry
 
 
sdk-java-http
sdk-java-http
 
 
sdk-java-lambda
sdk-java-lambda
 
 
sdk-kotlin-http
sdk-kotlin-http
 
 
sdk-kotlin-lambda
sdk-kotlin-lambda
 
 
sdk-lambda
sdk-lambda
 
 
sdk-request-identity
sdk-request-identity
 
 
sdk-serde-jackson
sdk-serde-jackson
 
 
sdk-serde-kotlinx
sdk-serde-kotlinx
 
 
sdk-spring-boot-kotlin-starter
sdk-spring-boot-kotlin-starter
 
 
sdk-spring-boot-starter
sdk-spring-boot-starter
 
 
sdk-spring-boot
sdk-spring-boot
 
 
sdk-testing
sdk-testing
 
 
test-services
test-services
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.ignore
.ignore
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
MIGRATION.md
MIGRATION.md
 
 
README.md
README.md
 
 
build.gradle.kts
build.gradle.kts
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle.kts
settings.gradle.kts
 
 

Repository files navigation

Documentation Java Kotlindocs Examples Discord Twitter

Restate JVM SDK

Restate is a system for easily building resilient applications using distributed durable async/await. This repository contains the Restate SDK for writing services using JVM languages.

This SDK features:

  • Implement Restate services using either:
    • Java
    • Kotlin coroutines
  • Deploy Restate services as:
    • Non-blocking HTTP servers
    • On AWS Lambda

Community

  • πŸ€—οΈ Join our online community for help, sharing feedback and talking to the community.
  • πŸ“– Check out our documentation to get quickly started!
  • πŸ“£ Follow us on Twitter for staying up to date.
  • πŸ™‹ Create a GitHub issue for requesting a new feature or reporting a problem.
  • 🏠 Visit our GitHub org for exploring other repositories.

Using the SDK

Prerequisites

  • JDK >= 17 (JDK >= 23 recommended β€” required for the latest Restate features; see Native access on JDK 23+)

tl;dr Use project templates

To get started, follow the Java quickstart or the Kotlin quickstart.

Setup a project (Java)

Scaffold a project using the build tool of your choice. For example, with Gradle (Kotlin script):

gradle init --type java-application

Depending on whether you want to deploy using HTTP or Lambda, add the appropriate dependency:

// For HTTP services
implementation("dev.restate:sdk-java-http:2.8.0")
// For Lambda services
// implementation("dev.restate:sdk-java-lambda:2.8.0")

Setup a project (Kotlin)

Scaffold a project using the build tool of your choice. For example, with Gradle (Kotlin script):

gradle init --type kotlin-application

Depending on whether you want to deploy using HTTP or Lambda, add the appropriate dependency:

// For HTTP services
implementation("dev.restate:sdk-kotlin-http:2.8.0")
// For Lambda services
// implementation("dev.restate:sdk-kotlin-lambda:2.8.0")

Implement your first Restate component (Java)

Implement your first virtual object in a new class, for example:

import dev.restate.sdk.Restate;
import dev.restate.sdk.annotation.Handler;
import dev.restate.sdk.annotation.VirtualObject;
import dev.restate.sdk.common.StateKey;

@VirtualObject
public class Greeter {

  private static final StateKey<Long> COUNT = StateKey.of("total", Long.class);

  @Handler
  public String greet(String name) {
    var state = Restate.state();
    long count = state.get(COUNT).orElse(0L);
    state.set(COUNT, count + 1);

    return String.format("Hello %s for the %d time!", name, count);
  }
}

By default, Jackson Databind will be used for serialization/deserialization. You can override this configuration by customizing the SerdeFactory, check out the javadocs for more details.

Implement your first Restate component (Kotlin)

Implement your first virtual object in a new class, for example:

import dev.restate.sdk.annotation.*
import dev.restate.sdk.kotlin.*

@VirtualObject
class Greeter {
  companion object {
    private val COUNT = stateKey("total")
  }

  @Handler
  suspend fun greet(name: String): String {
    val state = state()
    val count = state.get(COUNT) ?: 0L
    state.set(COUNT, count + 1)
    return "Hello $name for the $count time!"
  }
}

By default kotlinx.serialization will be used for serialization/deserialization. You can override this configuration by customizing the SerdeFactory, check out the javadocs for more details.

Deploy the service (HTTP Server)

To deploy the Restate service as HTTP server, add the following code to the main. For example in Java:

public static void main(String[] args) {
  RestateHttpServer.listen(
    Endpoint.bind(new Greeter())
  );
}

In Kotlin:

fun main() {
  RestateHttpServer.listen(
    endpoint {
      bind(Greeter())
    }
  )
}

Execute the project. For example, using Gradle:

gradle run

Deploy the service (AWS Lambda)

To deploy the Restate service as Lambda, configure the build tool to generate Fat-JARs, which are required by AWS Lambda to correctly load the JAR. For example, using Gradle:

plugins {
  // ...
  // The shadow plugin generates a shadow JAR ready for AWS Lambda
  id("com.github.johnrengelman.shadow").version("7.1.2")
  // ...
}

Now create the Lambda handler invoking the service. For example, in Java:

public class MyLambdaHandler extends BaseRestateLambdaHandler {
  @Override
  public void register(Endpoint.Builder builder) {
    builder.bind(new Greeter());
  }
}

In Kotlin:

class MyLambdaHandler : BaseRestateLambdaHandler {
  override fun register(builder: Endpoint.Builder) {
    builder.bind(Greeter())
  }
}

Now build the Fat-JAR. For example, using Gradle:

gradle shadowJar

You can now upload the generated Jar in AWS Lambda, and configure MyLambdaHandler as the Lambda class in the AWS UI.

Additional setup

Native access on JDK 23+

On JDK 23 and later the SDK runs its state machine through the native Restate shared-core library, via the Java Foreign Function & Memory API. This is required to support the latest Restate features. On older JDKs the SDK falls back to a pure-Java state machine, which is deprecated and will be removed in a future release β€” so running on JDK 23+ is strongly recommended.

Using the native library requires native access to be enabled for the application. If it isn't, the SDK still works but the JVM prints a one-time warning at startup (e.g. "A restricted method ... has been called ... Use --enable-native-access=ALL-UNNAMED to avoid a warning"), and a future JDK will turn that warning into an error β€” so it's worth enabling.

The cleanest way to enable it without a command-line flag is to add this attribute to the manifest of your application's runnable (fat) jar β€” for example with the Gradle Shadow plugin:

tasks.shadowJar {
  manifest { attributes("Enable-Native-Access" to "ALL-UNNAMED") }
}

(ALL-UNNAMED is the only accepted value.) For launchers that don't run the app via java -jar (custom entrypoints, containers, java -cp), pass --enable-native-access=ALL-UNNAMED directly or via the JDK_JAVA_OPTIONS environment variable.

If you'd rather grant native access selectively (the integrity-friendly approach recommended by the JDK) instead of to the whole class path, put the SDK jars on the module path and enable access only for the module that performs it β€” sdk-core publishes the stable automatic-module name dev.restate.sdk.core:

java --module-path libs --enable-native-access=dev.restate.sdk.core ...

(sdk-core works unchanged on the class path too; the module name is simply ignored there.)

To force the pure-Java state machine instead (no native access needed), set -Ddev.restate.sdk.statemachine.disableNewCore=true. On JDK < 23 the pure-Java state machine is always used.

Logging

The SDK uses log4j2 as logging facade, to configure it add the file resources/log4j2.properties:

# Set to debug or trace if log4j initialization is failing
status = warn

# Console appender configuration
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %notEmpty{[%X{restateInvocationTarget}]}%notEmpty{[%X{restateInvocationId}]} %c - %m%n

# Filter out logging during replay
appender.console.filter.replay.type = ContextMapFilter
appender.console.filter.replay.onMatch = DENY
appender.console.filter.replay.onMismatch = NEUTRAL
appender.console.filter.replay.0.type = KeyValuePair
appender.console.filter.replay.0.key = restateInvocationStatus
appender.console.filter.replay.0.value = REPLAYING

# Restate logs to debug level
logger.app.name = dev.restate
logger.app.level = info
logger.app.additivity = false
logger.app.appenderRef.console.ref = consoleLogger

# Root logger
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = consoleLogger

The SDK injects the following additional metadata to the logging context that can be used for filtering as well:

  • restateInvocationTarget: invocation target, e.g. counter.Counter/Add.
  • restateInvocationId: Invocation identifier, to be used in Restate observability tools. See https://docs.restate.dev/operate/invocation#invocation-identifier.
  • restateInvocationStatus: Invocation status, can be WAITING_START, REPLAYING, PROCESSING, CLOSED.

The dependencies sdk-java-http, sdk-java-lambda, sdk-kotlin-http and sdk-kotlin-lambda bring in log4j-core by default, but you can easily exclude/override that if you need to.

When assembling fat-jars, make sure to enable merging META-INF/services files. For more info, see apache/logging-log4j2#2099.

Versions

This library follows Semantic Versioning.

The compatibility with Restate is described in the following table:

Restate Server\sdk-java 2.2 - 2.3 2.4 - 2.8 2.9
1.5 - 1.6 βœ… βœ… βœ…
1.7 βœ… βœ… βœ…

Some features require a minimum version of both Restate and the SDK:

  • Scope and limit key: requires Restate >= 1.7 with sdk-java >= 2.9

Contributing

We’re excited if you join the Restate community and start contributing! Whether it is feature requests, bug reports, ideas & feedback or PRs, we appreciate any and all contributions. We know that your time is precious and, therefore, deeply value any effort to contribute!

Building the SDK locally

Prerequisites:

  • JDK >= 25
  • Docker or Podman

To build the SDK:

./gradlew build

To run the tests:

./gradlew check

To publish local snapshots of the project:

./gradlew -DskipSigning publishToMavenLocal

About

Restate SDK for JVM Languages

restate.dev

Topics

distributed-systemsjavajvmkotlinkotlin-coroutines

Resources

Readme
MIT license
Activity
Custom properties

Stars

60 stars

Watchers

2 watching

Forks

16 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 β€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Γ—600. No cookies required.