You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 1cb094e
Browse filesBrowse the repository at this point in the historyBrowse files
fix: align the event bus contract with the code and extend the demo
publish rejects null, exact-class dispatch is documented, the sequence counters are plain longs, and the demo shows a credit limit change flowing through the replica. The class diagram is a rendered PNG.
Copy file name to clipboardExpand all lines: event-carried-state-transfer/README.md
+18-7Lines changed: 18 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,8 @@ sequenceDiagram
57
57
OS->>R: apply (version 1 <= 2, ignored)
58
58
```
59
59
60
+

61
+
60
62
## Programmatic Example of Event-Carried State Transfer Pattern in Java
61
63
62
64
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)
116
118
117
119
privateCustomerState store(CustomerState state) {
118
120
customers.put(state.customerId(), state);
119
-
var event =newCustomerUpdatedEvent(eventSequence.incrementAndGet(), Instant.now(), state);
121
+
var event =newCustomerUpdatedEvent(++eventSequence, Instant.now(), state);
120
122
bus.publish(event);
121
123
return state;
122
124
}
@@ -166,13 +168,13 @@ public Order placeOrder(String customerId, BigDecimal amount) {
`App` registers a customer and changes the address, takes the customer service offline and places an order from the replica, publishes a stale event that the replica ignores, and finally shows the replica enforcing the credit limit.
177
+
`App` registers a customer and changes the address, takes the customer service offline and places an order from the replica, publishes a stale event that the replica ignores, and shows the replica enforcing the credit limit. It then brings the customer service back and raises that limit: the new limit travels inside the event, and the order that was just rejected is accepted from the replica alone, without a single call back to the producer.
176
178
177
179
```java
178
180
var bus =newEventBus();
@@ -188,6 +190,10 @@ var order = orderService.placeOrder("C-1", new BigDecimal("120.00")); // succeed
Copy file name to clipboardExpand all lines: event-carried-state-transfer/src/test/java/com/iluwatar/eventcarriedstatetransfer/CustomerServiceTest.java
0 commit comments