Prerequisites
Create an Encore app
Follow the Encore quickstart to install the CLI,
then create a new app:
Define your Restate service handlers
Create a Restate service with your handler logic. This is standard Restate code:Each
order-processor/restate.ts
ctx.run() call is journaled by Restate. If the process crashes mid-execution, Restate replays completed
steps and resumes where it left off.Expose the handler via an Encore raw endpoint
Create the Encore service and wire the Restate endpoint handler to a raw endpoint.Since Encore’s raw endpoints use Node.js HTTP types while the Restate SDK provides a Fetch API handler,
we need a small adapter to bridge between the two:Encore now serves the Restate handler at
order-processor/encore.service.ts
order-processor/api.ts
/restate/*. The Restate Server will call this
endpoint to discover and invoke your handlers.Start Restate Server and Encore
In one terminal, start the Restate Server:In another terminal, start your Encore app:
Register your service with Restate
Tell the Restate Server where to find your handlers:You should see the discovered
OrderProcessor service printed out.The
--use-http1.1 flag is needed because Encore’s raw endpoints serve HTTP/1.1.Invoke your handler
Send a request to Restate Server’s ingress (port 8080), which routes it to your Encore-hosted handler:You can also invoke the handler from other Encore API endpoints using the Restate client:
order-processor/orders.ts
Related resources
- Encore documentation
- Encore raw endpoints
encore-restate-gen: a CLI tool that auto-generates Restate service definitions and typed clients from your Encore project- Microservice orchestration use cases
- Sagas guide