Prerequisites
- JDK >= 17
Getting started
Use the following dependencies:Basic Services
Basic Services group related handlers and expose them as callable endpoints:- Define a service using the
@Serviceand@Handlerannotations - Each handler can be called at
<RESTATE_INGRESS>/MyService/myHandler. To override the service name (default is simple class name), use the annotation@Name. - Handlers take the
Context(JavaDocs/KotlinDocs) as the first argument. - The input parameter (at most one) and return type are optional and can be of any type. See serialization for more details.
- Create an endpoint to expose the service over HTTP (port
9080by default).
Virtual Objects
Virtual Objects are services that are stateful and key-addressable — each object instance has a unique ID and persistent state.- Use the
@VirtualObjectannotation. - The first argument of the handler must be the
ObjectContextparameter (JavaDocs/KotlinDocs). - Each instance is identified by a key (accessible via
ctx.key()). - Virtual Objects can have exclusive and shared handlers.
- Exclusive handlers receive an
ObjectContext, allowing read/write access to object state. - Shared handlers use the
@Sharedannotation and theSharedObjectContext(JavaDocs/KotlinDocs).
Workflows
Workflows are long-lived processes with a defined lifecycle. They run once per key and are ideal for orchestrating multi-step operations, which require external interaction via signals and queries.- Create the workflow by using the
@Workflowannotation. - Every workflow must include a
runhandler:- This is the main orchestration entry point
- It runs exactly once per workflow execution and uses the
WorkflowContext(JavaDocs/KotlinDocs) - Resubmission of the same workflow will fail with “Previously accepted”. The invocation ID can be found in the request header
x-restate-id. - Use
ctx.key()to access the workflow’s unique ID
- Additional handlers must use the
SharedWorkflowContext(JavaDocs/KotlinDocs) and can signal or query the workflow. They can run concurrently with therunhandler and until the retention time expires.