Service discovery for MoonBit: the contract backends implement, with one in-memory registry and a conformance suite.
// A service keeps itself registered for as long as this task runs, and leaves on the way out.
group.spawn_bg(() => @moonsd.hold(registry, "greeter", @moonsd.Endpoint::new("10.0.0.1", 12000)))
// A caller follows the service in one task, and reads the list on the request path without waiting.
let view = @moonsd.View::new()
group.spawn_bg(() => view.follow(registry, "greeter"))
view.endpoints()| Trait | Methods | What it promises |
|---|---|---|
| Registrar | register, renew, deregister | An endpoint is known for ttl milliseconds from its last renewal. renew raises Expired once the backend has let it go; deregister is harmless on a lease already gone. |
| Discovery | resolve, watch | resolve answers once, and an unknown service has no endpoints. |
| Watcher | next, close | The first next gives the service as it stands; each later one waits for a change. |
| Package | Contents |
|---|---|
| moonsd | Endpoint, Lease, Update, Refused, the three traits, hold, View |
| moonsd/memory | Registry, the contract in this process: leases when given a clock, revisions, snapshot and restore |
| moonsd/conformance | check, every behaviour the contract promises, run against any backend |
async test "my backend keeps the contract" {
let backend = connect()
@conformance.check(backend, backend)
}pub struct View {
// private fields
}let retry : Intlet ttl : IntInstall
Download zipService discovery for MoonBit: the contract backends implement, with one in-memory registry and a conformance suite.