cреда разработки #1 - eda in js

23
Среда Разработки в IBM Intro to Event-Driven Design with JavaScript

Upload: rudolf-manusadzhyan

Post on 12-Apr-2017

243 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Cреда разработки #1 - EDA in JS

Среда Разработки в IBM

Intro to Event-Driven Design with JavaScript

Page 2: Cреда разработки #1 - EDA in JS

Agenda

●Basics and EDA intro

● Foreplay Basic knowledge about functions in JavaScript

●Code writing

Page 3: Cреда разработки #1 - EDA in JS

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

Page 4: Cреда разработки #1 - EDA in JS

Time driven

Fruit system

run inventory check every 60 mins

Page 5: Cреда разработки #1 - EDA in JS

Request driven

Tarzan Fruit systemMe want three banans!

Page 6: Cреда разработки #1 - EDA in JS

Event driven

Fruit system “Tarzan took

three bananas”

“Fruit system is low on

bananas”

Page 7: Cреда разработки #1 - EDA in JS

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”)

Page 8: Cреда разработки #1 - EDA in JS

Typical EDA architecture

system system system

system system system

Event Bus

Event Poducer

Event Transport

Event Consumers

Page 9: Cреда разработки #1 - EDA in JS

Main benefits of EDA

●Better service (no batch, less waiting)

●No point-to-point integration (fire & forget)

●High performance, highly scalable systems

Page 10: Cреда разработки #1 - EDA in JS

The birth of system

Inventory

Customer

Shop

Page 11: Cреда разработки #1 - EDA in JS

The monolith

Inventory

Customer

Shop

NewsletterReporting

Payment

Page 12: Cреда разработки #1 - EDA in JS

SOA architecture

Shop Payment

Newsletter

Inventory

Customer Reporting

Divide the problem domains into separate systems

Page 13: Cреда разработки #1 - EDA in JS

SOA architecture

Shop Payment

Newsletter

Inventory

Customer Reporting

A lot of point to point integration...

Page 14: Cреда разработки #1 - EDA in JS

SOA + EDA =

Shop Payment

Newsletter

Inventory

Customer Reporting

Event Bus 3th system

Page 15: Cреда разработки #1 - EDA in JS

Core

[Observer’s minimum]

1.Publisher

2.Message

3.Subscriber

4.Emitter

5.*Topics

Page 16: Cреда разработки #1 - EDA in JS

Simple EDD implementation

MESSAGE

MESSAGE

MESSAGE

Simple Example

EmitterPublisher

Subscriber

Subscriber

Publisher/Subscriber

MESSAGE

Page 17: Cреда разработки #1 - EDA in JS

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

Page 18: Cреда разработки #1 - EDA in JS

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

Page 19: Cреда разработки #1 - EDA in JS

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...]])

Page 20: Cреда разработки #1 - EDA in JS

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...

Page 21: Cреда разработки #1 - EDA in JS

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..

Page 22: Cреда разработки #1 - EDA in JS

Time to coding!

Page 23: Cреда разработки #1 - EDA in JS

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