Skip to content

Commit 00c006f

Browse files
committed
docs: embed the rendered class diagram in the event-carried state transfer README
Render etc/event-carried-state-transfer.urm.puml to PNG and embed it in the detailed explanation section, matching the other modules, instead of the inline mermaid block. The producer and consumer snippets now show the plain long sequence counters the code uses.
1 parent 5bd0fd4 commit 00c006f

2 files changed

Lines changed: 4 additions & 77 deletions

File tree

‎event-carried-state-transfer/README.md‎

Lines changed: 4 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ sequenceDiagram
5757
OS->>R: apply (version 1 <= 2, ignored)
5858
```
5959

60+
![Event-Carried State Transfer class diagram](./etc/event-carried-state-transfer.urm.png)
61+
6062
## Programmatic Example of Event-Carried State Transfer Pattern in Java
6163

6264
The example has a producer, a channel and a consumer. The producer is the customer service, the channel is a tiny in-memory event bus and the consumer is the order service with its local customer replica.
@@ -116,7 +118,7 @@ public CustomerState changeShippingAddress(String customerId, String newAddress)
116118

117119
private CustomerState store(CustomerState state) {
118120
customers.put(state.customerId(), state);
119-
var event = new CustomerUpdatedEvent(eventSequence.incrementAndGet(), Instant.now(), state);
121+
var event = new CustomerUpdatedEvent(++eventSequence, Instant.now(), state);
120122
bus.publish(event);
121123
return state;
122124
}
@@ -166,7 +168,7 @@ public Order placeOrder(String customerId, BigDecimal amount) {
166168
"Amount " + amount + " exceeds credit limit " + customer.creditLimit() + " of " + customerId);
167169
}
168170
return new Order(
169-
"ORD-" + orderSequence.incrementAndGet(), customerId, customer.shippingAddress(), amount);
171+
"ORD-" + ++orderSequence, customerId, customer.shippingAddress(), amount);
170172
}
171173
```
172174

@@ -232,81 +234,6 @@ INFO OrderService -- Accepted ORD-2 for C-1 (900.00) shipping to '42 Ocean Avenu
232234
INFO App -- Order ORD-2 accepted
233235
```
234236

235-
## Class Diagram
236-
237-
```mermaid
238-
classDiagram
239-
class CustomerState {
240-
+String customerId
241-
+String name
242-
+String shippingAddress
243-
+BigDecimal creditLimit
244-
+long version
245-
+withShippingAddress(newAddress) CustomerState
246-
+withCreditLimit(newLimit) CustomerState
247-
}
248-
class CustomerUpdatedEvent {
249-
+long eventId
250-
+Instant occurredAt
251-
+CustomerState state
252-
}
253-
class EventListener~E~ {
254-
<<interface>>
255-
+onEvent(event) void
256-
}
257-
class EventBus {
258-
-Map~Class, List~ listeners
259-
+subscribe(eventType, listener) void
260-
+publish(event) void
261-
}
262-
class CustomerService {
263-
-Map~String, CustomerState~ customers
264-
-EventBus bus
265-
-long eventSequence
266-
-boolean online
267-
+register(customerId, name, shippingAddress, creditLimit) CustomerState
268-
+changeShippingAddress(customerId, newAddress) CustomerState
269-
+changeCreditLimit(customerId, newLimit) CustomerState
270-
+findCustomer(customerId) Optional~CustomerState~
271-
+shutdown() void
272-
+isOnline() boolean
273-
}
274-
class CustomerReplica {
275-
-Map~String, CustomerState~ customers
276-
+apply(event) boolean
277-
+find(customerId) Optional~CustomerState~
278-
+size() int
279-
}
280-
class OrderService {
281-
-CustomerReplica replica
282-
-long orderSequence
283-
+placeOrder(customerId, amount) Order
284-
+replica() CustomerReplica
285-
}
286-
class Order {
287-
+String orderId
288-
+String customerId
289-
+String shippingAddress
290-
+BigDecimal amount
291-
}
292-
class OrderRejectedException {
293-
+OrderRejectedException(message)
294-
}
295-
296-
CustomerUpdatedEvent --> CustomerState
297-
EventBus "1" --> "*" EventListener
298-
CustomerService --> EventBus
299-
CustomerService "1" --> "*" CustomerState
300-
CustomerService ..> CustomerUpdatedEvent : publishes
301-
CustomerReplica "1" --> "*" CustomerState
302-
CustomerReplica ..> CustomerUpdatedEvent : applies
303-
OrderService --> CustomerReplica
304-
OrderService ..> EventListener : adapts the replica
305-
OrderService ..> EventBus : subscribes
306-
OrderService ..> Order : creates
307-
OrderService ..> OrderRejectedException : throws
308-
```
309-
310237
## When to Use the Event-Carried State Transfer Pattern in Java
311238

312239
* Consumers need data owned by another service on every request and a synchronous call would add latency, load, or a hard availability dependency.
111 KB
Loading

0 commit comments

Comments
 (0)