Skip to content

Commit 5280cd0

Browse files
committed
Review changes for demo (without reorder)
1 parent 9521ee3 commit 5280cd0

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

documentation/modules/ROOT/pages/02-architecture.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ The event-driven flow enables eventual consistent collaboration and state synchr
8888

8989
A usual flow may look like:
9090

91-
1. An end-user application sends an _HTTP_ request to the _Event Mesh_. Such message can be understood as a _Command_ type event.
91+
1. An end-user application sends an _HTTP_ request to the _Event Mesh_.
92+
Such message can be understood as a _Command_ type event.
9293
2. The _Event Mesh_ (Broker) persists the event in a queue (like an Apache Kafka topic, but the implementation is hidden from the user).
9394
After _Event Mesh_ persists safely the data, it returns a successful _HTTP_ response with the `202 Accepted` return code.
9495
At this point, the operation could already be considered successful, from the end-user point of view.
@@ -155,7 +156,7 @@ The _Event Mesh_ pushes the events as _CloudEvents_ encoded as _REST_ messages.
155156
The exponential backoff algorithm used by _Event Mesh_ is configurable.
156157
It uses the following formula to calculate the backoff period: `+backoffDelay * 2^<numberOfRetries>+`, where the backoff delay is a base number of seconds, and number of retries is automatically tracked by the _Event Mesh_.
157158
158-
A dead letter sink can also be configured to send events in case they exceed the maximum retry number, which is also configurable.
159+
A dead letter sink can also be configured to send events in case they exceed the maximum retry number, which is also configurable.
159160
====
160161

161162
=== _Work Ledger_ analogy

documentation/modules/ROOT/pages/03-demo.adoc

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
== Demonstration
99

1010
Let's take a look at the following example.
11-
We'll be looking at a Cabs ride-sharing application, that mimics real-world solutions of similar kind.
11+
We'll be looking at a Cabs ride-sharing application, that resembles real-world solutions of similar kind.
1212
The application is written in a popular Java framework.
1313

