The document discusses reactive APIs and microservices architectures. It introduces the concept of reactive systems as being responsive, resilient, elastic, and message-driven. It then discusses some issues with using RPC-style APIs between microservices, such as fragility and data silos. As an alternative, it presents the concept of reactive technologies like message-based communication using protocols like the Muon reactive streams protocol. It also discusses using event logs and streaming data between services using this approach. Finally, it gives examples of implementing domain-driven design patterns on top of a reactive event log API using the Newton library.
78. Reactive: Technical Interaction Models?
Reactive
API
"I want to trade X for Y"
"I offer 10*Y in 2 minutes, or Z now"
"I'll take 10Y"
79. Reactive: Technical Interaction Models?
Reactive
API
"I want to trade X for Y"
"I offer 10*Y in 2 minutes, or Z now"
"I'll take 10Y"
"Here is Y"
80. Reactive: Technical Interaction Models?
Reactive
API
"I want to trade X for Y"
"I offer 10*Y in 2 minutes, or Z now"
"I'll take 10Y"
"Here is Y"
"Here is Y"
"Here is Y"
81. Reactive: Technical Interaction Models?
Reactive
API
"I want to trade X for Y"
"I offer 10*Y in 2 minutes, or Z now"
"I'll take 10Y"
"Here is Y"
"Here is Y"
"Here is Y"
"Slow down"
82. Reactive: Technical Interaction Models?
Reactive
API
"I want to trade X for Y"
"I offer 10*Y in 2 minutes, or Z now"
"I'll take 10Y"
"Here is Y"
"Here is Y"
"Here is Y"
"Slow down"
.....
86. Reactive: Technical Interaction Models?
Reactive
API
"I want to trade X for Y"
"I offer 10*Y in 2 minutes, or Z now"
"I'll take 10Y"
"Here is Y"
"Here is Y"
"Here is Y"
"Slow down"
.....
105. The Muon Model
Discovery
Transport
Network
….
Protocol
Client
channel N
channel
channel channel Service X
Service 2
Service 1
API
App Code
….
1) Your code
uses an API
2) The API
creates a
Protocol
3) The Protocol
communicates
using
messages
4) A transport
routes them over
the network
106. The Muon Model
Discovery
Transport
Network
….
Protocol
Client
channel N
channel
channel channel Service X
Service 2
Service 1
API
App Code
….
1) Your code
uses an API
2) The API
creates a
Protocol
3) The Protocol
communicates
using
messages
4) A transport
routes them over
the network
107. The Muon Model
Discovery
Transport
Network
….
Protocol
Client
channel N
channel
channel channel Service X
Service 2
Service 1
API
App Code
….
1) Your code
uses an API
2) The API
creates a
Protocol
3) The Protocol
communicates
using
messages
4) A transport
routes them over
the network
108. The Muon Model
Discovery
Transport
Network
….
Protocol
Client
channel N
channel
channel channel Service X
Service 2
Service 1
API
App Code
….
1) Your code
uses an API
2) The API
creates a
Protocol
3) The Protocol
communicates
using
messages
4) A transport
routes them over
the network
137. The Muon Model
Discovery
Transport
Network
….
Protocol
Client
channel N
channel
channel channel Service X
Service 2
Service 1
API
App Code
….
1) Your code
uses an API
2) The API
creates a
Protocol
3) The Protocol
communicates
using
messages
4) A transport
routes them over
the network
138. Muon Event Log API
A Message based API
http://github.com/muoncore/stack-events
139. Java Client
Muon muon = getMuon();
EventClient client = new DefaultEventClient(muon);
Order order = ...
client.event(
ClientEvent.ofType("OrderPlaced")
.payload(order)
.stream("/orders").build())
Muon Event Log API
140. Java Client
Muon muon = getMuon();
EventClient client = new DefaultEventClient(muon);
Subscriber<Event> s = … (RxJava, Reactor etc)
client.replay("/requests", REPLAY_ONLY, s);
Muon Event Log API
144. Aggregate RootsAggregate Roots
Part of the C in CQRS
Transactional Components
A Web of Objects, loaded as a Unit
Machines to turn Commands into Events
145. User: 1
Aggregate RootsAggregate Roots
Events
UserCreated
UserNameUpdated
UserActivated
Stream contains events for a single
User/ entity
146. Aggregate RootsAggregate Roots
class User extends AggregateRoot<String> {
private String email;
private boolean active;
private String id;
User(String email) {
raiseEvent(new UserCreated(email));
}
public void activateAccount() { raiseEvent(new UserRegistrationConfirmed(id)); }
public void delete() { raiseEvent(new UserDeleted(id)); }
@EventHandler
public void on(UserCreated ev) {
id = ev.getId();
Email = ev.getEmail();
}
@EventHandler
public void on(UserRegistrationConfirmed ev) {
active = true
}
}
147. Aggregate RootsAggregate Roots
class User extends AggregateRoot<String> {
private String email;
private boolean active;
private String id;
User(String email) {
raiseEvent(new UserCreated(email));
}
public void activateAccount() { raiseEvent(new UserRegistrationConfirmed(id)); }
public void delete() { raiseEvent(new UserDeleted(id)); }
@EventHandler
public void on(UserCreated ev) {
id = ev.getId();
Email = ev.getEmail();
}
@EventHandler
public void on(UserRegistrationConfirmed ev) {
active = true
}
}
148. Aggregate RootsAggregate Roots
class User extends AggregateRoot<String> {
private String email;
private boolean active;
private String id;
User(String email) {
raiseEvent(new UserCreated(email));
}
public void activateAccount() { raiseEvent(new UserRegistrationConfirmed(id)); }
public void delete() { raiseEvent(new UserDeleted(id)); }
@EventHandler
public void on(UserCreated ev) {
id = ev.getId();
Email = ev.getEmail();
}
@EventHandler
public void on(UserRegistrationConfirmed ev) {
active = true
}
}
157. Thoughts
Uses Muon Event Log API.
All Muon implementations can
contribute/ consume data (jvm, node, browser etc)
158. Thoughts
Uses Muon Event Log API.
All Muon implementations can
contribute/ consume data (jvm, node, browser etc)
Runs on any event store
that implements the Muon Event Log API
162. There's more...
More types of API available ...
Multiple transports available
me@daviddawson.me http://muoncore.io
163. There's more...
More types of API available ...
Multiple transports available
Any infrastructure you like!
me@daviddawson.me http://muoncore.io
164. There's more...
More types of API available ...
Multiple transports available
Any infrastructure you like!
Want to extend/ contribute? Join us at
me@daviddawson.me http://muoncore.io