@eventcatalog/create-eventcatalog 4.3.12-beta.1 → 4.3.13
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/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/CreateProduct/examples/index.mdx +194 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/DeleteProduct/examples/index.mdx +161 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/commands/UpdateProduct/examples/index.mdx +182 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductCreated/examples/index.mdx +227 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductDeleted/examples/index.mdx +175 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/events/ProductUpdated/examples/index.mdx +205 -0
- package/templates/default/domains/Catalog/systems/product-catalog-system/services/ProductAPI/queries/GetProduct/examples/index.mdx +205 -0
- package/templates/default/domains/Catalog/systems/search-system/services/SearchAPI/queries/SearchProducts/examples/index.mdx +369 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/commands/RegisterCustomer/examples/index.mdx +168 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/commands/UpdateCustomer/examples/index.mdx +168 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/events/CustomerRegistered/examples/index.mdx +201 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/events/CustomerUpdated/examples/index.mdx +194 -0
- package/templates/default/domains/Customer/systems/customer-management-system/services/CustomerAPI/queries/GetCustomer/examples/index.mdx +194 -0
- package/templates/default/domains/Customer/systems/identity-provider/services/OAuthAPI/commands/AuthenticateCustomer/examples/index.mdx +198 -0
- package/templates/default/domains/Customer/systems/identity-provider/services/OAuthAPI/events/CustomerAuthenticated/examples/index.mdx +276 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentCreated/examples/index.mdx +184 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentDelivered/examples/index.mdx +173 -0
- package/templates/default/domains/Fulfilment/systems/carrier/services/CarrierTrackingAPI/events/ShipmentFailed/examples/index.mdx +265 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/commands/ReleaseInventory/examples/index.mdx +246 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/events/InventoryReserved/examples/index.mdx +227 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/events/InventoryUnavailable/examples/index.mdx +229 -0
- package/templates/default/domains/Fulfilment/systems/inventory-system/services/InventoryService/queries/GetStockLevel/examples/index.mdx +186 -0
- package/templates/default/domains/Fulfilment/systems/shipping-system/services/CarrierAdapter/commands/CreateShipment/examples/index.mdx +206 -0
- package/templates/default/domains/Fulfilment/systems/warehouse-system/services/PickingWorker/events/OrderPacked/examples/index.mdx +172 -0
- package/templates/default/domains/Fulfilment/systems/warehouse-system/services/WarehouseService/events/OrderReadyForShipping/examples/index.mdx +208 -0
- package/templates/default/domains/Ordering/systems/checkout-system/services/CheckoutOrchestrator/commands/AuthorizePayment/examples/index.mdx +179 -0
- package/templates/default/domains/Ordering/systems/checkout-system/services/CheckoutOrchestrator/commands/ReserveInventory/examples/index.mdx +215 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/commands/CancelOrder/examples/index.mdx +163 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/commands/CreateOrder/examples/index.mdx +246 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCancelled/examples/index.mdx +267 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCompleted/examples/index.mdx +171 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/events/OrderCreated/examples/index.mdx +190 -0
- package/templates/default/domains/Ordering/systems/order-management-system/services/OrderService/queries/GetOrder/examples/index.mdx +343 -0
- package/templates/default/domains/Payments/systems/fraud-detection/services/FraudAPI/events/FraudCheckFailed/examples/index.mdx +271 -0
- package/templates/default/domains/Payments/systems/fraud-detection/services/FraudAPI/events/FraudCheckPassed/examples/index.mdx +173 -0
- package/templates/default/domains/Payments/systems/payment-processing-system/services/PaymentWorker/events/PaymentRequested/examples/index.mdx +191 -0
- package/templates/default/domains/Payments/systems/payment-processing-system/services/PaymentWorker/events/RefundRequested/examples/index.mdx +194 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/PaymentFailed/examples/index.mdx +265 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/PaymentSucceeded/examples/index.mdx +190 -0
- package/templates/default/domains/Payments/systems/stripe/services/StripeWebhookEndpoint/events/RefundProcessed/examples/index.mdx +186 -0
- package/templates/default/domains/Reviews/services/RatingAggregator/events/rating-updated/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/flag-review/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/submit-review/examples/index.mdx +195 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/commands/vote-review-helpful/examples/index.mdx +178 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-flagged/examples/index.mdx +186 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-helpful-voted/examples/index.mdx +177 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/events/review-submitted/examples/index.mdx +194 -0
- package/templates/default/domains/Reviews/services/ReviewAPI/queries/get-product-reviews/examples/index.mdx +259 -0
- package/templates/default/domains/Reviews/services/ReviewModerationWorker/events/review-published/examples/index.mdx +183 -0
- package/templates/default/domains/Reviews/services/ReviewModerationWorker/events/review-rejected/examples/index.mdx +178 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/AddItemToCart/examples/index.mdx +171 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/CheckoutCart/examples/index.mdx +168 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/commands/RemoveItemFromCart/examples/index.mdx +170 -0
- package/templates/default/domains/Shopping/systems/cart-system/services/CartAPI/events/CartCheckedOut/examples/index.mdx +275 -0
- package/templates/default/domains/Shopping/systems/promotion-system/services/PromotionService/commands/CalculateDiscount/examples/index.mdx +207 -0
- package/templates/default/domains/Shopping/systems/promotion-system/services/PromotionService/events/DiscountCalculated/examples/index.mdx +190 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Create a multi-item order with its payment authorisation
|
|
6
|
+
|
|
7
|
+
Stock is reserved and payment is authorised for two T-shirts and a cap. As the final step of the checkout saga, the Checkout Orchestrator sends this command to the Order Service.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `cartId` and `customerId` link the order to the checked-out cart and the customer.
|
|
12
|
+
- `items` has 2 lines: 2 × Classic White T-shirt at 1,999 pence and 1 × Logo Cap at 1,499 pence. `unitPrice` is per unit, in minor units.
|
|
13
|
+
- `total` is the sum of `quantity` × `unitPrice` across all lines.
|
|
14
|
+
- `currency` is `GBP`.
|
|
15
|
+
- `paymentAuthorizationId` references the hold placed by `AuthorizePayment`, so the funds can be captured.
|
|
16
|
+
|
|
17
|
+
The total is **3,998 + 1,499 = 5,497 pence (£54.97)**.
|
|
18
|
+
|
|
19
|
+
### Using this example
|
|
20
|
+
|
|
21
|
+
The Order Service should store both lines, check that `total` equals the sum of the lines, and publish `OrderCreated` with a total of 5,497 `GBP`.
|
|
22
|
+
|
|
23
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the CreateOrder schema. The package names and send methods are illustrative.
|
|
24
|
+
|
|
25
|
+
</Column>
|
|
26
|
+
|
|
27
|
+
<Column>
|
|
28
|
+
|
|
29
|
+
<CodeGroup dropdown>
|
|
30
|
+
|
|
31
|
+
```typescript send-create-order.ts
|
|
32
|
+
import { EventsClient } from '@acme/events';
|
|
33
|
+
import type { CreateOrder } from './schemas/create-order';
|
|
34
|
+
|
|
35
|
+
const client = new EventsClient({
|
|
36
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const command: CreateOrder = {
|
|
40
|
+
cartId: 'c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d',
|
|
41
|
+
customerId: '3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d',
|
|
42
|
+
items: [
|
|
43
|
+
{
|
|
44
|
+
productId: '5e8f2a1b-3c4d-4e5f-8a6b-7c8d9e0f1a2b',
|
|
45
|
+
quantity: 2,
|
|
46
|
+
unitPrice: 1999,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
productId: '6f9a3b2c-4d5e-4f6a-9b7c-8d9e0f1a2b3c',
|
|
50
|
+
quantity: 1,
|
|
51
|
+
unitPrice: 1499,
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
total: 5497,
|
|
55
|
+
currency: 'GBP',
|
|
56
|
+
paymentAuthorizationId: 'auth_7Hk2Qp9LmX4v',
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
await client.send('CreateOrder', command);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```python send_create_order.py
|
|
63
|
+
import os
|
|
64
|
+
from acme_events import EventsClient
|
|
65
|
+
|
|
66
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
67
|
+
|
|
68
|
+
command = {
|
|
69
|
+
"cartId": "c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
|
70
|
+
"customerId": "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
71
|
+
"items": [
|
|
72
|
+
{
|
|
73
|
+
"productId": "5e8f2a1b-3c4d-4e5f-8a6b-7c8d9e0f1a2b",
|
|
74
|
+
"quantity": 2,
|
|
75
|
+
"unitPrice": 1999,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"productId": "6f9a3b2c-4d5e-4f6a-9b7c-8d9e0f1a2b3c",
|
|
79
|
+
"quantity": 1,
|
|
80
|
+
"unitPrice": 1499,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
"total": 5497,
|
|
84
|
+
"currency": "GBP",
|
|
85
|
+
"paymentAuthorizationId": "auth_7Hk2Qp9LmX4v",
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
client.send("CreateOrder", command)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```java SendCreateOrder.java
|
|
92
|
+
import com.acme.events.EventsClient;
|
|
93
|
+
import java.util.List;
|
|
94
|
+
import java.util.Map;
|
|
95
|
+
|
|
96
|
+
public class SendCreateOrder {
|
|
97
|
+
public static void main(String[] args) {
|
|
98
|
+
var client = new EventsClient(
|
|
99
|
+
System.getenv("ACME_API_KEY")
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
var command = Map.of(
|
|
103
|
+
"cartId", "c1a2b3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
|
|
104
|
+
"customerId", "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
105
|
+
"items", List.of(
|
|
106
|
+
Map.of(
|
|
107
|
+
"productId", "5e8f2a1b-3c4d-4e5f-8a6b-7c8d9e0f1a2b",
|
|
108
|
+
"quantity", 2,
|
|
109
|
+
"unitPrice", 1999
|
|
110
|
+
),
|
|
111
|
+
Map.of(
|
|
112
|
+
"productId", "6f9a3b2c-4d5e-4f6a-9b7c-8d9e0f1a2b3c",
|
|
113
|
+
"quantity", 1,
|
|
114
|
+
"unitPrice", 1499
|
|
115
|
+
)
|
|
116
|
+
),
|
|
117
|
+
"total", 5497,
|
|
118
|
+
"currency", "GBP",
|
|
119
|
+
"paymentAuthorizationId", "auth_7Hk2Qp9LmX4v"
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
client.send("CreateOrder", command);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
</CodeGroup>
|
|
128
|
+
|
|
129
|
+
</Column>
|
|
130
|
+
|
|
131
|
+
</Columns>
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
<Columns cols={2}>
|
|
136
|
+
|
|
137
|
+
<Column>
|
|
138
|
+
|
|
139
|
+
## 2. Create a single-item euro order
|
|
140
|
+
|
|
141
|
+
A customer in Ireland buys one hoodie priced in euros. The command carries only the required fields and leaves out `paymentAuthorizationId`.
|
|
142
|
+
|
|
143
|
+
### Payload details
|
|
144
|
+
|
|
145
|
+
- `items` has one line: 1 × Heavyweight Hoodie at 5,799 cents.
|
|
146
|
+
- `total` equals that single line.
|
|
147
|
+
- `currency` is `EUR`, so `unitPrice` and `total` are in cents.
|
|
148
|
+
- `paymentAuthorizationId` is optional and omitted here.
|
|
149
|
+
|
|
150
|
+
The total is **5,799 cents (€57.99)**.
|
|
151
|
+
|
|
152
|
+
### Using this example
|
|
153
|
+
|
|
154
|
+
Use this to check that the Order Service creates an order without a `paymentAuthorizationId` and keeps the `EUR` currency on the resulting `OrderCreated` event.
|
|
155
|
+
|
|
156
|
+
The examples use a **fictional Acme Events SDK** to send a payload matching the CreateOrder schema. The package names and send methods are illustrative.
|
|
157
|
+
|
|
158
|
+
</Column>
|
|
159
|
+
|
|
160
|
+
<Column>
|
|
161
|
+
|
|
162
|
+
<CodeGroup dropdown>
|
|
163
|
+
|
|
164
|
+
```typescript send-create-order.ts
|
|
165
|
+
import { EventsClient } from '@acme/events';
|
|
166
|
+
import type { CreateOrder } from './schemas/create-order';
|
|
167
|
+
|
|
168
|
+
const client = new EventsClient({
|
|
169
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const command: CreateOrder = {
|
|
173
|
+
cartId: 'd2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e',
|
|
174
|
+
customerId: '8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e',
|
|
175
|
+
items: [
|
|
176
|
+
{
|
|
177
|
+
productId: '7a0b4c3d-5e6f-4a7b-8c8d-9e0f1a2b3c4d',
|
|
178
|
+
quantity: 1,
|
|
179
|
+
unitPrice: 5799,
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
total: 5799,
|
|
183
|
+
currency: 'EUR',
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
await client.send('CreateOrder', command);
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
```python send_create_order.py
|
|
190
|
+
import os
|
|
191
|
+
from acme_events import EventsClient
|
|
192
|
+
|
|
193
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
194
|
+
|
|
195
|
+
command = {
|
|
196
|
+
"cartId": "d2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
|
197
|
+
"customerId": "8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e",
|
|
198
|
+
"items": [
|
|
199
|
+
{
|
|
200
|
+
"productId": "7a0b4c3d-5e6f-4a7b-8c8d-9e0f1a2b3c4d",
|
|
201
|
+
"quantity": 1,
|
|
202
|
+
"unitPrice": 5799,
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
"total": 5799,
|
|
206
|
+
"currency": "EUR",
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
client.send("CreateOrder", command)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
```java SendCreateOrder.java
|
|
213
|
+
import com.acme.events.EventsClient;
|
|
214
|
+
import java.util.List;
|
|
215
|
+
import java.util.Map;
|
|
216
|
+
|
|
217
|
+
public class SendCreateOrder {
|
|
218
|
+
public static void main(String[] args) {
|
|
219
|
+
var client = new EventsClient(
|
|
220
|
+
System.getenv("ACME_API_KEY")
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
var command = Map.of(
|
|
224
|
+
"cartId", "d2b3c4e5-f6a7-4b8c-9d0e-1f2a3b4c5d6e",
|
|
225
|
+
"customerId", "8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e",
|
|
226
|
+
"items", List.of(
|
|
227
|
+
Map.of(
|
|
228
|
+
"productId", "7a0b4c3d-5e6f-4a7b-8c8d-9e0f1a2b3c4d",
|
|
229
|
+
"quantity", 1,
|
|
230
|
+
"unitPrice", 5799
|
|
231
|
+
)
|
|
232
|
+
),
|
|
233
|
+
"total", 5799,
|
|
234
|
+
"currency", "EUR"
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
client.send("CreateOrder", command);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
</CodeGroup>
|
|
243
|
+
|
|
244
|
+
</Column>
|
|
245
|
+
|
|
246
|
+
</Columns>
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Publish a customer-requested cancellation
|
|
6
|
+
|
|
7
|
+
The Order Service has handled a `CancelOrder` command from the customer's account page. It publishes this event so inventory, payments and fulfilment can undo their work.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `orderId` is the cancelled order.
|
|
12
|
+
- `customerId` is included, so notification services can send a cancellation email.
|
|
13
|
+
- `reason` is `CUSTOMER_REQUESTED`.
|
|
14
|
+
- `cancelledAt` is the ISO-8601 UTC time the cancellation was recorded.
|
|
15
|
+
|
|
16
|
+
### Using this example
|
|
17
|
+
|
|
18
|
+
Consumers should release the stock, void the payment authorisation and confirm the cancellation to the customer.
|
|
19
|
+
|
|
20
|
+
The examples use a **fictional Acme Events SDK** to publish a payload matching the OrderCancelled schema. The package names and publish methods are illustrative.
|
|
21
|
+
|
|
22
|
+
</Column>
|
|
23
|
+
|
|
24
|
+
<Column>
|
|
25
|
+
|
|
26
|
+
<CodeGroup dropdown>
|
|
27
|
+
|
|
28
|
+
```typescript publish-order-cancelled.ts
|
|
29
|
+
import { EventsClient } from '@acme/events';
|
|
30
|
+
import type { OrderCancelled } from './schemas/order-cancelled';
|
|
31
|
+
|
|
32
|
+
const client = new EventsClient({
|
|
33
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const event: OrderCancelled = {
|
|
37
|
+
orderId: 'e3f4a5b6-7c8d-4e9f-a0b1-c2d3e4f5a6b7',
|
|
38
|
+
customerId: '3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d',
|
|
39
|
+
reason: 'CUSTOMER_REQUESTED',
|
|
40
|
+
cancelledAt: '2026-09-12T20:10:05Z',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
await client.publish('OrderCancelled', event);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python publish_order_cancelled.py
|
|
47
|
+
import os
|
|
48
|
+
from acme_events import EventsClient
|
|
49
|
+
|
|
50
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
51
|
+
|
|
52
|
+
event = {
|
|
53
|
+
"orderId": "e3f4a5b6-7c8d-4e9f-a0b1-c2d3e4f5a6b7",
|
|
54
|
+
"customerId": "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
55
|
+
"reason": "CUSTOMER_REQUESTED",
|
|
56
|
+
"cancelledAt": "2026-09-12T20:10:05Z",
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
client.publish("OrderCancelled", event)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```java PublishOrderCancelled.java
|
|
63
|
+
import com.acme.events.EventsClient;
|
|
64
|
+
import java.util.Map;
|
|
65
|
+
|
|
66
|
+
public class PublishOrderCancelled {
|
|
67
|
+
public static void main(String[] args) {
|
|
68
|
+
var client = new EventsClient(
|
|
69
|
+
System.getenv("ACME_API_KEY")
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
var event = Map.of(
|
|
73
|
+
"orderId", "e3f4a5b6-7c8d-4e9f-a0b1-c2d3e4f5a6b7",
|
|
74
|
+
"customerId", "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
75
|
+
"reason", "CUSTOMER_REQUESTED",
|
|
76
|
+
"cancelledAt", "2026-09-12T20:10:05Z"
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
client.publish("OrderCancelled", event);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
</CodeGroup>
|
|
85
|
+
|
|
86
|
+
</Column>
|
|
87
|
+
|
|
88
|
+
</Columns>
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
<Columns cols={2}>
|
|
93
|
+
|
|
94
|
+
<Column>
|
|
95
|
+
|
|
96
|
+
## 2. Publish a cancellation after a payment failure
|
|
97
|
+
|
|
98
|
+
Capturing the payment failed after the order was created, so the Order Service cancels the order as compensation. The event carries only the required fields.
|
|
99
|
+
|
|
100
|
+
### Payload details
|
|
101
|
+
|
|
102
|
+
- `orderId` is the order that could not be paid for.
|
|
103
|
+
- `reason` is `PAYMENT_FAILED`.
|
|
104
|
+
- `customerId` is optional and omitted, so consumers must look the customer up by `orderId` if they need it.
|
|
105
|
+
- `cancelledAt` records when the compensation ran.
|
|
106
|
+
|
|
107
|
+
### Using this example
|
|
108
|
+
|
|
109
|
+
Use this to check that consumers handle an event without `customerId`, and that payment services do not try to refund money that was never taken.
|
|
110
|
+
|
|
111
|
+
The examples use a **fictional Acme Events SDK** to publish a payload matching the OrderCancelled schema. The package names and publish methods are illustrative.
|
|
112
|
+
|
|
113
|
+
</Column>
|
|
114
|
+
|
|
115
|
+
<Column>
|
|
116
|
+
|
|
117
|
+
<CodeGroup dropdown>
|
|
118
|
+
|
|
119
|
+
```typescript publish-order-cancelled.ts
|
|
120
|
+
import { EventsClient } from '@acme/events';
|
|
121
|
+
import type { OrderCancelled } from './schemas/order-cancelled';
|
|
122
|
+
|
|
123
|
+
const client = new EventsClient({
|
|
124
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const event: OrderCancelled = {
|
|
128
|
+
orderId: 'f4a5b6c7-8d9e-4f0a-b1c2-d3e4f5a6b7c8',
|
|
129
|
+
reason: 'PAYMENT_FAILED',
|
|
130
|
+
cancelledAt: '2026-09-15T09:02:17Z',
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
await client.publish('OrderCancelled', event);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```python publish_order_cancelled.py
|
|
137
|
+
import os
|
|
138
|
+
from acme_events import EventsClient
|
|
139
|
+
|
|
140
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
141
|
+
|
|
142
|
+
event = {
|
|
143
|
+
"orderId": "f4a5b6c7-8d9e-4f0a-b1c2-d3e4f5a6b7c8",
|
|
144
|
+
"reason": "PAYMENT_FAILED",
|
|
145
|
+
"cancelledAt": "2026-09-15T09:02:17Z",
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
client.publish("OrderCancelled", event)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
```java PublishOrderCancelled.java
|
|
152
|
+
import com.acme.events.EventsClient;
|
|
153
|
+
import java.util.Map;
|
|
154
|
+
|
|
155
|
+
public class PublishOrderCancelled {
|
|
156
|
+
public static void main(String[] args) {
|
|
157
|
+
var client = new EventsClient(
|
|
158
|
+
System.getenv("ACME_API_KEY")
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
var event = Map.of(
|
|
162
|
+
"orderId", "f4a5b6c7-8d9e-4f0a-b1c2-d3e4f5a6b7c8",
|
|
163
|
+
"reason", "PAYMENT_FAILED",
|
|
164
|
+
"cancelledAt", "2026-09-15T09:02:17Z"
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
client.publish("OrderCancelled", event);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
</CodeGroup>
|
|
173
|
+
|
|
174
|
+
</Column>
|
|
175
|
+
|
|
176
|
+
</Columns>
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
<Columns cols={2}>
|
|
181
|
+
|
|
182
|
+
<Column>
|
|
183
|
+
|
|
184
|
+
## 3. Publish a cancellation because stock ran out
|
|
185
|
+
|
|
186
|
+
The warehouse finds that the last units of a product are damaged and cannot fulfil the order. The Order Service cancels it and tells downstream systems why.
|
|
187
|
+
|
|
188
|
+
### Payload details
|
|
189
|
+
|
|
190
|
+
- `orderId` is the order that cannot be fulfilled.
|
|
191
|
+
- `customerId` is included so the customer can be told and offered an alternative.
|
|
192
|
+
- `reason` is `OUT_OF_STOCK`.
|
|
193
|
+
- `cancelledAt` is the ISO-8601 UTC time of the cancellation.
|
|
194
|
+
|
|
195
|
+
### Using this example
|
|
196
|
+
|
|
197
|
+
Consumers should void or refund the payment, and reporting should count this as a stock problem rather than a customer choice.
|
|
198
|
+
|
|
199
|
+
The examples use a **fictional Acme Events SDK** to publish a payload matching the OrderCancelled schema. The package names and publish methods are illustrative.
|
|
200
|
+
|
|
201
|
+
</Column>
|
|
202
|
+
|
|
203
|
+
<Column>
|
|
204
|
+
|
|
205
|
+
<CodeGroup dropdown>
|
|
206
|
+
|
|
207
|
+
```typescript publish-order-cancelled.ts
|
|
208
|
+
import { EventsClient } from '@acme/events';
|
|
209
|
+
import type { OrderCancelled } from './schemas/order-cancelled';
|
|
210
|
+
|
|
211
|
+
const client = new EventsClient({
|
|
212
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const event: OrderCancelled = {
|
|
216
|
+
orderId: '1b2c3d4e-5f6a-4b7c-9d8e-0f1a2b3c4d5e',
|
|
217
|
+
customerId: '8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e',
|
|
218
|
+
reason: 'OUT_OF_STOCK',
|
|
219
|
+
cancelledAt: '2026-09-16T13:36:50Z',
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
await client.publish('OrderCancelled', event);
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
```python publish_order_cancelled.py
|
|
226
|
+
import os
|
|
227
|
+
from acme_events import EventsClient
|
|
228
|
+
|
|
229
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
230
|
+
|
|
231
|
+
event = {
|
|
232
|
+
"orderId": "1b2c3d4e-5f6a-4b7c-9d8e-0f1a2b3c4d5e",
|
|
233
|
+
"customerId": "8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e",
|
|
234
|
+
"reason": "OUT_OF_STOCK",
|
|
235
|
+
"cancelledAt": "2026-09-16T13:36:50Z",
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
client.publish("OrderCancelled", event)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
```java PublishOrderCancelled.java
|
|
242
|
+
import com.acme.events.EventsClient;
|
|
243
|
+
import java.util.Map;
|
|
244
|
+
|
|
245
|
+
public class PublishOrderCancelled {
|
|
246
|
+
public static void main(String[] args) {
|
|
247
|
+
var client = new EventsClient(
|
|
248
|
+
System.getenv("ACME_API_KEY")
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
var event = Map.of(
|
|
252
|
+
"orderId", "1b2c3d4e-5f6a-4b7c-9d8e-0f1a2b3c4d5e",
|
|
253
|
+
"customerId", "8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e",
|
|
254
|
+
"reason", "OUT_OF_STOCK",
|
|
255
|
+
"cancelledAt", "2026-09-16T13:36:50Z"
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
client.publish("OrderCancelled", event);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
</CodeGroup>
|
|
264
|
+
|
|
265
|
+
</Column>
|
|
266
|
+
|
|
267
|
+
</Columns>
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<Columns cols={2}>
|
|
2
|
+
|
|
3
|
+
<Column>
|
|
4
|
+
|
|
5
|
+
## 1. Publish completion of a UK order
|
|
6
|
+
|
|
7
|
+
The T-shirts and cap from a UK order are delivered two days after purchase. The Order Service publishes this event to mark the end of the order's happy path.
|
|
8
|
+
|
|
9
|
+
### Payload details
|
|
10
|
+
|
|
11
|
+
- `orderId` is the order that was fulfilled.
|
|
12
|
+
- `customerId` identifies the customer, so they can be asked for a review.
|
|
13
|
+
- `completedAt` is the ISO-8601 UTC time the delivery was confirmed.
|
|
14
|
+
|
|
15
|
+
### Using this example
|
|
16
|
+
|
|
17
|
+
Consumers should close out fulfilment, capture the payment and move the order to completed in reporting.
|
|
18
|
+
|
|
19
|
+
The examples use a **fictional Acme Events SDK** to publish a payload matching the OrderCompleted schema. The package names and publish methods are illustrative.
|
|
20
|
+
|
|
21
|
+
</Column>
|
|
22
|
+
|
|
23
|
+
<Column>
|
|
24
|
+
|
|
25
|
+
<CodeGroup dropdown>
|
|
26
|
+
|
|
27
|
+
```typescript publish-order-completed.ts
|
|
28
|
+
import { EventsClient } from '@acme/events';
|
|
29
|
+
import type { OrderCompleted } from './schemas/order-completed';
|
|
30
|
+
|
|
31
|
+
const client = new EventsClient({
|
|
32
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const event: OrderCompleted = {
|
|
36
|
+
orderId: '4c7e9a2b-1d3f-4b5a-8e6c-2f9d0a1b3c5e',
|
|
37
|
+
customerId: '3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d',
|
|
38
|
+
completedAt: '2026-09-13T14:27:09Z',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
await client.publish('OrderCompleted', event);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```python publish_order_completed.py
|
|
45
|
+
import os
|
|
46
|
+
from acme_events import EventsClient
|
|
47
|
+
|
|
48
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
49
|
+
|
|
50
|
+
event = {
|
|
51
|
+
"orderId": "4c7e9a2b-1d3f-4b5a-8e6c-2f9d0a1b3c5e",
|
|
52
|
+
"customerId": "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
53
|
+
"completedAt": "2026-09-13T14:27:09Z",
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
client.publish("OrderCompleted", event)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```java PublishOrderCompleted.java
|
|
60
|
+
import com.acme.events.EventsClient;
|
|
61
|
+
import java.util.Map;
|
|
62
|
+
|
|
63
|
+
public class PublishOrderCompleted {
|
|
64
|
+
public static void main(String[] args) {
|
|
65
|
+
var client = new EventsClient(
|
|
66
|
+
System.getenv("ACME_API_KEY")
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
var event = Map.of(
|
|
70
|
+
"orderId", "4c7e9a2b-1d3f-4b5a-8e6c-2f9d0a1b3c5e",
|
|
71
|
+
"customerId", "3f2b8c1e-7a4d-4e9b-9c6f-1d2e3a4b5c6d",
|
|
72
|
+
"completedAt", "2026-09-13T14:27:09Z"
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
client.publish("OrderCompleted", event);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
</CodeGroup>
|
|
81
|
+
|
|
82
|
+
</Column>
|
|
83
|
+
|
|
84
|
+
</Columns>
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
<Columns cols={2}>
|
|
89
|
+
|
|
90
|
+
<Column>
|
|
91
|
+
|
|
92
|
+
## 2. Publish completion of an international order
|
|
93
|
+
|
|
94
|
+
A hoodie shipped to Ireland takes five days to arrive. When the carrier confirms delivery, the Order Service publishes this event.
|
|
95
|
+
|
|
96
|
+
### Payload details
|
|
97
|
+
|
|
98
|
+
- `orderId` is the euro order created on 14 September.
|
|
99
|
+
- `customerId` identifies the customer in Ireland.
|
|
100
|
+
- `completedAt` is five days after the order was created, which reporting can use to track international delivery times.
|
|
101
|
+
|
|
102
|
+
### Using this example
|
|
103
|
+
|
|
104
|
+
Use this to check that consumers work out delivery time from the order's creation time and `completedAt`, whatever the currency or destination.
|
|
105
|
+
|
|
106
|
+
The examples use a **fictional Acme Events SDK** to publish a payload matching the OrderCompleted schema. The package names and publish methods are illustrative.
|
|
107
|
+
|
|
108
|
+
</Column>
|
|
109
|
+
|
|
110
|
+
<Column>
|
|
111
|
+
|
|
112
|
+
<CodeGroup dropdown>
|
|
113
|
+
|
|
114
|
+
```typescript publish-order-completed.ts
|
|
115
|
+
import { EventsClient } from '@acme/events';
|
|
116
|
+
import type { OrderCompleted } from './schemas/order-completed';
|
|
117
|
+
|
|
118
|
+
const client = new EventsClient({
|
|
119
|
+
apiKey: process.env.ACME_API_KEY!,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const event: OrderCompleted = {
|
|
123
|
+
orderId: 'b5d8e1f2-6a3c-4d7b-9f0e-3a4b5c6d7e8f',
|
|
124
|
+
customerId: '8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e',
|
|
125
|
+
completedAt: '2026-09-19T11:48:32Z',
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
await client.publish('OrderCompleted', event);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```python publish_order_completed.py
|
|
132
|
+
import os
|
|
133
|
+
from acme_events import EventsClient
|
|
134
|
+
|
|
135
|
+
client = EventsClient(api_key=os.environ["ACME_API_KEY"])
|
|
136
|
+
|
|
137
|
+
event = {
|
|
138
|
+
"orderId": "b5d8e1f2-6a3c-4d7b-9f0e-3a4b5c6d7e8f",
|
|
139
|
+
"customerId": "8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e",
|
|
140
|
+
"completedAt": "2026-09-19T11:48:32Z",
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
client.publish("OrderCompleted", event)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```java PublishOrderCompleted.java
|
|
147
|
+
import com.acme.events.EventsClient;
|
|
148
|
+
import java.util.Map;
|
|
149
|
+
|
|
150
|
+
public class PublishOrderCompleted {
|
|
151
|
+
public static void main(String[] args) {
|
|
152
|
+
var client = new EventsClient(
|
|
153
|
+
System.getenv("ACME_API_KEY")
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
var event = Map.of(
|
|
157
|
+
"orderId", "b5d8e1f2-6a3c-4d7b-9f0e-3a4b5c6d7e8f",
|
|
158
|
+
"customerId", "8a7c6e5d-2b1f-4c3a-9e8d-7f6a5b4c3d2e",
|
|
159
|
+
"completedAt", "2026-09-19T11:48:32Z"
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
client.publish("OrderCompleted", event);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
</CodeGroup>
|
|
168
|
+
|
|
169
|
+
</Column>
|
|
170
|
+
|
|
171
|
+
</Columns>
|