1414
=== Initial application
@@ -31,18 +31,19 @@ public void completeTransit(Long driverId, UUID requestUUID, Address destination
3131
}
3232
Address from = addressRepository.getByHash(transitDetails.from.getHash());
3333
Address to = addressRepository.getByHash(destinationAddress.getHash());
34+
3435
Money finalPrice = completeTransitService.completeTransit(
3536
driverId, requestUUID, from, to); // <2>
36-
Money driverFee = driverFeeService.calculateDriverFee(
37-
finalPrice, driverId);
37+
Money driverFee = driverFeeService.calculateDriverFee(finalPrice, driverId);
3838
driverService.markNotOccupied(driverId); // <2>
39-
transitDetailsFacade.transitCompleted(requestUUID,
40-
Instant.now(clock), finalPrice, driverFee); // <2>
41-
awardsService.registerMiles(transitDetails.client.getId(),
42-
transitDetails.transitId); // <2>
39+
40+
transitDetailsFacade.transitCompleted(requestUUID, Instant.now(clock),
41+
finalPrice, driverFee); // <2>
42+
awardsService.registerMiles(transitDetails.client.getId(), transitDetails.transitId); // <2>
4343
invoiceGenerator.generate(finalPrice.toInt(),
4444
transitDetails.client.getName() + " " +
4545
transitDetails.client.getLastName()); // <2>
46+
4647
eventsEventSender.publish(new TransitCompleted(
4748
transitDetails.client.getId(), transitDetails.transitId,
4849
transitDetails.from.getHash(), destinationAddress.getHash(),
@@ -112,19 +113,22 @@ The entrypoint is the _Cloud Event_ of type `cabs.drivers.calculate-fee` we are
112113
----
113114
impl Service {
114115
pub async fn calculate_fee(&mut self, ce: Event) -> Result<()> {
115-
let fee_event = Self::parse_fee_event(ce)?; // <1>
116-
let subject = fee_event.id.clone();
116+
let calc_fee_intent = Self::unwrap_calculatefee(ce)?; // <1>
117+
let subject = calc_fee_intent.id.clone();
118+
119+
log::debug!("calculate fee for: {:?}", calc_fee_intent);
120+
let drv = self.repo.get(&calc_fee_intent.entity.driver_id).await?;
117121
118-
let drv = self.repo.get(&fee_event.entity.driver_id).await?;
122+
let fee = drv.calculate_fee(&calc_fee_intent.entity.transit_price); // <2>
119123
120-
let fee = drv.calculate_fee(&fee_event.entity.transit_price); // <2>
124+
log::debug!("fee value: {:?}", fee);
121125
122-
let fee_event = DriverFeeEvent {
123-
driver_id: fee_event.entity.driver_id,
126+
let driverfee_event = DriverFeeEvent {
127+
driver_id: calc_fee_intent.entity.driver_id,
124128
fee,
125129
}; // <3>
126130
127-
let mut builder = fee_event.to_builder(); // <3>
131+
let mut builder = driverfee_event.to_builder(); // <3>
128132
if let Some(id) = subject {
129133
builder = builder.subject(id);
130134
} // <3>
@@ -140,10 +144,10 @@ impl Service {
140144

141145
In the above code, we are doing the following:
142146

143-
<1> We are parsing the internal, business logic, fee event from the _Cloud Events_ envelope.
144-
<2> We are calculating the fee for this event, using some business logic.
145-
<3> We are wrapping the calculated fee into the _Cloud Events_ envelope.
146-
<4> We are sending the fee back to the _Event Mesh_ using _HTTP REST_ client.
147+
<1> We are unwrapping _Cloud Event_ envelope into an internal, domain, fee value object.
148+
<2> We are calculating the fee value using some domain logic.
149+
<3> We are wrapping the calculated fee value into a new _Cloud Event_.
150+
<4> We are sending the fee, as _Cloud Event_, back to the _Event Mesh_ using _HTTP REST_ client.
147151

148152
Of course, in order for this method to be called, we need to route the event from the HTTP listener:
149153

@@ -238,13 +242,13 @@ spec:
238242

239243
[IMPORTANT]
240244
====
241-
The policy is `+exponential+`, and the `+retry+` is 10, which means that after approximately 6 min and 50 sec the event will be dropped.
245+
In our example, the policy is `+exponential+`, and the `+retry+` is 10, which means that after approximately 6 min and 50 sec the event will be dropped (or routed to the `+deadLetterSink+` if configured).
242246
====
243247

244248
[NOTE]
245249
====
246250
A `+deadLetterSink+` option could be configured for the _Broker_ to send the events that failed to be delivered in time to a back-up location.
247-
Events captured in a back-up location can be re-transmitted into the _Event Mesh_ later.
251+
Events captured in a back-up location can be re-transmitted into the _Event Mesh_ later by reconfiguring the _Mesh_ (after resolving the outage or deploying a bug fix).
248252
====
249253

250254
==== Legacy application changes
@@ -276,12 +280,12 @@ public void driverFeeCalculated(DriverFee driverFee) { // <3>
276280
====
277281
<1> Notice, we are just invoking the `+calculateDriverFee+`, that doesn't return anything.
278282
It's asynchronous.
279-
<2> We are using the `@EventListener` annotation to listen for the business events withing the applition.
283+
<2> We are using the `@EventListener` annotation to listen for the domain events within the application.
280284
Don't confuse this with _Cloud Events_ that are sent and received outside the application.
281285
<3> The exact fee is calculated by the _Drivers_ module, and we'll be notified later, with the `+driverFeeCalculated+` method.
282286
====
283287

284-
To make it work, we need to add a new _Cloud Event_ sender and listener.
288+
To communicate with the _Event Mesh_, we need to add a new _Cloud Event_ sender and listener.
285289
That's being done similarly, as in the case of _Rust_ application.
286290

287291
Below, you can see how you may implement the _Cloud Event_ sender:
@@ -391,13 +395,13 @@ public class CloudEventReceiver {
391395
}
392396
----
393397

394-
<1> We unwrap the _CloudEvent_ into our custom event type
398+
<1> We unwrap the _CloudEvent_ into our domain event type (in the example that's the `+DriverFeeCalculated+` type)
395399
<2> And publish it withing the application, using the framework's _EventsPublisher_ implementation.
396-
The event will be transmitted to the methods annotated with `@EventListener`.
400+
The domain events will be transmitted to the methods annotated with `@EventListener`.
397401

398402
[CAUTION]
399403
====
400-
Don't confuse the the framework's _EventsPublisher_ with _Cloud Event_ sender and receiver.
404+
Don't confuse the framework's _EventsPublisher_ with _Cloud Event_ sender and receiver.
401405
====
402406

403407
==== The wiring of our _Event Mesh_
@@ -765,7 +769,8 @@ The OpenShift Container Platform provides can provide a clear visualization of o
765769
image::solution-odc.png[width=100%]
766770

767771
The console shows two sink bindings on the left, and they are feeding the events from the applications to the _Broker_ (depicted in the center).
768-
on the right, you could see the two applications deployed as _Knative_ services, and two triggers (as lines) that configure the _Event Mesh_ to feed appropriate events to the applications.
772+
The _Broker_ is the centralized infrastructure piece that ensures a proper decoupling of the services.
773+
On the right, you could see the two applications deployed as _Knative_ services, and two triggers (as lines) that configure the _Event Mesh_ to feed appropriate events to the applications.
769774

770775
=== Walkthrough guide
771776

documentation/modules/ROOT/pages/developer-resources.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
== Developer Resources
88

9-
* https://github.com/cardil/cabs-usvc[Demo Source] _(The example code used in this solution)_
10-
* https://youtu.be/Rc5IO6S6ZOk[youtu.be / Rc5IO6S6ZOk] _(The talk that served a base for this solution)_
9+
* https://github.com/cardil/cabs-usvc[Demo source code] &mdash; _The example code used in this solution, based on the https://github.com/legacyfighter/cabs-java[LegacyFighter Java app]_
10+
* https://youtu.be/Rc5IO6S6ZOk[Let's get meshy! Microservices are easy with Event Mesh] &mdash; _The talk that served a base for this solution_
1111
* https://www.redhat.com/en/technologies/cloud-computing/openshift/serverless[Red Hat OpenShift Serverless]
1212
* https://knative.dev/docs/eventing/event-mesh/[Knative Event Mesh]
1313
* https://bit.ly/knative-tutorial[Knative Tutorial]

0 commit comments

Comments
 (0)