@cratis/pi 7.51.5 → 7.52.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package/corpus/harnesses/copilot/instructions/documentation.instructions.md +1 -0
- package/package/corpus/harnesses/copilot/instructions/glossary.instructions.md +2 -1
- package/package/corpus/harnesses/copilot/instructions/profiles.instructions.md +15 -0
- package/package/corpus/product-sync.json +26 -20
- package/package/corpus/rules/documentation.md +1 -0
- package/package/corpus/rules/glossary.md +2 -1
- package/package/corpus/rules/profiles.md +15 -0
- package/package/corpus/skills/cratis-application-slice-specifications/references/query-and-decision-scenarios.md +14 -3
- package/package/corpus/skills/cratis-arc-command/SKILL.md +4 -0
- package/package/corpus/skills/cratis-arc-command/references/decisions-and-routing.md +22 -3
- package/package/corpus/skills/cratis-arc-command/references/fresh-identifiers.md +52 -0
- package/package/corpus/skills/cratis-arc-command/references/generated-values.md +7 -7
- package/package/corpus/skills/cratis-arc-command/references/handler-shapes.md +9 -0
- package/package/corpus/skills/cratis-arc-command/references/proxy-generation.md +5 -0
- package/package/corpus/skills/cratis-arc-command/references/read-model-injection.md +11 -0
- package/package/corpus/skills/cratis-arc-command-execution/SKILL.md +12 -1
- package/package/corpus/skills/cratis-arc-command-execution/references/command-refusals.md +65 -0
- package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +5 -0
- package/package/corpus/skills/cratis-arc-hosting/SKILL.md +1 -0
- package/package/corpus/skills/cratis-arc-observable-query-http/SKILL.md +6 -0
- package/package/corpus/skills/cratis-chronicle-client-dotnet/references/additional-surfaces.md +18 -0
- package/package/corpus/skills/cratis-chronicle-client-dotnet/references/discovery.md +33 -1
- package/package/corpus/skills/cratis-chronicle-client-dotnet/references/lifecycle.md +7 -1
- package/package/corpus/skills/cratis-chronicle-compliance/SKILL.md +5 -0
- package/package/corpus/skills/cratis-chronicle-decision-reads/SKILL.md +17 -0
- package/package/corpus/skills/cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md +3 -3
- package/package/corpus/skills/cratis-chronicle-event-constraints/SKILL.md +4 -0
- package/package/corpus/skills/cratis-chronicle-event-constraints/references/storage-uniqueness.md +28 -0
- package/package/corpus/skills/cratis-chronicle-event-modeling/SKILL.md +5 -3
- package/package/corpus/skills/cratis-chronicle-event-specifications/SKILL.md +7 -0
- package/package/corpus/skills/cratis-chronicle-event-type-migration/SKILL.md +18 -0
- package/package/corpus/skills/cratis-chronicle-event-type-migration/references/explicit-migrations.md +46 -0
- package/package/corpus/skills/cratis-chronicle-hosting/SKILL.md +8 -0
- package/package/corpus/skills/cratis-chronicle-hosting/references/operations.md +42 -0
- package/package/corpus/skills/cratis-chronicle-multi-tenancy/SKILL.md +1 -0
- package/package/corpus/skills/cratis-chronicle-projection/references/model-bound-attributes.md +6 -0
- package/package/corpus/skills/cratis-chronicle-projection/references/variants.md +7 -0
- package/package/corpus/skills/cratis-chronicle-reactor/SKILL.md +13 -7
- package/package/corpus/skills/cratis-chronicle-reactor/references/cross-service-events.md +9 -2
- package/package/corpus/skills/cratis-chronicle-reactor/references/return-event-metadata.md +7 -0
- package/package/corpus/skills/cratis-chronicle-reactor/references/slice-delivery-checklist.md +3 -3
- package/package/corpus/skills/cratis-chronicle-reactor/references/specifications.md +11 -5
- package/package/corpus/skills/cratis-chronicle-read-model/SKILL.md +8 -4
- package/package/corpus/skills/cratis-chronicle-read-model/references/collection-observation.md +49 -0
- package/package/corpus/skills/cratis-chronicle-read-model/references/queries.md +13 -2
- package/package/corpus/skills/cratis-chronicle-read-model-specifications/SKILL.md +8 -0
- package/package/corpus/skills/cratis-chronicle-web-workbench/SKILL.md +15 -0
- package/package/corpus/skills/cratis-multi-service-architecture/SKILL.md +204 -0
- package/package/corpus/skills/cratis-multi-service-architecture/references/publish-and-consume.md +229 -0
- package/package/corpus/skills/cratis-multi-service-local-orchestration/SKILL.md +172 -0
- package/package/corpus/skills/cratis-multi-service-local-orchestration/references/docker-compose.md +144 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/SKILL.md +4 -0
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/automation-patterns.md +1 -1
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/effects-and-idempotency.md +24 -5
- package/package/corpus/skills/cratis-screenplay-automations-and-translations/references/public-events-and-direction.md +1 -1
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/SKILL.md +11 -6
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/invocation-identity.md +3 -1
- package/package/corpus/skills/cratis-screenplay-captures-and-reactions/references/refusals-and-redelivery.md +97 -26
- package/package/corpus/skills/cratis-screenplay-command-surface/references/compliance.md +2 -1
- package/package/corpus/skills/cratis-screenplay-command-surface/references/generated-values-and-responses.md +45 -10
- package/package/corpus/skills/cratis-screenplay-command-surface/verification.json +3 -1
- package/package/corpus/skills/cratis-screenplay-event-modeling/SKILL.md +1 -0
- package/package/corpus/skills/cratis-screenplay-event-modeling/references/parsed-not-runnable.md +10 -6
- package/package/corpus/skills/cratis-screenplay-model-authoring/SKILL.md +5 -1
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/language-reference.md +7 -3
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-loop.md +28 -12
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/mcp-tools.md +29 -6
- package/package/corpus/skills/cratis-screenplay-model-authoring/references/screen-authoring-workflow.md +15 -3
- package/package/corpus/skills/cratis-screenplay-model-authoring/verification.json +4 -1
- package/package/corpus/skills/cratis-screenplay-model-review/references/checklist.md +1 -1
- package/package/corpus/skills/cratis-screenplay-read-surface/SKILL.md +4 -0
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/SKILL.md +5 -1
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/delivery-protocol.md +1 -1
- package/package/corpus/skills/cratis-screenplay-render-and-gap-fill/references/renderability-gate.md +1 -1
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/SKILL.md +9 -1
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/scenario-catalogue.md +12 -10
- package/package/corpus/skills/cratis-screenplay-scenario-coverage/references/spec-forms-by-mode.md +11 -6
- package/package/corpus/skills/cratis-screenplay-slice-design/references/field-lineage.md +1 -1
- package/package/corpus/skills/cratis-screenplay-specifications/SKILL.md +18 -10
- package/package/corpus/skills/cratis-screenplay-specifications/references/examples-and-routes.md +14 -13
- package/package/corpus/skills/cratis-screenplay-specifications/references/query-rejections.md +44 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/SKILL.md +2 -1
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/multi-service-models.md +188 -0
- package/package/corpus/skills/cratis-screenplay-streams-and-consistency/verification.json +1 -1
- package/package/corpus/skills/cratis-screenplay-toolchain/SKILL.md +6 -1
- package/package/corpus/skills/cratis-screenplay-toolchain/references/diagnostics.md +12 -4
- package/package/corpus/skills/cratis-screenplay-toolchain/references/executable-subset.md +10 -6
- package/package/corpus/skills/cratis-screenplay-toolchain/references/renderable-subset.md +28 -9
- package/package/corpus/skills/cratis-screenplay-toolchain/references/screenplay-contract.json +4658 -230
- package/package/corpus/skills/cratis-screenplay-toolchain/references/screenplay-contract.version +1 -1
- package/package/corpus/skills/cratis-screenplay-toolchain/references/traps.md +1 -1
- package/package/corpus/skills/cratis-specifications-csharp/SKILL.md +5 -0
- package/package/corpus/skills/cratis-specifications-csharp/references/application-scenarios.md +1 -1
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/SKILL.md +1 -1
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/admission.md +63 -15
- package/package/corpus/skills/cratis-stage-rendering-and-sandbox/references/sandbox-and-specrunner.md +2 -2
- package/package/corpus/skills/cratis-technical-examples/SKILL.md +22 -0
- package/package/profile-catalog.json +3 -1
- package/package.json +1 -1
package/package/corpus/skills/cratis-chronicle-read-model/references/collection-observation.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
2
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
3
|
+
|
|
4
|
+
# Observe a Chronicle collection
|
|
5
|
+
|
|
6
|
+
Requires Chronicle 19.54.0 for `IReadModels.Observe<T>()`. Check the client package
|
|
7
|
+
version; on older clients use a supported provider-specific observation and
|
|
8
|
+
verify its key and protected-value access path rather than assuming equivalence.
|
|
9
|
+
|
|
10
|
+
This query fragment belongs on an Arc `[ReadModel]` record `ProjectSummary`:
|
|
11
|
+
|
|
12
|
+
```csharp
|
|
13
|
+
public static System.Reactive.Subjects.ISubject<IEnumerable<ProjectSummary>> All(
|
|
14
|
+
Cratis.Chronicle.ReadModels.IReadModels readModels) =>
|
|
15
|
+
readModels.Observe<ProjectSummary>();
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The model must have an active projection or reducer. The initial emission is the
|
|
19
|
+
complete stored collection (including empty); later emissions replace it.
|
|
20
|
+
Registered container names and key properties are honored without a property
|
|
21
|
+
named `Id`, on MongoDB, SQL and in-memory storage. PII and encrypted values are
|
|
22
|
+
released before delivery. The namespace is captured when `Observe` is called;
|
|
23
|
+
keep the observation in its tenant scope.
|
|
24
|
+
|
|
25
|
+
`Observe<T>(Expression<Func<T, bool>>? filter = null)` filters **client-side after
|
|
26
|
+
release**. It does not reduce server reads or transport and adds no server-side
|
|
27
|
+
sorting/paging. There is no default 50-row window: for large lists choose
|
|
28
|
+
Chronicle's materialized paginated observation, not a post-snapshot page.
|
|
29
|
+
Use `Watch<T>()` for individual changesets, removal metadata and event context.
|
|
30
|
+
|
|
31
|
+
Each call owns a separate observation. The first subscriber starts its stream;
|
|
32
|
+
additional subscribers share it and receive the latest snapshot. Last-subscription
|
|
33
|
+
disposal, subject disposal or `OnCompleted` stops it permanently. Call `Observe`
|
|
34
|
+
again to restart. Stream, filter and deserialization errors reach `OnError`;
|
|
35
|
+
there is no automatic resubscription. SQL polling can coalesce several writes.
|
|
36
|
+
|
|
37
|
+
Passive and event-target models throw `ReadModelCannotBeObserved`; an unknown
|
|
38
|
+
model throws `UnknownReadModel`. Custom `IReadModels` implementations must
|
|
39
|
+
implement or forward `Observe`; its default implementation throws rather than
|
|
40
|
+
pretending observation succeeded.
|
|
41
|
+
|
|
42
|
+
## Verify
|
|
43
|
+
|
|
44
|
+
Run `dotnet build -c Debug` and `dotnet test` for the owning query specs. Cover
|
|
45
|
+
empty, add, update, remove, filter exit and disposal.
|
|
46
|
+
Requires Arc 22.87.0 for Chronicle observations in `QueryScenario`.
|
|
47
|
+
Requires Arc 22.91.1 with Chronicle 19.59.1 for default-mode children/joins/reducers. Scenario rebuilds do
|
|
48
|
+
not prove database notifications or server streaming: exercise those in the
|
|
49
|
+
provider's integration test.
|
|
@@ -37,6 +37,9 @@ are never queries. Use `[ReadModel(RequireQueryAttribute = true)]` and `[Query]`
|
|
|
37
37
|
on intended endpoints when the type also has folds (`Create`/`Reduce`) or public
|
|
38
38
|
helpers. `[Query]` alone does not hide siblings. ARC0026 checks invalid/ambiguous
|
|
39
39
|
query declarations; ARCCHR0019 warns about fold-like statics exposed by convention.
|
|
40
|
+
Requires Arc 22.90.0 for automatic exclusion of methods taking the model itself,
|
|
41
|
+
including `Reduce(event, current)`; `[Query]` cannot force such a method into an
|
|
42
|
+
endpoint. On older Arc keep the explicit `[Query]` policy above; check the package version.
|
|
40
43
|
A `CancellationToken` parameter is supplied by Arc, not a query argument/proxy
|
|
41
44
|
input. Concept parameters are always caller-supplied, never DI. Invalid bool,
|
|
42
45
|
overflow, concept or collection-element GET/QUERY arguments return HTTP 400.
|
|
@@ -96,6 +99,13 @@ public static ISubject<<ReadModelName>> Observe<SingularName>ById(
|
|
|
96
99
|
|
|
97
100
|
Return `ISubject<...>` directly. Do **not** return `Task<ISubject<...>>`.
|
|
98
101
|
|
|
102
|
+
For Chronicle-maintained models, prefer `IReadModels.Observe<T>()` over direct
|
|
103
|
+
sink access so registered collection names, keys and protected-value release are
|
|
104
|
+
preserved.
|
|
105
|
+
Requires Chronicle 19.54.0; read
|
|
106
|
+
[collection observation](collection-observation.md) when exposing such a list.
|
|
107
|
+
The MongoDB extension examples here remain for provider-owned collections.
|
|
108
|
+
|
|
99
109
|
## The `Observe` family — exact signatures
|
|
100
110
|
|
|
101
111
|
```csharp
|
|
@@ -205,5 +215,6 @@ public record <ReadModelName>(...)
|
|
|
205
215
|
When only backend code reads the model, skip `[ReadModel]` entirely and use
|
|
206
216
|
`IEventStore.ReadModels.GetInstanceById<T>(key)`. Its declared return type is
|
|
207
217
|
non-nullable even though no instance may exist, so test the result. There is no
|
|
208
|
-
predicate or `IQueryable` surface on `IReadModels
|
|
209
|
-
|
|
218
|
+
general predicate or `IQueryable` snapshot surface on `IReadModels`.
|
|
219
|
+
`Observe<T>(filter)` is a collection-observation API, not a server-side filtered
|
|
220
|
+
snapshot query; see [collection observation](collection-observation.md).
|
|
@@ -121,6 +121,14 @@ For a filtered reducer, seed the routing metadata as well:
|
|
|
121
121
|
unrouted seeds no longer reach a handler for another stream. Child-before-parent
|
|
122
122
|
writes are retried when the parent later arrives; decimal seeds retain exact values.
|
|
123
123
|
|
|
124
|
+
Requires Chronicle 19.53.1 for nested child `IdentifiedBy` paths to update/remove
|
|
125
|
+
the existing child rather than duplicate it, and 19.53.2 for in-memory child joins
|
|
126
|
+
to preserve the root and all matching siblings. Check the testing/client versions;
|
|
127
|
+
older in-memory outcomes can diverge from persistent sinks. Cover root properties,
|
|
128
|
+
sibling preservation and nested child update/removal, not only one joined value.
|
|
129
|
+
Requires Chronicle 19.58.0 for reducer tag filters and seeded tags/source/stream
|
|
130
|
+
metadata to match production; include matching and excluded events.
|
|
131
|
+
|
|
124
132
|
Events are processed in the order supplied. Seed before asserting, and do not
|
|
125
133
|
try to separate a "setup" `Given` from an "act" `Given` — for a read model they
|
|
126
134
|
are the same phase.
|
|
@@ -79,6 +79,15 @@ the host root and from environment variables prefixed `Cratis__Chronicle__`.
|
|
|
79
79
|
false silently disables the Workbench**, because the Workbench is nothing but a
|
|
80
80
|
client of that API.
|
|
81
81
|
|
|
82
|
+
Requires Chronicle 19.55.0 for `Workbench:BasePath`
|
|
83
|
+
(`Cratis__Chronicle__Workbench__BasePath`) behind a path-routed proxy. It prefixes
|
|
84
|
+
page assets and API/stream/WebSocket routes and accepts stripped or retained
|
|
85
|
+
prefixes; gRPC clients do not use it. Requires 19.56.1 for all navigation and
|
|
86
|
+
Read Models redirects to retain that prefix. Check the kernel version; older
|
|
87
|
+
kernels need a dedicated host/root route. This is explicit configuration, not
|
|
88
|
+
`X-Forwarded-Prefix` trust. Leave it empty for a Stage-bundled kernel whose
|
|
89
|
+
Workbench page is already rewritten by Stage.
|
|
90
|
+
|
|
82
91
|
An application that embeds Chronicle can host the Workbench as a side-car web
|
|
83
92
|
server instead, on its own port and optionally under a base path.
|
|
84
93
|
|
|
@@ -148,6 +157,7 @@ Everything below mutates the running server.
|
|
|
148
157
|
| Screen | Operation | Confirmed in the UI? |
|
|
149
158
|
| --- | --- | --- |
|
|
150
159
|
| Observers | Replay observer | yes |
|
|
160
|
+
| Observers | Fast forward to sequence tail | yes |
|
|
151
161
|
| Observers | Clear quarantine | **no** |
|
|
152
162
|
| Observers | Remove observer | yes |
|
|
153
163
|
| Failed partitions | Retry partition | **no** |
|
|
@@ -168,6 +178,11 @@ Everything below mutates the running server.
|
|
|
168
178
|
| Applications | Add, change secret, remove | remove |
|
|
169
179
|
| Development Tools | **Reset kernel state** | yes |
|
|
170
180
|
|
|
181
|
+
Requires Chronicle 19.56.0 for Fast forward: it skips every unhandled event,
|
|
182
|
+
discards failed partitions and retains already-built state. This is deliberate
|
|
183
|
+
loss of pending processing, not a repair or replay. Read the hosting operations
|
|
184
|
+
reference before authorizing it; older Workbenches have no such action.
|
|
185
|
+
|
|
171
186
|
**A missing confirmation dialog is not permission.** Clear quarantine, retry
|
|
172
187
|
partition, stop/resume/delete job, and perform recommendation all fire on the
|
|
173
188
|
first click. Decide before clicking, not after.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cratis-multi-service-architecture
|
|
3
|
+
description: Design a system of several Cratis services that each own a Chronicle event store - store per service on one kernel, namespace alignment, public contract events and the outbox, the three consumer routes, at-least-once delivery and idempotent consumers, personal data across stores, contract versioning, and what Arc leaves to the application. Use when splitting an application into services, connecting two event stores, or publishing and consuming events across services. Not for running the services locally (use cratis-multi-service-local-orchestration), tenancy inside one store (use cratis-chronicle-multi-tenancy), or Screenplay models (use cratis-screenplay-streams-and-consistency).
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
8
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
9
|
+
|
|
10
|
+
# Several Cratis services, several event stores
|
|
11
|
+
|
|
12
|
+
A multi-service Cratis system is several applications, each owning one Chronicle
|
|
13
|
+
**event store** (the top-level container of its event sequences, event types,
|
|
14
|
+
observers and read models), talking to each other only through **public
|
|
15
|
+
contract events**. The producer publishes to its **outbox**; Chronicle forwards
|
|
16
|
+
each subscribed event into the consumer store's **inbox** for that producer
|
|
17
|
+
(`inbox-<producer store>`); the consumer translates it into its own private facts.
|
|
18
|
+
|
|
19
|
+
Requires Chronicle 19.36.0 or later (`dotnet list package`) for `[Public]`, kernel
|
|
20
|
+
visibility enforcement and publishing through an event-target projection. Older
|
|
21
|
+
clients register event types with unspecified visibility, which the kernel admits
|
|
22
|
+
to the outbox with a warning; upgrade before relying on the rules below.
|
|
23
|
+
|
|
24
|
+
## Decide these first
|
|
25
|
+
|
|
26
|
+
1. **One event store per service, one kernel for all of them.** A Chronicle kernel
|
|
27
|
+
hosts many fully isolated stores. Forwarding between stores happens inside the
|
|
28
|
+
kernel, so two services on different kernels cannot subscribe to each other;
|
|
29
|
+
Chronicle provides no kernel-to-kernel link. Separate kernels need a transport
|
|
30
|
+
the application owns (for example webhooks to an endpoint of the other service).
|
|
31
|
+
2. **A store is the service boundary; a namespace is a tenant inside it.** Do not
|
|
32
|
+
model services as namespaces of one store, and do not model tenants as stores.
|
|
33
|
+
Forwarding appends into the consumer's inbox **in the namespace with the same
|
|
34
|
+
name** as the producer's, so every service must map a tenant to the identical
|
|
35
|
+
namespace name. Arc's `TenantNamespaceResolver` maps the tenant id verbatim and
|
|
36
|
+
an unset tenant to `Default`, which aligns automatically when every service
|
|
37
|
+
resolves the same tenant id. Chronicle has no namespace mapping between stores.
|
|
38
|
+
3. **The store name is part of the contract.** The producer's configured
|
|
39
|
+
`Cratis:Chronicle:EventStore` must equal the name in its contracts'
|
|
40
|
+
`[EventStore("…")]`; that string is how the consumer's subscription finds the
|
|
41
|
+
producer's outbox. Declare it once as a constant in the contracts project and
|
|
42
|
+
never derive it from a deployment environment.
|
|
43
|
+
4. **Only public contract events cross.** Never share read models, private event
|
|
44
|
+
types, a database or a collection between services. The producer translates
|
|
45
|
+
private facts into a deliberate public summary event; the consumer translates
|
|
46
|
+
that into its own private events (a Translation slice on each side).
|
|
47
|
+
5. **Ownership is a convention the client does not enforce.**
|
|
48
|
+
`IChronicleClient.GetEventStore(name)` addresses any store on the kernel and a
|
|
49
|
+
store comes into existence when a client first registers with it. A service
|
|
50
|
+
appends only to its own store and its own outbox. Review for appends into another
|
|
51
|
+
service's store or event log.
|
|
52
|
+
|
|
53
|
+
## Publish a contract
|
|
54
|
+
|
|
55
|
+
Put public events in a thin `<Service>.Contracts` project that references only
|
|
56
|
+
`Cratis.Chronicle` and carries the producer's store name once:
|
|
57
|
+
|
|
58
|
+
```xml
|
|
59
|
+
<ItemGroup>
|
|
60
|
+
<AssemblyAttribute Include="Cratis.Chronicle.Events.EventStoreAttribute">
|
|
61
|
+
<_Parameter1>Ordering</_Parameter1>
|
|
62
|
+
</AssemblyAttribute>
|
|
63
|
+
</ItemGroup>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```csharp
|
|
67
|
+
// Ordering.Contracts/OrderAccepted.cs
|
|
68
|
+
using Cratis.Chronicle.Events;
|
|
69
|
+
|
|
70
|
+
namespace Ordering.Contracts;
|
|
71
|
+
|
|
72
|
+
[EventType]
|
|
73
|
+
public record OrderAccepted(decimal Total);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
An `[EventStore]` on the type or its assembly registers the type as **public**;
|
|
77
|
+
`[Public]` does the same without naming a store. The kernel refuses a private
|
|
78
|
+
type in the outbox (`PrivateEventTypeCannotBeAppendedToOutbox`) and a public type
|
|
79
|
+
in the event log (`PublicEventTypeCannotBeAppendedToEventLog`); both arrive as
|
|
80
|
+
append-result errors, not exceptions, and refuse the whole batch.
|
|
81
|
+
|
|
82
|
+
Choose how the producer publishes:
|
|
83
|
+
|
|
84
|
+
| Default | When | Delivery behavior |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| **Event-target projection**: `IProjectionFor<OrderAccepted>` built `From<OrderPlaced>` | The public event is a fold of private events | One atomic append per change, idempotent on retry; the outbox is the default destination |
|
|
87
|
+
| Reactor that observes a private event and appends to `EventSequenceId.Outbox` | The public event needs data a projection cannot fold | Re-runs on partition recovery, so it can append again |
|
|
88
|
+
| Command or service appending to the event log and then the outbox | Never | Two appends are not atomic: the private fact can stand without its publication |
|
|
89
|
+
|
|
90
|
+
Event-target targets cannot carry `[PII]` (`EventSequenceTargetCarriesCompliance`),
|
|
91
|
+
only one publisher may target a given event type per sequence
|
|
92
|
+
(`EventPublisherConflict`), and replaying the publishing projection appends **new**
|
|
93
|
+
public instances rather than rewriting history. Read
|
|
94
|
+
[references/publish-and-consume.md](references/publish-and-consume.md) when writing
|
|
95
|
+
the publishing projection or reactor, the consumer, an explicit subscription or a
|
|
96
|
+
CLI subscription.
|
|
97
|
+
|
|
98
|
+
## Consume a contract
|
|
99
|
+
|
|
100
|
+
Pick one route per source store:
|
|
101
|
+
|
|
102
|
+
| Route | Use when |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| **Implicit**: reference the producer's contracts package; observe its types in a reactor, reducer or projection | Default for .NET consumers. The client routes the observer to `inbox-<store>` and registers one kernel subscription per source store |
|
|
105
|
+
| **Explicit**: `eventStore.Subscriptions.Subscribe(id, "Ordering", b => b.WithEventType<OrderAccepted>())` and observe `[EventSequence(EventSequenceId.InboxPrefix + "Ordering")]` | Kotlin, TypeScript and Elixir consumers, contract types without `[EventStore]`, or a consumer that must choose types at run time |
|
|
106
|
+
| **Operator**: `cratis chronicle subscriptions add <id> <source-store> <type-ids> -e <target-store>` | Wiring stores that run no consumer code yet, or repairing a subscription by hand |
|
|
107
|
+
|
|
108
|
+
Implicit `[EventStore]` routing exists only in the .NET client. A producer marks a type public with
|
|
109
|
+
`[Public]` in .NET, or `use Chronicle.Events.EventType, public: true` in Elixir (Requires
|
|
110
|
+
Chronicle.Elixir 3.11.0). Every handled
|
|
111
|
+
type of one observer must come from one store (`CHR0008`), and an observer-level
|
|
112
|
+
`[EventStore]` cannot be combined with an explicit event sequence (`CHR0013`).
|
|
113
|
+
`cratis-chronicle-reactor` owns the routing order and those analyzers.
|
|
114
|
+
|
|
115
|
+
The consumer's first act is translation: append its **own private** event, then
|
|
116
|
+
build its read models from that. Never build a long-lived read model straight from
|
|
117
|
+
another service's contract; the contract then dictates the consumer's history.
|
|
118
|
+
|
|
119
|
+
## Delivery semantics the design must absorb
|
|
120
|
+
|
|
121
|
+
- **Order holds per event source only.** Observers process each event source's
|
|
122
|
+
events in order; nothing orders events of different sources, or of different
|
|
123
|
+
stores, relative to each other.
|
|
124
|
+
- **At least once.** Forwarding is a kernel observer of the producer's outbox; a
|
|
125
|
+
failed inbox append fails the partition and is retried from the last forwarded
|
|
126
|
+
event, and the inbox append carries no deduplication key. Producer replays add
|
|
127
|
+
new public instances. Design every consumer to tolerate a repeated contract fact.
|
|
128
|
+
- **Idempotent consumers.** A `ReactorDelivery` handler parameter identifies one
|
|
129
|
+
delivery of one inbox event (reactor, store, namespace, sequence, partition,
|
|
130
|
+
sequence number) and is stable across retry, recovery and replay; keep a receipt
|
|
131
|
+
under its `Id` before a side effect. It cannot recognize the same contract fact
|
|
132
|
+
appended to the inbox twice, because each copy has its own sequence number. Where
|
|
133
|
+
that would cause harm, make the translation idempotent on a business key the
|
|
134
|
+
contract carries, or let a constraint refuse the duplicate local fact.
|
|
135
|
+
`[OnceOnly]` only excludes replays.
|
|
136
|
+
- **Inbox history is the consumer's.** Replaying a consumer observer re-reads the
|
|
137
|
+
inbox, not the producer. Unsubscribing leaves forwarded events in place and a
|
|
138
|
+
re-subscription resumes from that point. Chronicle documents no way to re-forward
|
|
139
|
+
producer history into an existing inbox, so a consumer that must rebuild from the
|
|
140
|
+
producer's past needs an application-owned backfill.
|
|
141
|
+
- **Startup order is tolerant.** A subscription to a store that does not exist yet
|
|
142
|
+
is parked and activates when the store appears.
|
|
143
|
+
|
|
144
|
+
## Personal data across stores
|
|
145
|
+
|
|
146
|
+
Forwarding preserves the event's subject and copies the subject's encryption key
|
|
147
|
+
into the consumer's store in the same namespace, unless that subject was erased
|
|
148
|
+
there. An erasure therefore reaches every store in the namespace. A forwarded
|
|
149
|
+
`[PII]` event for a subject erased in the consumer fails its partition. Give
|
|
150
|
+
every event that carries personal data an explicit subject, keep personal data out
|
|
151
|
+
of tags, and export only the fields consumers need. Read
|
|
152
|
+
`cratis-chronicle-compliance` for subjects and erasure.
|
|
153
|
+
|
|
154
|
+
## Versioning contracts
|
|
155
|
+
|
|
156
|
+
A public event type follows the same generation and migration rules as a private
|
|
157
|
+
one (`cratis-chronicle-event-type-migration`). Kernel subscriptions name event
|
|
158
|
+
types by id and register them as generation 1, and the CLI's `subscriptions add`
|
|
159
|
+
takes ids only. Prefer additive, optional changes to a contract; publish a new
|
|
160
|
+
event type for a breaking change and keep publishing the old one until every
|
|
161
|
+
consumer has moved, rather than adding a generation consumers may not handle.
|
|
162
|
+
Version the contracts package with the contract, and never move a type between
|
|
163
|
+
stores.
|
|
164
|
+
|
|
165
|
+
## Arc in every service
|
|
166
|
+
|
|
167
|
+
- Each service is its own Arc host (`AddCratis()` or `AddCratisArc` plus
|
|
168
|
+
`WithChronicle`) with its own `Cratis:Chronicle:EventStore` and its own read-model
|
|
169
|
+
database. `cratis-arc-hosting` owns the bootstrap.
|
|
170
|
+
- Arc provides no server-side client for another service's commands or queries;
|
|
171
|
+
generated proxies are for frontends. Prefer events between services. When a
|
|
172
|
+
command truly needs another service's answer, fetch it in `Provide()` through an
|
|
173
|
+
application-owned HTTP client and treat it as untrusted input.
|
|
174
|
+
- Arc does not propagate identity or tenant between services. A service calling
|
|
175
|
+
another forwards the tenant header itself, authenticates as itself, and the callee
|
|
176
|
+
enforces its own authorization. Forwarded identity details are not authorization
|
|
177
|
+
evidence; see `cratis-arc-authentication-authorization-and-identity`.
|
|
178
|
+
- A frontend talking to several services: `<Arc microservice="…">` only adds routing
|
|
179
|
+
metadata for an ingress the application configures, and nested `<Arc>` providers
|
|
180
|
+
do not isolate identity or hubs. Prefer one frontend per service, or one ingress
|
|
181
|
+
that routes by that metadata.
|
|
182
|
+
|
|
183
|
+
## Verify the system
|
|
184
|
+
|
|
185
|
+
1. `cratis chronicle event-stores list` shows one store per service and nothing
|
|
186
|
+
named after an environment or a tenant.
|
|
187
|
+
2. `cratis chronicle subscriptions list -e <consumer-store>` shows one subscription
|
|
188
|
+
per producer, with exactly the contract type ids the consumer handles.
|
|
189
|
+
3. A specification on each side: the producer publishes the contract from its
|
|
190
|
+
private fact; the consumer turns one contract fact into its private fact, and a
|
|
191
|
+
repeated delivery of it changes nothing.
|
|
192
|
+
4. One end-to-end run per tenant namespace: append on the producer, then observe
|
|
193
|
+
the consumer's private event in the same namespace. Diagnose a stuck flow with
|
|
194
|
+
`cratis chronicle diagnose --all-event-stores` (`cratis-chronicle-cli-operations`).
|
|
195
|
+
|
|
196
|
+
## Route near misses
|
|
197
|
+
|
|
198
|
+
- Run several services, a kernel and frontends together on one machine:
|
|
199
|
+
`cratis-multi-service-local-orchestration`.
|
|
200
|
+
- Decide event vocabulary and stream boundaries inside one service:
|
|
201
|
+
`cratis-chronicle-event-modeling`.
|
|
202
|
+
- Model the services, public events and Translate slices in Screenplay:
|
|
203
|
+
`cratis-screenplay-streams-and-consistency`.
|
|
204
|
+
- Kernel production hosting, TLS and clustering: `cratis-chronicle-hosting`.
|
package/package/corpus/skills/cratis-multi-service-architecture/references/publish-and-consume.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
<!-- Copyright (c) Cratis. All rights reserved. -->
|
|
2
|
+
<!-- Licensed under the MIT license. See LICENSE file in the project root for full license information. -->
|
|
3
|
+
|
|
4
|
+
# Publishing and consuming a contract between two stores
|
|
5
|
+
|
|
6
|
+
## Contents
|
|
7
|
+
|
|
8
|
+
- The example system
|
|
9
|
+
- Publish with an event-target projection
|
|
10
|
+
- Publish from a reactor
|
|
11
|
+
- Consume through implicit routing
|
|
12
|
+
- Consume through an explicit subscription
|
|
13
|
+
- Subscribe from the CLI
|
|
14
|
+
- Make a consumer side effect idempotent
|
|
15
|
+
- Checks
|
|
16
|
+
|
|
17
|
+
## The example system
|
|
18
|
+
|
|
19
|
+
`Ordering` and `Billing` are two services, each with its own event store of the
|
|
20
|
+
same name on one kernel. `Ordering` records a private `OrderPlaced`, publishes the
|
|
21
|
+
public `OrderAccepted`, and `Billing` turns it into its private `InvoiceRequested`.
|
|
22
|
+
Each service's configuration names its own store:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"Cratis": {
|
|
27
|
+
"Chronicle": {
|
|
28
|
+
"EventStore": "Ordering"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The contracts project (`Ordering.Contracts`, referencing only `Cratis.Chronicle`)
|
|
35
|
+
carries `[assembly: EventStore("Ordering")]` through the `AssemblyAttribute` item
|
|
36
|
+
shown in the skill and holds `OrderAccepted`. `Billing` references the contracts
|
|
37
|
+
project or its package, never `Ordering` itself. The `AssemblyAttribute` item needs
|
|
38
|
+
`GenerateAssemblyInfo` left at its default `true`.
|
|
39
|
+
|
|
40
|
+
## Publish with an event-target projection
|
|
41
|
+
|
|
42
|
+
The default. A projection whose target is an `[EventType]` record publishes the
|
|
43
|
+
folded state as that event, to the outbox unless the event type carries
|
|
44
|
+
`[PublishTo("<sequence>")]`. The key is the event source id, so the published event
|
|
45
|
+
keeps the order's event source id and the consumer reads it from `EventContext`.
|
|
46
|
+
|
|
47
|
+
```csharp
|
|
48
|
+
// Ordering/Placing/OrderPlaced.cs
|
|
49
|
+
using Cratis.Chronicle.Events;
|
|
50
|
+
|
|
51
|
+
namespace Ordering.Placing;
|
|
52
|
+
|
|
53
|
+
[EventType]
|
|
54
|
+
public record OrderPlaced(decimal Total);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```csharp
|
|
58
|
+
// Ordering/Placing/OrderAcceptedPublisher.cs
|
|
59
|
+
using Cratis.Chronicle.Projections;
|
|
60
|
+
using Ordering.Contracts;
|
|
61
|
+
|
|
62
|
+
namespace Ordering.Placing;
|
|
63
|
+
|
|
64
|
+
public class OrderAcceptedPublisher : IProjectionFor<OrderAccepted>
|
|
65
|
+
{
|
|
66
|
+
public void Define(IProjectionBuilderFor<OrderAccepted> builder) => builder
|
|
67
|
+
.From<OrderPlaced>(_ => _
|
|
68
|
+
.Set(m => m.Total).To(e => e.Total));
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
What the event-sequence sink guarantees: each change is one append whose
|
|
73
|
+
publication identity is deterministic, so a retried or redelivered step returns
|
|
74
|
+
the event already committed instead of a second one. A step that changes nothing
|
|
75
|
+
publishes nothing. A change to the projection's mapping triggers a replay that
|
|
76
|
+
publishes new instances for the same source events; consumers see them as new
|
|
77
|
+
facts. Registration fails on the client with
|
|
78
|
+
`PrivateEventTypeCannotBePublishedToOutbox` when the target is not public, with
|
|
79
|
+
`EventLogIsNotAPublicationTarget` for the event log, with
|
|
80
|
+
`EventSequenceTargetCarriesCompliance` for a `[PII]` target, and with
|
|
81
|
+
`EventPublisherConflict` for a second publisher of the same type to the same
|
|
82
|
+
sequence.
|
|
83
|
+
|
|
84
|
+
## Publish from a reactor
|
|
85
|
+
|
|
86
|
+
Use this only when a fold cannot express the public event. The reactor appends to
|
|
87
|
+
the outbox and must fail its partition when the append is refused; a refused append
|
|
88
|
+
returns errors and throws nothing, so ignoring the result silently drops the
|
|
89
|
+
publication. Recovery re-runs the handler, so the same contract fact can be
|
|
90
|
+
appended again.
|
|
91
|
+
|
|
92
|
+
```csharp
|
|
93
|
+
// Ordering/Placing/PublishOrderAccepted.cs
|
|
94
|
+
using Cratis.Chronicle;
|
|
95
|
+
using Cratis.Chronicle.EventSequences;
|
|
96
|
+
using Cratis.Chronicle.Events;
|
|
97
|
+
using Cratis.Chronicle.Reactors;
|
|
98
|
+
using Ordering.Contracts;
|
|
99
|
+
|
|
100
|
+
namespace Ordering.Placing;
|
|
101
|
+
|
|
102
|
+
public class OrderAcceptedNotPublished(AppendResult result)
|
|
103
|
+
: Exception($"Publishing OrderAccepted failed with {result.Errors.Count()} error(s) and {result.ConstraintViolations.Count()} constraint violation(s).");
|
|
104
|
+
|
|
105
|
+
public class PublishOrderAccepted(IEventStore eventStore) : IReactor
|
|
106
|
+
{
|
|
107
|
+
[OnceOnly]
|
|
108
|
+
public async Task Placed(OrderPlaced @event, EventContext context)
|
|
109
|
+
{
|
|
110
|
+
var result = await eventStore
|
|
111
|
+
.GetEventSequence(EventSequenceId.Outbox)
|
|
112
|
+
.Append(context.EventSourceId, new OrderAccepted(@event.Total));
|
|
113
|
+
if (!result.IsSuccess) throw new OrderAcceptedNotPublished(result);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`[OnceOnly]` keeps a replay of this reactor from publishing again; it does not
|
|
119
|
+
stop recovery from doing so.
|
|
120
|
+
|
|
121
|
+
## Consume through implicit routing
|
|
122
|
+
|
|
123
|
+
The default for a .NET consumer. Because `OrderAccepted`'s assembly names the
|
|
124
|
+
`Ordering` store, the client routes this reactor to `inbox-Ordering` and registers
|
|
125
|
+
a kernel subscription for the handled types after registering its observers. The
|
|
126
|
+
returned event is appended to `Billing`'s event log under the incoming event
|
|
127
|
+
source id.
|
|
128
|
+
|
|
129
|
+
```csharp
|
|
130
|
+
// Billing/Invoicing/InvoiceRequested.cs
|
|
131
|
+
using Cratis.Chronicle.Events;
|
|
132
|
+
|
|
133
|
+
namespace Billing.Invoicing;
|
|
134
|
+
|
|
135
|
+
[EventType]
|
|
136
|
+
public record InvoiceRequested(decimal Total);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```csharp
|
|
140
|
+
// Billing/Invoicing/AcceptOrders.cs
|
|
141
|
+
using Cratis.Chronicle.Reactors;
|
|
142
|
+
using Ordering.Contracts;
|
|
143
|
+
|
|
144
|
+
namespace Billing.Invoicing;
|
|
145
|
+
|
|
146
|
+
public class AcceptOrders : IReactor
|
|
147
|
+
{
|
|
148
|
+
[OnceOnly]
|
|
149
|
+
public InvoiceRequested Accepted(OrderAccepted @event) => new(@event.Total);
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
A reducer or projection handling contract types is routed the same way, but keep
|
|
154
|
+
read models on the consumer's private events (see the skill). When the contract
|
|
155
|
+
types carry no `[EventStore]`, put `[EventStore("Ordering")]` on the observer class
|
|
156
|
+
instead, never together with `[EventSequence]`.
|
|
157
|
+
|
|
158
|
+
## Consume through an explicit subscription
|
|
159
|
+
|
|
160
|
+
Use this when the consumer is not .NET, when the contract types carry no store, or
|
|
161
|
+
when types are chosen at run time. Register it at startup through the singleton
|
|
162
|
+
client, then observe the inbox explicitly:
|
|
163
|
+
|
|
164
|
+
```csharp
|
|
165
|
+
// Billing/Program.cs (excerpt, after builder.Build())
|
|
166
|
+
var client = app.Services.GetRequiredService<IChronicleClient>();
|
|
167
|
+
var billing = await client.GetEventStore("Billing");
|
|
168
|
+
await billing.Subscriptions.Subscribe(
|
|
169
|
+
"ordering-to-billing",
|
|
170
|
+
"Ordering",
|
|
171
|
+
subscription => subscription.WithEventType<OrderAccepted>());
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```csharp
|
|
175
|
+
// Billing/Invoicing/AcceptOrders.cs
|
|
176
|
+
using Cratis.Chronicle.EventSequences;
|
|
177
|
+
using Cratis.Chronicle.Reactors;
|
|
178
|
+
using Ordering.Contracts;
|
|
179
|
+
|
|
180
|
+
namespace Billing.Invoicing;
|
|
181
|
+
|
|
182
|
+
[EventSequence(EventSequenceId.InboxPrefix + "Ordering")]
|
|
183
|
+
public class AcceptOrders : IReactor
|
|
184
|
+
{
|
|
185
|
+
[OnceOnly]
|
|
186
|
+
public InvoiceRequested Accepted(OrderAccepted @event) => new(@event.Total);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
A class-level `[EventSequence]` takes priority over the contract's store for
|
|
191
|
+
routing, and the client registers no implicit subscription for such an observer.
|
|
192
|
+
`Subscribe` is idempotent per subscription id, so calling it on every start is
|
|
193
|
+
safe. Without `WithEventType`, the subscription covers every event type the client
|
|
194
|
+
knows when it registers; types it does not know are not forwarded. `Unsubscribe`
|
|
195
|
+
stops forwarding and keeps the inbox events; subscribing again with the same id
|
|
196
|
+
resumes from that point, not from the producer's beginning.
|
|
197
|
+
|
|
198
|
+
## Subscribe from the CLI
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
cratis chronicle subscriptions add ordering-to-billing Ordering <OrderAccepted-type-id> -e Billing
|
|
202
|
+
cratis chronicle subscriptions list -e Billing
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
`add` takes comma-separated event type ids (list them with
|
|
206
|
+
`cratis chronicle event-types list -e Ordering`) and does not prompt; `remove`
|
|
207
|
+
prompts unless given `--yes`. Both mutate a running store: follow the
|
|
208
|
+
authorization discipline in `cratis-chronicle-cli-operations`.
|
|
209
|
+
|
|
210
|
+
## Make a consumer side effect idempotent
|
|
211
|
+
|
|
212
|
+
For an external side effect in a consumer reactor, take a `ReactorDelivery`
|
|
213
|
+
parameter and keep a receipt under `delivery.Id` in storage the application owns:
|
|
214
|
+
check it before the effect and record it after. The identity is the same across
|
|
215
|
+
retry, recovery and replay of that inbox event. It differs for a second copy of the
|
|
216
|
+
same contract fact in the inbox, so when duplicates would cause harm, key the
|
|
217
|
+
receipt (or a unique constraint on the local fact) on a business identity the
|
|
218
|
+
contract carries. Chronicle documents the receipt pattern under reactors, delivery
|
|
219
|
+
identity: <https://www.cratis.io/chronicle/reactors/delivery-identity/>.
|
|
220
|
+
|
|
221
|
+
## Checks
|
|
222
|
+
|
|
223
|
+
- Producer specification: appending the private fact publishes exactly one contract
|
|
224
|
+
event with the expected content; an identical repeat publishes nothing.
|
|
225
|
+
- Consumer specification: one contract event yields one private fact; a repeated
|
|
226
|
+
delivery does not produce a second side effect.
|
|
227
|
+
- `cratis chronicle observers list -e Billing` shows the consumer observer on
|
|
228
|
+
`inbox-Ordering`, and `cratis chronicle failed-partitions list -e Billing` is
|
|
229
|
+
empty after an end-to-end run.
|