Download - Cреда разработки #1 - EDA in JS
Среда Разработки в IBM
Intro to Event-Driven Design with JavaScript
Agenda
●Basics and EDA intro
● Foreplay Basic knowledge about functions in JavaScript
●Code writing
The three styles of interaction
Type of interaction Initiator Participants
Time-driven Time The specified system
Request-driven Client Client and Server
Event-driven Event Open-ended
Time driven
Fruit system
run inventory check every 60 mins
Request driven
Tarzan Fruit systemMe want three banans!
Event driven
Fruit system “Tarzan took
three bananas”
“Fruit system is low on
bananas”
5 Principles of EDA
●“Real-time” events as they happen at the producer
●Push notifications
●One-way “fire-and-forget”
●Immediate action at the consumers
●Informational (“someone logged in”), not commands (“audit this”)
Typical EDA architecture
system system system
system system system
Event Bus
Event Poducer
Event Transport
Event Consumers
Main benefits of EDA
●Better service (no batch, less waiting)
●No point-to-point integration (fire & forget)
●High performance, highly scalable systems
The birth of system
Inventory
Customer
Shop
The monolith
Inventory
Customer
Shop
NewsletterReporting
Payment
SOA architecture
Shop Payment
Newsletter
Inventory
Customer Reporting
Divide the problem domains into separate systems
SOA architecture
Shop Payment
Newsletter
Inventory
Customer Reporting
A lot of point to point integration...
SOA + EDA =
Shop Payment
Newsletter
Inventory
Customer Reporting
Event Bus 3th system
Core
[Observer’s minimum]
1.Publisher
2.Message
3.Subscriber
4.Emitter
5.*Topics
Simple EDD implementation
MESSAGE
MESSAGE
MESSAGE
Simple Example
EmitterPublisher
Subscriber
Subscriber
Publisher/Subscriber
MESSAGE
JS Functions
Context. This.var typicalAmerican = { firstName: “John”, lastName: “Smith”, sayYourName: function(){ return "My name is " + this.firstName + ‘ ’ + this.lastName; }}
typicalAmerican.sayYourName(); //My name is John Smith
Context. This.var typicalAmerican = { firstName: “John”, lastName: “Smith”, sayYourName: function(){ return "My name is " + this.firstName + ‘ ’ + this.lastName; }}
var typicalAmericansName = typicalAmerican.sayYourName;
typicalAmericansName(); //My name is undefined undefined
typicalAmericansName.call({firstName: “Rud”, lastName: “Man”}); //My name is Rud Man
Function#call(context)
JS Functions
JS Functions
Context. This.var typicalAmerican = { firstName: “John”, lastName: “Smith”, sayYourName: function(middleName){ return "My name is " + this.firstName + ‘ ’ + middleName + ' ' + this.lastName; return ['My name is', this.firstName, middleName, this.lastName].join(' '); }}
var typicalAmericansName = typicalAmerican.sayYourName;typicalAmericansName.call({firstName: “Rud”, lastName: “Man”}, “Arm”); //My name is Rud Arm Man
Use the join, Luke
Function#call(context[, arg1[, arg2...]])
JS Functions
Argumentsfunction Point(x, y){ this.coords = [x, y]; this.distanceTo = function(x, y){ var sqrt = Math.sqrt abs = Math.abs, point=[x, y]; return sqrt(sqrt(abs(this.coords[0] - point[0])) + sqrt(abs(this.coords[1] - point[1]))); }}
var point = new Point(0, 0);point.distanceTo(1,1); //1.41...
JS Functions
what about multiplay arguments?function Point(x, y, ...){}
function Point(){ this.coords = arguments; // arguments == [x, y, ...] this.distanceTo = function(){ var sqrt = Math.sqrt abs = Math.abs, res = 0, point = arguments; for(var i=0, len=coords.length; i<len; ++i){ res += sqrt(abs(this.coords[i] - point[i])); } return sqrt(res); }}
var point = new Point(1, 1);point.distanceTo(0, 0); //1.41..
Time to coding!
Links
Mediator pattern - http://largescalejs.ru/the-mediator-pattern/(how to remove subscription see in comments ;)
Context in JS (this, #call and #apply) - https://learn.javascript.ru/call-apply
Event Driven Architecture by Stefan Norberg on SlideShare - http://www.slideshare.net/stnor/event-driven-architecture-3395407