Crate wasmcloud_nats_kvcache[][src]

NATS Key Value Cache

A simple distributed cache that exposes a wasmcloud:keyvalue capability provider contract. All state changes are replicated over NATS in the form of events that are then reconstituted by other nodes to build state. Replays can be requested with high watermark values in order to reload/synchronize state for joining or lagging nodes.

Protocol

Subject PatternUsage
{root}.eventsSubscribed to by all running providers. Each event received on this subject is processed by an aggregate to update local state
{root}.replay.reqQueue subscribed by all running providers. In response to a request, a provider will stream responses to the requester

When a requester sends a request, they will send it with a high watermark (hwm). This indicates the offset from zero of the latest message the requester has received. In response, the provider that handled the request will first send a ReplayRequestAck back on the reply subject, indicating the local (handling provider) hwm and the hwm sent by the requester. Subtracting these two will tell the requester how many more messages to receive on that reply subject, one for each event the requester has not received.

As an example, assume the requester has a high watermark of 12, and the handling provider has a high watermark of 15. The requester will first receive a ReplayRequestAck indicating how many subsequent events to expect in reply, followed then by n CacheEvents.

Structs

NatsReplicatedKVProvider

An instance of a wasmcloud:keyvalue capability provider that replicates changes to the cache by means of pub/sub over a NATS message broker

ReplayRequest
ReplayRequestAck

Enums

CacheEvent

Indicates an event that has occurred on a distributed cache. In all of the variants of this event, the first parameter is always the key

Functions

__capability_provider_create