SlideShare una empresa de Scribd logo
1 de 32
Flow Based Programming and 
Reactive Programming with node.js 
Sven Beauprez
2 
Who am I? 
● Independent Enterprise Solution Architect 
– Specialized in SOA and EAI 
– Strong background in Java web development since '90s 
● Steering member of IoT BE 
● Steering member of JavaPolis/Devoxx 2002 – 2009 
● Keep in touch 
– sven.beauprez@prorabel.com 
– https://www.linkedin.com/in/svenbeauprez
3 
Node.js main characterisitcs 
● … runs as a single process 
– Does not start a new process for each new request, which would mean a lot of overhead 
● … runs applications in a single thread 
– Does not start a new thread for each new request, which means less complex code and 
avoiding race conditions 
● … is asynchronous 
– Can handle multiple requests at one time without blocking new requests by using 
I/O eventing, callbacks and an event loop 
● … is ideal for I/O intensive tasks, but less for CPU intensive 
– CPU intensive tasks within the application would block the process and must be 
offloaded in worker threads/processes 
In other words a perfect fit for IoT where the main tasks 
on the edges and in the fog is collecting sensor data
4 
Node.js event loop* 
waiting waiting 
Event Loop 
(single thread) 
Incoming 
request 
Query DB 
(offloaded) 
Process 
result 
Write log 
(offloaded) Respond 
Thread Pool 
& Async I/O 
Filesystem 
Network 
Other 
Event 
Queue 
*http://kunkle.org/nodejs-explained-pres
5 
Node.js callback hell 
callback 1 
callback 2 
callback 3 
● Naive example of a node.js application 
Confusing, this gives even wrong result
6 
Node.js promises 
● Also called futures, deffereds, eventuals,... 
● A promise is an object (proxy) that represents the result of an asynchronous 
function call 
var promise = doSomethingAync() 
promise.then(onFulfilled, onRejected) 
● Biggest advantage of promises is that they can be chained to avoid callback hell 
readFile().then(readAnotherFile).then(doSomethingElse).then(...) 
● Promises can return any other value and the next 'onFulfilled' will be passed the 
value as argument 
readFile().then(function (buf) {return JSON.parse(buf.toString())}) 
.then(function (data) {// do something with `data`}) 
Promises are a simple form of dataflow programming
7 
What is dataflow? 
● Traditionally a program is modeled as a series of operations 
happening in a specific order, in other words how to do 
computations. 
Source: http://www.autobild.de/
8 
What is dataflow? 
● Dataflow programming emphasizes the movement of data 
and models programs as a series of connection. It describes 
what computation should be performed. 
Source: http://commons.wikimedia.org/wiki/File:Hyundai_car_assembly_line.jpg
9 
Flow Based Programming (FBP) 
● Describes a graph of nodes, which exchange messages 
containing data via the edges. The edges are defined outside 
the nodes, in others words nodes have no control on where 
the data comes from and where it goes to
10 
FBP: Unix Pipes 
● Unix pipes are an example of linear flow based 
programming while a stream of data follows the pipes and 
the different 'smaller' dedictated applications run in parallel 
ps aux | grep myApp | grep -v grep | awk '{print $2}' | xargs kill
11 
FBP: Yahoo Pipes 
Source: https://pipes.yahoo.com/pipes/pipe.info?_id=ZKJobpaj3BGZOew9G8evXg
12 
FBP: Enterprise Application Integration 
http://www.eaipatterns.com/Chapter1.html
13 
FBP: Node-RED
14 
FBP: Node-RED 
● According to the founders: 
– A light-weight, edge of network, application builder 
– Easy to use, drag and drop interface 
– A tool that allows the developer to focus on the task at hand 
● My definition: 
– A network of connected light-weight nodes to process stream(s) of 
edge generated events via message passing
15 
FBP: Node-RED 
● Messages are JSON objects 
“payload : “Hello world!” 
“topic” : “foo” 
……
16 
FBP: Node-RED 
● Different categories of nodes are defined: 
– Input: to process incoming events 
● Example: Inject trigger, HTTP, TCP, UDP, websocket, MQTT, 
file, Datastore, social (Twitter), … and custom nodes 
– Output: to serve or send outgoing events 
● Example: Debug, HTTP, TCP, UDP, websocket, MQTT, file, 
Datastore, social (Twitter), … and custom nodes 
– Functions: to manipulate messages and message payloads 
● Transform, filter, map, analyse, …
17 
FBP: Node-RED – Function node 
● Generic Function node: 
– Runs user-defined javascript code in a sandbox 
– Returns (forward) custom build messages with payloads 
● return msg; 
● return [msg1, msg2, msg3]; 
● return [msg1, [msgA, msgB]];
18 
FBP: Node-RED – Function Context 
● Each node has its own context to save state between calls 
– Since node.js is single threaded, no race conditions can occur and 
the state is always correct and up to date
19 
FBP: Node-RED – Custom Nodes 
● Custom nodes are defined via a pair of files: 
– .js : 
● defines what the node does 
● runs on the server 
– .html : 
● defines the node's properties, edit dialog and help text 
● runs in a browser 
● When configuration needs to be shared between nodes, eg. IN node and the 
related OUT node share the same IP address, a special config node can be defined 
– A dependeny on the config node is added in the custom node
20 
FBP: Node-RED 
Demo
21 
(Functional) Reactive Programming (FRP) 
● What if 
C = A + B 
meant C always equals A plus B, at any time?
22 
FRP: spreadsheets are reactive 
● The functions in a cell/chart react on changes in another cell
23 
FRP: dynamic values 
● In reactive programming, datatypes represent a value “over 
time”* 
– An example is getting coördinates of the mouse 
x = <mouse-x> 
y = <mouse-y> 
in reactive programming, the assignment needs to be made only 
once and the variables/properties will always be up to date with 
the latest values 
– All following computations based on these variables will also be 
values that change over time 
minX = x - 16; 
minY = y - 16; 
maxX = x + 16; 
maxY = y + 16; 
//draw 32x32 box around mouse pointer 
rectangle(minX, minY, maxX, maxY) 
*http://stackoverflow.com/a/1028642
24 
FRP: bacon.js how does it look like? 
http://jsfiddle.net/njs3szqe/
25 
FRP: bacon.js 'c = a + b', always 
http://jsfiddle.net/Lpe77wjk/
26 
FRP: 'functional' reactive programming 
● 'Functional' means that building blocks of functional programming are used 
– Ideas are borrowed from languages such as Haskell, Lisp, Scheme,... 
● Higher order functions are used extensively all over the place 
– Higher order = takes one or more functions as input and/or outputs a function 
– Examples: 
● Map, filter, scan, combine, takeWhile,... 
● See https://github.com/baconjs/bacon.js/ for an exhaustive list supported by 
bacon 
● See https://github.com/ReactiveX/RxJava/wiki/Observable for visual 
representation of many of these functions
27 
FRP: higher order function map() 
● Transform items emitted by a stream/property by applying a 
function to each of them 
https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#map
28 
FRP: higher order function filter() 
● Filter items emitted by a stream 
https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#filter
29 
FRP: higher order function scan() 
● Apply a function to each item emitted by a stream and emit 
each successive value 
https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#scan
30 
FRP: higher order function takeWhile() 
● Emit items emitted by a stream as long as a specified 
condition is true, then skip the remainder 
https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#takewhile-and-takewhilewithindex
FRP: Applying FRP in IoT – Bacon.js & Tessel 
31
32 
Q&A

Más contenido relacionado

La actualidad más candente

High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uring
ScyllaDB
 
Building Active Directory Monitoring with Telegraf, InfluxDB, and Grafana
Building Active Directory Monitoring with Telegraf, InfluxDB, and GrafanaBuilding Active Directory Monitoring with Telegraf, InfluxDB, and Grafana
Building Active Directory Monitoring with Telegraf, InfluxDB, and Grafana
Boni Yeamin
 

La actualidad más candente (20)

USENIX Vault'19: Performance analysis in Linux storage stack with BPF
USENIX Vault'19: Performance analysis in Linux storage stack with BPFUSENIX Vault'19: Performance analysis in Linux storage stack with BPF
USENIX Vault'19: Performance analysis in Linux storage stack with BPF
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPDockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
 
Node red with Arduino
Node red with ArduinoNode red with Arduino
Node red with Arduino
 
Ifupdown2: Network Interface Manager
Ifupdown2: Network Interface ManagerIfupdown2: Network Interface Manager
Ifupdown2: Network Interface Manager
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Kernel Recipes 2019 - XDP closer integration with network stack
Kernel Recipes 2019 -  XDP closer integration with network stackKernel Recipes 2019 -  XDP closer integration with network stack
Kernel Recipes 2019 - XDP closer integration with network stack
 
Project ACRN hypervisor introduction
Project ACRN hypervisor introduction Project ACRN hypervisor introduction
Project ACRN hypervisor introduction
 
OpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideOpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-Side
 
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
[MeetUp][1st] 오리뎅이의_쿠버네티스_네트워킹
 
eBPF Perf Tools 2019
eBPF Perf Tools 2019eBPF Perf Tools 2019
eBPF Perf Tools 2019
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDP
 
Solidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesSolidity Security and Best Coding Practices
Solidity Security and Best Coding Practices
 
High-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uringHigh-Performance Networking Using eBPF, XDP, and io_uring
High-Performance Networking Using eBPF, XDP, and io_uring
 
Xdp and ebpf_maps
Xdp and ebpf_mapsXdp and ebpf_maps
Xdp and ebpf_maps
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDKDoS and DDoS mitigations with eBPF, XDP and DPDK
DoS and DDoS mitigations with eBPF, XDP and DPDK
 
Building Active Directory Monitoring with Telegraf, InfluxDB, and Grafana
Building Active Directory Monitoring with Telegraf, InfluxDB, and GrafanaBuilding Active Directory Monitoring with Telegraf, InfluxDB, and Grafana
Building Active Directory Monitoring with Telegraf, InfluxDB, and Grafana
 
[MeetUp][2nd] 오리뎅이의_쿠버네티스_네트워킹_v1.2
[MeetUp][2nd] 오리뎅이의_쿠버네티스_네트워킹_v1.2[MeetUp][2nd] 오리뎅이의_쿠버네티스_네트워킹_v1.2
[MeetUp][2nd] 오리뎅이의_쿠버네티스_네트워킹_v1.2
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDK
 
EBPF and Linux Networking
EBPF and Linux NetworkingEBPF and Linux Networking
EBPF and Linux Networking
 
Building IAM for OpenStack
Building IAM for OpenStackBuilding IAM for OpenStack
Building IAM for OpenStack
 

Destacado

Nio100 demo box
Nio100 demo boxNio100 demo box
Nio100 demo box
和得 王
 

Destacado (20)

An introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-REDAn introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-RED
 
01 Node-RED Basic
01 Node-RED Basic01 Node-RED Basic
01 Node-RED Basic
 
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
 
Supercharge your IOT toolbox with MQTT and Node-RED
Supercharge your IOT toolbox with MQTT and Node-REDSupercharge your IOT toolbox with MQTT and Node-RED
Supercharge your IOT toolbox with MQTT and Node-RED
 
Web of Things (wiring web objects with Node-RED)
Web of Things (wiring web objects with Node-RED)Web of Things (wiring web objects with Node-RED)
Web of Things (wiring web objects with Node-RED)
 
AT&T Hack Dallas Node-RED Tutorial
AT&T Hack Dallas Node-RED TutorialAT&T Hack Dallas Node-RED Tutorial
AT&T Hack Dallas Node-RED Tutorial
 
Using bluemix predictive analytics service in Node-RED
Using bluemix predictive analytics service in Node-REDUsing bluemix predictive analytics service in Node-RED
Using bluemix predictive analytics service in Node-RED
 
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflows
 
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud ComputingIDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
 
Node red for Raspberry Pi
Node red for Raspberry PiNode red for Raspberry Pi
Node red for Raspberry Pi
 
Node-RED Interoperability Test
Node-RED Interoperability TestNode-RED Interoperability Test
Node-RED Interoperability Test
 
node.js dao
node.js daonode.js dao
node.js dao
 
MQTT と Quickstart と NodeRED
MQTT と Quickstart と NodeREDMQTT と Quickstart と NodeRED
MQTT と Quickstart と NodeRED
 
IAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-REDIAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-RED
 
TampereJS Meetup: Node-RED by Mika Karaila, Valmet
TampereJS Meetup: Node-RED by Mika Karaila, ValmetTampereJS Meetup: Node-RED by Mika Karaila, Valmet
TampereJS Meetup: Node-RED by Mika Karaila, Valmet
 
Distributed Data Flow for the Web of Things: Distributed Node-RED
Distributed Data Flow for the Web of Things: Distributed Node-REDDistributed Data Flow for the Web of Things: Distributed Node-RED
Distributed Data Flow for the Web of Things: Distributed Node-RED
 
Node red workshop
Node red workshopNode red workshop
Node red workshop
 
Nio100 demo box
Nio100 demo boxNio100 demo box
Nio100 demo box
 
EDT-IOT September 2015 Meetup - IOT+Node-RED
EDT-IOT September 2015 Meetup - IOT+Node-REDEDT-IOT September 2015 Meetup - IOT+Node-RED
EDT-IOT September 2015 Meetup - IOT+Node-RED
 

Similar a Flow Base Programming with Node-RED and Functional Reactive Programming with Baconjs

Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Elixir Club
 
Easy deployment & management of cloud apps
Easy deployment & management of cloud appsEasy deployment & management of cloud apps
Easy deployment & management of cloud apps
David Cunningham
 
Node js
Node jsNode js
Node js
hazzaz
 

Similar a Flow Base Programming with Node-RED and Functional Reactive Programming with Baconjs (20)

Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
 
Nodejs
NodejsNodejs
Nodejs
 
Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Easy deployment & management of cloud apps
Easy deployment & management of cloud appsEasy deployment & management of cloud apps
Easy deployment & management of cloud apps
 
Informix Expedition Through Connectivity
Informix Expedition Through ConnectivityInformix Expedition Through Connectivity
Informix Expedition Through Connectivity
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJS
 
React native
React nativeReact native
React native
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
 
Node js
Node jsNode js
Node js
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 

Último

Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
Diya Sharma
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 

Último (20)

Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
Dwarka Sector 26 Call Girls | Delhi | 9999965857 🫦 Vanshika Verma More Our Se...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
Russian Call Girls in %(+971524965298  )#  Call Girls in DubaiRussian Call Girls in %(+971524965298  )#  Call Girls in Dubai
Russian Call Girls in %(+971524965298 )# Call Girls in Dubai
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort ServiceBusty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
Busty Desi⚡Call Girls in Vasundhara Ghaziabad >༒8448380779 Escort Service
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Sarai Rohilla Escort Service Delhi N.C.R.
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 

Flow Base Programming with Node-RED and Functional Reactive Programming with Baconjs

  • 1. Flow Based Programming and Reactive Programming with node.js Sven Beauprez
  • 2. 2 Who am I? ● Independent Enterprise Solution Architect – Specialized in SOA and EAI – Strong background in Java web development since '90s ● Steering member of IoT BE ● Steering member of JavaPolis/Devoxx 2002 – 2009 ● Keep in touch – sven.beauprez@prorabel.com – https://www.linkedin.com/in/svenbeauprez
  • 3. 3 Node.js main characterisitcs ● … runs as a single process – Does not start a new process for each new request, which would mean a lot of overhead ● … runs applications in a single thread – Does not start a new thread for each new request, which means less complex code and avoiding race conditions ● … is asynchronous – Can handle multiple requests at one time without blocking new requests by using I/O eventing, callbacks and an event loop ● … is ideal for I/O intensive tasks, but less for CPU intensive – CPU intensive tasks within the application would block the process and must be offloaded in worker threads/processes In other words a perfect fit for IoT where the main tasks on the edges and in the fog is collecting sensor data
  • 4. 4 Node.js event loop* waiting waiting Event Loop (single thread) Incoming request Query DB (offloaded) Process result Write log (offloaded) Respond Thread Pool & Async I/O Filesystem Network Other Event Queue *http://kunkle.org/nodejs-explained-pres
  • 5. 5 Node.js callback hell callback 1 callback 2 callback 3 ● Naive example of a node.js application Confusing, this gives even wrong result
  • 6. 6 Node.js promises ● Also called futures, deffereds, eventuals,... ● A promise is an object (proxy) that represents the result of an asynchronous function call var promise = doSomethingAync() promise.then(onFulfilled, onRejected) ● Biggest advantage of promises is that they can be chained to avoid callback hell readFile().then(readAnotherFile).then(doSomethingElse).then(...) ● Promises can return any other value and the next 'onFulfilled' will be passed the value as argument readFile().then(function (buf) {return JSON.parse(buf.toString())}) .then(function (data) {// do something with `data`}) Promises are a simple form of dataflow programming
  • 7. 7 What is dataflow? ● Traditionally a program is modeled as a series of operations happening in a specific order, in other words how to do computations. Source: http://www.autobild.de/
  • 8. 8 What is dataflow? ● Dataflow programming emphasizes the movement of data and models programs as a series of connection. It describes what computation should be performed. Source: http://commons.wikimedia.org/wiki/File:Hyundai_car_assembly_line.jpg
  • 9. 9 Flow Based Programming (FBP) ● Describes a graph of nodes, which exchange messages containing data via the edges. The edges are defined outside the nodes, in others words nodes have no control on where the data comes from and where it goes to
  • 10. 10 FBP: Unix Pipes ● Unix pipes are an example of linear flow based programming while a stream of data follows the pipes and the different 'smaller' dedictated applications run in parallel ps aux | grep myApp | grep -v grep | awk '{print $2}' | xargs kill
  • 11. 11 FBP: Yahoo Pipes Source: https://pipes.yahoo.com/pipes/pipe.info?_id=ZKJobpaj3BGZOew9G8evXg
  • 12. 12 FBP: Enterprise Application Integration http://www.eaipatterns.com/Chapter1.html
  • 14. 14 FBP: Node-RED ● According to the founders: – A light-weight, edge of network, application builder – Easy to use, drag and drop interface – A tool that allows the developer to focus on the task at hand ● My definition: – A network of connected light-weight nodes to process stream(s) of edge generated events via message passing
  • 15. 15 FBP: Node-RED ● Messages are JSON objects “payload : “Hello world!” “topic” : “foo” ……
  • 16. 16 FBP: Node-RED ● Different categories of nodes are defined: – Input: to process incoming events ● Example: Inject trigger, HTTP, TCP, UDP, websocket, MQTT, file, Datastore, social (Twitter), … and custom nodes – Output: to serve or send outgoing events ● Example: Debug, HTTP, TCP, UDP, websocket, MQTT, file, Datastore, social (Twitter), … and custom nodes – Functions: to manipulate messages and message payloads ● Transform, filter, map, analyse, …
  • 17. 17 FBP: Node-RED – Function node ● Generic Function node: – Runs user-defined javascript code in a sandbox – Returns (forward) custom build messages with payloads ● return msg; ● return [msg1, msg2, msg3]; ● return [msg1, [msgA, msgB]];
  • 18. 18 FBP: Node-RED – Function Context ● Each node has its own context to save state between calls – Since node.js is single threaded, no race conditions can occur and the state is always correct and up to date
  • 19. 19 FBP: Node-RED – Custom Nodes ● Custom nodes are defined via a pair of files: – .js : ● defines what the node does ● runs on the server – .html : ● defines the node's properties, edit dialog and help text ● runs in a browser ● When configuration needs to be shared between nodes, eg. IN node and the related OUT node share the same IP address, a special config node can be defined – A dependeny on the config node is added in the custom node
  • 21. 21 (Functional) Reactive Programming (FRP) ● What if C = A + B meant C always equals A plus B, at any time?
  • 22. 22 FRP: spreadsheets are reactive ● The functions in a cell/chart react on changes in another cell
  • 23. 23 FRP: dynamic values ● In reactive programming, datatypes represent a value “over time”* – An example is getting coördinates of the mouse x = <mouse-x> y = <mouse-y> in reactive programming, the assignment needs to be made only once and the variables/properties will always be up to date with the latest values – All following computations based on these variables will also be values that change over time minX = x - 16; minY = y - 16; maxX = x + 16; maxY = y + 16; //draw 32x32 box around mouse pointer rectangle(minX, minY, maxX, maxY) *http://stackoverflow.com/a/1028642
  • 24. 24 FRP: bacon.js how does it look like? http://jsfiddle.net/njs3szqe/
  • 25. 25 FRP: bacon.js 'c = a + b', always http://jsfiddle.net/Lpe77wjk/
  • 26. 26 FRP: 'functional' reactive programming ● 'Functional' means that building blocks of functional programming are used – Ideas are borrowed from languages such as Haskell, Lisp, Scheme,... ● Higher order functions are used extensively all over the place – Higher order = takes one or more functions as input and/or outputs a function – Examples: ● Map, filter, scan, combine, takeWhile,... ● See https://github.com/baconjs/bacon.js/ for an exhaustive list supported by bacon ● See https://github.com/ReactiveX/RxJava/wiki/Observable for visual representation of many of these functions
  • 27. 27 FRP: higher order function map() ● Transform items emitted by a stream/property by applying a function to each of them https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#map
  • 28. 28 FRP: higher order function filter() ● Filter items emitted by a stream https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#filter
  • 29. 29 FRP: higher order function scan() ● Apply a function to each item emitted by a stream and emit each successive value https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#scan
  • 30. 30 FRP: higher order function takeWhile() ● Emit items emitted by a stream as long as a specified condition is true, then skip the remainder https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#takewhile-and-takewhilewithindex
  • 31. FRP: Applying FRP in IoT – Bacon.js & Tessel 31