Skip to content

Commit d7cf9e7

Browse files
committed
docs: Update README with state store API
1 parent e67a4e5 commit d7cf9e7

1 file changed

Lines changed: 97 additions & 1 deletion

File tree

README.md

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Protobuf messages, to allow your events to evolve over time.
2323
- 💾 State storage
2424
- 🗄 Supports multiple key-value stores for storing state
2525
- 📄 Values in Protobuf format, for strong typing and schema evolution
26-
- 🔄 Optimistic concurrency control using compare and swap based on revisions
26+
- ↔️ Optimistic concurrency control using compare and swap
2727
- 🔍 Observability via OpenTelemetry tracing and metrics
2828

2929
### Planned features
@@ -152,6 +152,102 @@ The server will respond with confirmations to `Ack`, `Reject` and `Ping`
152152
messages. These confirmations contain information about if the message was
153153
processed successfully, or if it failed.
154154

155+
## Storing state
156+
157+
Windshift provides the ability to define key-value stores for storing state.
158+
159+
The `windshift.state.v1alpha1.EventsService` is the main gRPC service for
160+
working with state.
161+
162+
### Defining stores
163+
164+
Stores can be created with the `EnsureStore` method. This method will create
165+
a store if it does not exist yet.
166+
167+
Example in pseudo-code:
168+
169+
```typescript
170+
service.EnsureStore(windshift.state.v1alpha1.EnsureStoreRequest{
171+
name: "orders",
172+
})
173+
```
174+
175+
### Setting values
176+
177+
Values can be set using the `Set` method, either normally, only if the key does
178+
not exist yet, or only if the key already exists in a specific revision.
179+
180+
Example in pseudo-code:
181+
182+
```typescript
183+
result = service.Set(windshift.state.v1alpha1.SetRequest{
184+
store: "orders",
185+
key: "order-123",
186+
value: protobufMessage,
187+
})
188+
189+
revision = result.revision
190+
```
191+
192+
Setting only if the key does not exist yet:
193+
194+
```typescript
195+
result = service.Set(windshift.state.v1alpha1.SetRequest{
196+
store: "orders",
197+
key: "order-123",
198+
value: protobufMessage,
199+
create_only: true,
200+
})
201+
```
202+
203+
Updating a value with a specific revision:
204+
205+
```typescript
206+
result = service.Set(windshift.state.v1alpha1.SetRequest{
207+
store: "orders",
208+
key: "order-123",
209+
value: protobufMessage,
210+
last_revision: revision,
211+
})
212+
```
213+
214+
### Getting values
215+
216+
Values can be retrieved using the `Get` method.
217+
218+
Example in pseudo-code:
219+
220+
```typescript
221+
result = service.Get(windshift.state.v1alpha1.GetRequest{
222+
store: "orders",
223+
key: "order-123",
224+
})
225+
```
226+
227+
### Deleting values
228+
229+
Values can be deleted using the `Delete` method, either normally or if the
230+
specified revision matches the current revision.
231+
232+
Example in pseudo-code:
233+
234+
```typescript
235+
service.Delete(windshift.state.v1alpha1.DeleteRequest{
236+
store: "orders",
237+
key: "order-123",
238+
})
239+
```
240+
241+
Delete only if the revision matches:
242+
243+
```typescript
244+
service.Delete(windshift.state.v1alpha1.DeleteRequest{
245+
store: "orders",
246+
key: "order-123",
247+
last_revision: revision,
248+
})
249+
```
250+
155251
## Working with the code
156252

157253
This project depends on [pre-commit](https://pre-commit.com/) to automate

0 commit comments

Comments
 (0)