Dapralpha
Run Motoko actors as Dapr actors, with state in Dapr's state store and Dapr reminders as timers.
Each actor key is a Dapr actor. The Dapr sidecar places it and delivers its messages one at a time; its state is stored in Dapr's actor state store (Redis, after dapr init).
You also need the moxzi SDK and hosts bundles; see Actor platforms.
Prerequisites#
- Go 1.22 or later
- The Dapr CLI, with
dapr initalready run
Create and run a project#
moxzi host new dapr hello
cd hello
ONCE=1 ./run.sh
actor.mo -> actor.wasm + actor.did (245563 bytes, 1 file(s), 50 steps, 0.57s)
Counter/1.inc() -> [1]
Run it a second time. The host is a new process, and the actor's state comes back from the platform's store:
ONCE=1 ./run.sh
actor.mo -> actor.wasm + actor.did (245563 bytes, 1 file(s), 50 steps, 0.70s)
Counter/1.inc() -> [2]
ONCE=1 exits after the demo. Without it, the host keeps running on port 8090 (set PORT to change it), and you can call any key:
curl -X POST localhost:8090/actors/Counter/2/method/inc \
-H 'content-type: application/json' -d '[]'
--example ledger and --example saga work on Dapr too; see Examples.
The project#
| Path | Contents |
|---|---|
actor.mo | The Counter actor type. Each key Counter/ID is a separate actor |
host/ | moxzi's Dapr adapter. It's yours to change |
run.sh | Builds the actor and the host, starts what Dapr needs, and runs the demo |
Change actor.mo and run ./run.sh again. New keys use the new code. Existing keys keep their code until they're upgraded; host/README.md describes upgrades.
How it maps#
| Handled by | |
|---|---|
| One message at a time per key | The Dapr actor turn lock |
| Placement | Dapr placement |
| Actor state | Dapr's actor state store, under the app id moxzi-matrix-hello |
| Durable timers | One Dapr reminder per actor |
Call the host's own port (8090), not the Dapr sidecar's v1.0/actors API: the sidecar only knows the two internal methods the adapter registers. State stays in Dapr's store after the project directory is deleted; a new project with the same name sees it.
Configuration#
| Variable | Default | Effect |
|---|---|---|
PORT | 8090 | The host's HTTP port |
MOXZI_HOST_TOKEN | random | Token for the host's control endpoints (/_moxzi/*) |