Skip to content

resonatehq-examples/example-hello-world-java

Hello World — Resonate

Hello World | Resonate Java SDK

The canonical Resonate program: register a function, invoke it durably, read the result.

Heads up — resonate-sdk-java is pre-release (v0.1.x). This example pins io.resonatehq:resonate-sdk-java:0.1.1, the first published release on Maven Central. Expect API changes before v1.0.

What this demonstrates

  • Constructing a Resonate instance against a Resonate dev server with the builder.
  • Registering a Java method as a Resonate workflow via a method reference.
  • Running it durably with r.run(id, ref, args) and reading the typed result with handle.result().

If a worker crashes mid-execution and restarts, the same durable invocation resumes from where it left off — for a function this simple you won't see that behavior, but every example in this org builds on the same primitives.

The code

public static String greet(Context ctx, String name) {
    return "hello, " + name + "!";
}

public static void main(String[] args) {
    Resonate r = Resonate.builder().url("http://localhost:8001").build();
    r.register(HelloWorld::greet);
    try {
        String id = "hello-" + System.nanoTime();
        ResonateHandle<String> handle = r.run(id, HelloWorld::greet, "world");
        System.out.println(handle.result()); // hello, world!
    } finally {
        r.stop();
    }
}

The builder needs a server URL (or the RESONATE_URL environment variable). r.run dispatches the function against a durable promise; handle.result() blocks until it settles.

Prerequisites

  • Java 21+ — the SDK uses virtual threads, a Java 21 feature. Java 8/11/17 will not work.
  • The resonate server CLI. Install with Homebrew on macOS or Linux:
    brew install resonatehq/tap/resonate
    Other install paths: https://docs.resonatehq.io/get-started/quickstart.

You do not need to install the SDK separately — the Gradle wrapper pulls it from Maven Central on the first build.

Setup

git clone https://github.com/resonatehq-examples/example-hello-world-java.git
cd example-hello-world-java

Run it

In one terminal, start the dev server:

resonate dev

In another, run the example:

./gradlew run

What to look for

Expected output:

hello, world!

The function ran on a durable invocation backed by a promise on the server. You can inspect the promise on the dashboard at http://localhost:8001.

File structure

example-hello-world-java/
├── src/main/java/io/resonatehq/examples/helloworld/HelloWorld.java
├── build.gradle.kts     dependencies + Java 21 toolchain + main class
├── settings.gradle.kts  project name
├── gradlew, gradle/      Gradle wrapper
├── assets/              README banner images
├── LICENSE              Apache-2.0
└── README.md

Next steps

Community

License

Apache-2.0

About

The canonical Resonate program in Java: register a function, run it durably, read the result.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages