The canonical Resonate program: register a function, invoke it durably, read the result.
Heads up —
resonate-sdk-javais pre-release (v0.1.x). This example pinsio.resonatehq:resonate-sdk-java:0.1.1, the first published release on Maven Central. Expect API changes beforev1.0.
- Constructing a
Resonateinstance 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 withhandle.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.
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.
- Java 21+ — the SDK uses virtual threads, a Java 21 feature. Java 8/11/17 will not work.
- The
resonateserver CLI. Install with Homebrew on macOS or Linux:Other install paths: https://docs.resonatehq.io/get-started/quickstart.brew install resonatehq/tap/resonate
You do not need to install the SDK separately — the Gradle wrapper pulls it from Maven Central on the first build.
git clone https://github.com/resonatehq-examples/example-hello-world-java.git
cd example-hello-world-javaIn one terminal, start the dev server:
resonate devIn another, run the example:
./gradlew runExpected 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.
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
- Get started — install paths + first-program walkthrough.
- Durable execution concepts — what makes invocations durable + how the runtime resumes them.
- Java SDK docs — the full Java API surface.
example-recursive-factorial-java— see what a recursive workflow + worker/client split looks like in Java.
- Discord: https://resonatehq.io/discord
- X: https://x.com/resonatehqio
- LinkedIn: https://www.linkedin.com/company/resonatehqio
- YouTube: https://www.youtube.com/@resonatehqio
- Journal: https://journal.resonatehq.io