SlideShare a Scribd company logo
1 of 43
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.
Grails and the “Real-time web”
By Stephane Maldini
Prologue
Solving a basic problem
“Your valuable users don’t like waiting”
The Age of Asynchronous
Fact #1:
– HTTP request thread is critical path
– Do the barely necessary for fast rendering
– If it‟s long*, do it in a separate thread
The Age of Asynchronous
Fact #2:
– Creating new Threads needs caution
– Context switching hurts performances
– Concurrent programming is tricky*
The Age of Asynchronous
Fact #3:
– Burden on your application is never constant
– Scaling Up is a good start…
– …And Scaling Out is only next
Dilemma
So I have to use background threads ?
But using them might lead to issues and
headaches ?
And what if I really need to scale out ?
Reactive programming
• Adding a level of indirection :
Driving your application with Events
• Laziness is key
• Scale up/out by tweaking dispatching
The big picture
Events
Bus
Point to point
Service
Consumer
Service
Consumer
Service
Consumer
Service
Consumer
Service
Consumer
Application
The big picture
Events
Bus
Publish/Subscribe
Service
Consumer
Service
Consumer
Service
Consumer
Service
Consumer
Service
Consumer
Application
The big picture
Events
Bus
Publish/Subscribe
App
App
App
App
App
Cloud
Remember Platform-Core ? Remember Events ?
Introducing GRAILS-EVENTS
BOOM!
worse slide ever™
The new deal
• New features. And quite a few.
– Streaming data, Selectors, Queue
• Based on a solid foundation – Reactor
– Where Platform-core Events best ideas have leaked
• Semantic changes
– But relatively easy migration path
So what Grails Events is about
• Grails Apps and Plugins can use Events to:
– Listen for plugins/app events
– Start simple with in-memory eventing
– Do Asynchronous calls (default)
– Increase in flexibility if required
Installing Grails Events
• It‟s a binary plugin (!)
• Requires Grails 2.2+
Reactor big picture
Semantics: Consumer
• A Consumer:
– Accepts an Event
– Is registered in a Service or Events artifact, or by calling on()
– Can be thread safe
• Depending on the dispatcher type
• Assuming the consumer is not registered more than once
Semantics: Selector
• A Selector:
– Matches an event key
– Is paired with a consumer during its registration
Semantics: Reactor
• A Reactor:
– Is a dedicated Consumer Registry
– Has an assigned Dispatcher
– Uses a specific Event Router
• Usually, if the Dispatcher doesn‟t need to be adapted,
reuse the default reactor grailsReactor
Platform Core: Sending Events
def user = new User(params).save()
//non-blocking call, will trigger application listeners for this topic
event('mailRegistration', user)
//blocking call :
//event('mailRegistration', user).waitFor()
//can also be written like that
//event topic:'mailRegistration', data:user
//and if you need to reuse the current thread
//event topic:'mailRegistration', data:user, fork:false
render(view:'sendingRegistrationMail’)
Events: Sending Events
def user = new User(params).save()
//non-blocking call, will trigger application listeners for this topic
event('mailRegistration', user)
//Do things on each reply :
//event('mailRegistration', user){
if(it == ‘end’){
cancel()
}
}
//can also be written like that
//event key:'mailRegistration', data:user
render(view:'sendingRegistrationMail')
Platform Core Events : Consuming Events
class UserService{
//use method name 'mailRegistration' as topic name
//can also use custom topic name using topic arg: @Listener(topic='test')
@grails.events.Listener
def mailRegistration(User user){
sendMail{
to user.mail
subject "Confirmation"
html g.render(template:"userMailConfirmation")
}
}
//Can also receive an EventMessage to get more information on this particular event)
@grails.events.Listener(topic="mailRegistration")
def mailRegistration2(org.grails.plugin.platform.events.EventMessage msg){
sendMail{
to msg.data.mail
subject "Confirmation"
html g.render(template:"userMailConfirmation")
}
}
}
Events : Consuming Events
class UserService{
//use method name 'mailRegistration' as topic name
//can also use custom topic name using topic arg: @Selector(‘test')
@reactor.spring.annotation.Selector
def mailRegistration(User user){
sendMail{
to user.mail
subject "Confirmation"
html g.render(template:"userMailConfirmation")
}
}
//Can also receive an Event to get more information on this particular event)
@reactor.spring.annotation.Selector("mailRegistration")
def mailRegistration2(reactor.event.Event msg){
sendMail{
to msg.data.mail
subject "Confirmation"
html g.render(template:"userMailConfirmation")
}
}
}
Events : A new Artifact
Reactor awesomeness : Selectors
• Listen for arbitrary keys
• import static reactor.event.selector.Selectors.*
Reactor awesomeness : Stream API
• Reactive Extensions programming style
• Avoid callback hell
Reactor awesomeness : Promise API
• Grails 2.3 Promises become a Reactor Promises
• Benefits from Dispatcher overriding
• Powerful once Combined with Consumers
Reactor awesomeness : Routing
• During event dispatching, consumers list is selected
• Publish Subscribe is the default
• Possible to assign different routing strategy
Reactor awesomeness : Extensibility
• Main extension points:
– Dispatcher, Selector, Registry, EventRouter
• Metadata in Reactor Events DSL:
– ext(„someExtension‟, [ „doStuff‟ : true ])
GORM events
• GORM is now an extension
– Using ext(‘gorm’, true) on any candidate reactor
– Applicable Selectors: simple topic form (beforeInsert...)
– A boolean reply is evaluated as a cancel directive
GRAILS-EVENTS-PUSH
Eventing over HTTP
An elegant solution to browser push
• Powered by Atmosphere 2
• Automatically picks an adapted protocol:
– WebSockets, ServerSideEvent, Streaming, Polling…
• Consumer bridges for server-to-client push
• Reactor bridge for client-to-server push
• Javascript library
Installing Grails Events Push
1. Install Grails Events plugin
2. Install Grails Events Push plugin
Generating Simple Browsers bridges
React on server side events
Generating Advanced Browsers bridges
DEMO
Burn some idols for the demo gods please
Epilogue
The Bad Stuff
• events-si : Events API on top of Spring Integration
– Not here (just) yet
• events-vertx : Abandoned experiment
– Working around Distributed Reactor
• Stream DSL could be optimized
– Reducing the number of objects
Roadmap
• events:
– Document, especially for Migration from Platform Core
– Stick with latest awesome features from Reactor
• Still Many API to expose: Processors, Buffer, TCP, Queues,
Sequencer…
• events-push -> events-atmosphere :
– More robust subscription mech
– Update atmosphere client
– Add support for replyTo
– Add support for binary
Roadmap
• events-sockjs:
– Involves Reactor work here
• events-si:
– Supports new events plugin
• events-xx:
– The plugin where you are the hero
Learn More. Stay Connected.
• Follow-up
– Reactor repository: http://github.com/reactor/
– Mail: @smaldini / smaldini@gopivotal.com
• Talk to us on Twitter: @springcentral
• Find Session replays on YouTube: spring.io/video

More Related Content

What's hot

Embedded Mirror Maker
Embedded Mirror MakerEmbedded Mirror Maker
Embedded Mirror MakerSimon Suo
 
Project Deimos
Project DeimosProject Deimos
Project DeimosSimon Suo
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelinesTimothy Farkas
 
Meteor Boulder meetup #1
Meteor Boulder meetup #1Meteor Boulder meetup #1
Meteor Boulder meetup #1Robert Dickert
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsJohan Andrén
 
Use open stack to run java programs inside a Docker container
Use open stack to run java programs inside a Docker containerUse open stack to run java programs inside a Docker container
Use open stack to run java programs inside a Docker containerMiano Sebastiano
 
mule custom aggregator
mule   custom aggregatormule   custom aggregator
mule custom aggregatorPaolo Mojica
 
Write code that writes code!
Write code that writes code!Write code that writes code!
Write code that writes code!Jason Feinstein
 
Complex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESBComplex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESBPrabath Siriwardena
 
Functional Load Testing with Gatling
Functional Load Testing with GatlingFunctional Load Testing with Gatling
Functional Load Testing with GatlingGerald Muecke
 
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksMarcus Denker
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in ActionKnoldus Inc.
 
Zookeeper Architecture
Zookeeper ArchitectureZookeeper Architecture
Zookeeper ArchitecturePrasad Wali
 
Reactive programming with Pivotal's reactor
Reactive programming with Pivotal's reactorReactive programming with Pivotal's reactor
Reactive programming with Pivotal's reactorVMware Tanzu
 
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017Codemotion
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketKonrad Malawski
 
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaSMariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaSJelastic Multi-Cloud PaaS
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka StreamsKonrad Malawski
 

What's hot (20)

Embedded Mirror Maker
Embedded Mirror MakerEmbedded Mirror Maker
Embedded Mirror Maker
 
Project Deimos
Project DeimosProject Deimos
Project Deimos
 
Stateful streaming data pipelines
Stateful streaming data pipelinesStateful streaming data pipelines
Stateful streaming data pipelines
 
Meteor Boulder meetup #1
Meteor Boulder meetup #1Meteor Boulder meetup #1
Meteor Boulder meetup #1
 
Asynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka StreamsAsynchronous stream processing with Akka Streams
Asynchronous stream processing with Akka Streams
 
Use open stack to run java programs inside a Docker container
Use open stack to run java programs inside a Docker containerUse open stack to run java programs inside a Docker container
Use open stack to run java programs inside a Docker container
 
mule custom aggregator
mule   custom aggregatormule   custom aggregator
mule custom aggregator
 
Write code that writes code!
Write code that writes code!Write code that writes code!
Write code that writes code!
 
Complex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESBComplex Event Processing with Esper and WSO2 ESB
Complex Event Processing with Esper and WSO2 ESB
 
Functional Load Testing with Gatling
Functional Load Testing with GatlingFunctional Load Testing with Gatling
Functional Load Testing with Gatling
 
Reactor in Action
Reactor in ActionReactor in Action
Reactor in Action
 
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinksVUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
VUB Brussels Lecture 2019: Advanced Reflection: MetaLinks
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in Action
 
Zookeeper Architecture
Zookeeper ArchitectureZookeeper Architecture
Zookeeper Architecture
 
Reactive programming with Pivotal's reactor
Reactive programming with Pivotal's reactorReactive programming with Pivotal's reactor
Reactive programming with Pivotal's reactor
 
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
Mario Fusco - Reactive programming in Java - Codemotion Milan 2017
 
Angular meteor presentation
Angular meteor presentationAngular meteor presentation
Angular meteor presentation
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to Socket
 
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaSMariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
MariaDB Auto-Clustering, Vertical and Horizontal Scaling within Jelastic PaaS
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
 

Similar to Ss2gx

Data Microservices with Spring Cloud
Data Microservices with Spring CloudData Microservices with Spring Cloud
Data Microservices with Spring CloudOrkhan Gasimov
 
Explained: Domain events
Explained: Domain eventsExplained: Domain events
Explained: Domain eventsJoão Pires
 
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...OpenCredo
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJSLilia Sfaxi
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...Data Con LA
 
Building a system for machine and event-oriented data with Rocana
Building a system for machine and event-oriented data with RocanaBuilding a system for machine and event-oriented data with Rocana
Building a system for machine and event-oriented data with RocanaTreasure Data, Inc.
 
Introduction to Stream Processing
Introduction to Stream ProcessingIntroduction to Stream Processing
Introduction to Stream ProcessingGuido Schmutz
 
Building a system for machine and event-oriented data - Data Day Seattle 2015
Building a system for machine and event-oriented data - Data Day Seattle 2015Building a system for machine and event-oriented data - Data Day Seattle 2015
Building a system for machine and event-oriented data - Data Day Seattle 2015Eric Sammer
 
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...apidays
 
Building a system for machine and event-oriented data - Velocity, Santa Clara...
Building a system for machine and event-oriented data - Velocity, Santa Clara...Building a system for machine and event-oriented data - Velocity, Santa Clara...
Building a system for machine and event-oriented data - Velocity, Santa Clara...Eric Sammer
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and PracticesLaunchAny
 
Reactive programming
Reactive programmingReactive programming
Reactive programmingSUDIP GHOSH
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEORNodeXperts
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applicationsIvano Malavolta
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesYaroslav Tkachenko
 
Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with RailsPaul Gallagher
 
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...OpenWhisk
 
OpenWhisk: Where Did My Servers Go?
OpenWhisk: Where Did My Servers Go?OpenWhisk: Where Did My Servers Go?
OpenWhisk: Where Did My Servers Go?Carlos Santana
 

Similar to Ss2gx (20)

Eventsggx
EventsggxEventsggx
Eventsggx
 
Data Microservices with Spring Cloud
Data Microservices with Spring CloudData Microservices with Spring Cloud
Data Microservices with Spring Cloud
 
Explained: Domain events
Explained: Domain eventsExplained: Domain events
Explained: Domain events
 
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
ThingMonk 2016 - Concursus Event sourcing for the IOT By Tareq Abedrabbo & Do...
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJS
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Building an Event-oriented...
 
Building a system for machine and event-oriented data with Rocana
Building a system for machine and event-oriented data with RocanaBuilding a system for machine and event-oriented data with Rocana
Building a system for machine and event-oriented data with Rocana
 
Introduction to Stream Processing
Introduction to Stream ProcessingIntroduction to Stream Processing
Introduction to Stream Processing
 
Building a system for machine and event-oriented data - Data Day Seattle 2015
Building a system for machine and event-oriented data - Data Day Seattle 2015Building a system for machine and event-oriented data - Data Day Seattle 2015
Building a system for machine and event-oriented data - Data Day Seattle 2015
 
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
apidays LIVE Jakarta - Building an Event-Driven Architecture by Harin Honesty...
 
Building a system for machine and event-oriented data - Velocity, Santa Clara...
Building a system for machine and event-oriented data - Velocity, Santa Clara...Building a system for machine and event-oriented data - Velocity, Santa Clara...
Building a system for machine and event-oriented data - Velocity, Santa Clara...
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and Practices
 
Reactive programming
Reactive programmingReactive programming
Reactive programming
 
Meet with Meteor
Meet with MeteorMeet with Meteor
Meet with Meteor
 
Reactive Application Using METEOR
Reactive Application Using METEORReactive Application Using METEOR
Reactive Application Using METEOR
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applications
 
Actors or Not: Async Event Architectures
Actors or Not: Async Event ArchitecturesActors or Not: Async Event Architectures
Actors or Not: Async Event Architectures
 
Multi-tenancy with Rails
Multi-tenancy with RailsMulti-tenancy with Rails
Multi-tenancy with Rails
 
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
IBM Bluemix OpenWhisk: Serverless Conference 2016, London, UK: The Future of ...
 
OpenWhisk: Where Did My Servers Go?
OpenWhisk: Where Did My Servers Go?OpenWhisk: Where Did My Servers Go?
OpenWhisk: Where Did My Servers Go?
 

More from Stéphane Maldini

Multi-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketMulti-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketStéphane Maldini
 
The Future of Reactive Architectures
The Future of Reactive ArchitecturesThe Future of Reactive Architectures
The Future of Reactive ArchitecturesStéphane Maldini
 
What's new in Reactor Californium
What's new in Reactor CaliforniumWhat's new in Reactor Californium
What's new in Reactor CaliforniumStéphane Maldini
 
Spring boot 2.0 reactive bits (June 2018)
Spring boot 2.0 reactive bits (June 2018)Spring boot 2.0 reactive bits (June 2018)
Spring boot 2.0 reactive bits (June 2018)Stéphane Maldini
 
Reactor 3.0, a reactive foundation for java 8 and Spring
Reactor 3.0, a reactive foundation for java 8 and SpringReactor 3.0, a reactive foundation for java 8 and Spring
Reactor 3.0, a reactive foundation for java 8 and SpringStéphane Maldini
 
Introduction to Reactive Streams and Reactor 2.5
Introduction to Reactive Streams and Reactor 2.5Introduction to Reactive Streams and Reactor 2.5
Introduction to Reactive Streams and Reactor 2.5Stéphane Maldini
 
Intro to Reactive Programming
Intro to Reactive ProgrammingIntro to Reactive Programming
Intro to Reactive ProgrammingStéphane Maldini
 
Designing for Distributed Systems with Reactor and Reactive Streams
Designing for Distributed Systems with Reactor and Reactive StreamsDesigning for Distributed Systems with Reactor and Reactive Streams
Designing for Distributed Systems with Reactor and Reactive StreamsStéphane Maldini
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesStéphane Maldini
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorStéphane Maldini
 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013Stéphane Maldini
 
Groovy reactor grails realtime web devoxx 2013
Groovy reactor grails realtime web   devoxx 2013Groovy reactor grails realtime web   devoxx 2013
Groovy reactor grails realtime web devoxx 2013Stéphane Maldini
 

More from Stéphane Maldini (14)

The value of reactive
The value of reactiveThe value of reactive
The value of reactive
 
Multi-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocketMulti-service reactive streams using Spring, Reactor, RSocket
Multi-service reactive streams using Spring, Reactor, RSocket
 
The Future of Reactive Architectures
The Future of Reactive ArchitecturesThe Future of Reactive Architectures
The Future of Reactive Architectures
 
Spring Cloud Gateway
Spring Cloud GatewaySpring Cloud Gateway
Spring Cloud Gateway
 
What's new in Reactor Californium
What's new in Reactor CaliforniumWhat's new in Reactor Californium
What's new in Reactor Californium
 
Spring boot 2.0 reactive bits (June 2018)
Spring boot 2.0 reactive bits (June 2018)Spring boot 2.0 reactive bits (June 2018)
Spring boot 2.0 reactive bits (June 2018)
 
Reactor 3.0, a reactive foundation for java 8 and Spring
Reactor 3.0, a reactive foundation for java 8 and SpringReactor 3.0, a reactive foundation for java 8 and Spring
Reactor 3.0, a reactive foundation for java 8 and Spring
 
Introduction to Reactive Streams and Reactor 2.5
Introduction to Reactive Streams and Reactor 2.5Introduction to Reactive Streams and Reactor 2.5
Introduction to Reactive Streams and Reactor 2.5
 
Intro to Reactive Programming
Intro to Reactive ProgrammingIntro to Reactive Programming
Intro to Reactive Programming
 
Designing for Distributed Systems with Reactor and Reactive Streams
Designing for Distributed Systems with Reactor and Reactive StreamsDesigning for Distributed Systems with Reactor and Reactive Streams
Designing for Distributed Systems with Reactor and Reactive Streams
 
Reactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServicesReactor, Reactive streams and MicroServices
Reactor, Reactive streams and MicroServices
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
Reactor grails realtime web devoxx 2013
Reactor grails realtime web   devoxx 2013Reactor grails realtime web   devoxx 2013
Reactor grails realtime web devoxx 2013
 
Groovy reactor grails realtime web devoxx 2013
Groovy reactor grails realtime web   devoxx 2013Groovy reactor grails realtime web   devoxx 2013
Groovy reactor grails realtime web devoxx 2013
 

Recently uploaded

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Ss2gx

  • 1. © 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Grails and the “Real-time web” By Stephane Maldini
  • 3. Solving a basic problem “Your valuable users don’t like waiting”
  • 4. The Age of Asynchronous Fact #1: – HTTP request thread is critical path – Do the barely necessary for fast rendering – If it‟s long*, do it in a separate thread
  • 5. The Age of Asynchronous Fact #2: – Creating new Threads needs caution – Context switching hurts performances – Concurrent programming is tricky*
  • 6. The Age of Asynchronous Fact #3: – Burden on your application is never constant – Scaling Up is a good start… – …And Scaling Out is only next
  • 7. Dilemma So I have to use background threads ? But using them might lead to issues and headaches ? And what if I really need to scale out ?
  • 8. Reactive programming • Adding a level of indirection : Driving your application with Events • Laziness is key • Scale up/out by tweaking dispatching
  • 9. The big picture Events Bus Point to point Service Consumer Service Consumer Service Consumer Service Consumer Service Consumer Application
  • 12. Remember Platform-Core ? Remember Events ?
  • 14. The new deal • New features. And quite a few. – Streaming data, Selectors, Queue • Based on a solid foundation – Reactor – Where Platform-core Events best ideas have leaked • Semantic changes – But relatively easy migration path
  • 15. So what Grails Events is about • Grails Apps and Plugins can use Events to: – Listen for plugins/app events – Start simple with in-memory eventing – Do Asynchronous calls (default) – Increase in flexibility if required
  • 16. Installing Grails Events • It‟s a binary plugin (!) • Requires Grails 2.2+
  • 18. Semantics: Consumer • A Consumer: – Accepts an Event – Is registered in a Service or Events artifact, or by calling on() – Can be thread safe • Depending on the dispatcher type • Assuming the consumer is not registered more than once
  • 19. Semantics: Selector • A Selector: – Matches an event key – Is paired with a consumer during its registration
  • 20. Semantics: Reactor • A Reactor: – Is a dedicated Consumer Registry – Has an assigned Dispatcher – Uses a specific Event Router • Usually, if the Dispatcher doesn‟t need to be adapted, reuse the default reactor grailsReactor
  • 21. Platform Core: Sending Events def user = new User(params).save() //non-blocking call, will trigger application listeners for this topic event('mailRegistration', user) //blocking call : //event('mailRegistration', user).waitFor() //can also be written like that //event topic:'mailRegistration', data:user //and if you need to reuse the current thread //event topic:'mailRegistration', data:user, fork:false render(view:'sendingRegistrationMail’)
  • 22. Events: Sending Events def user = new User(params).save() //non-blocking call, will trigger application listeners for this topic event('mailRegistration', user) //Do things on each reply : //event('mailRegistration', user){ if(it == ‘end’){ cancel() } } //can also be written like that //event key:'mailRegistration', data:user render(view:'sendingRegistrationMail')
  • 23. Platform Core Events : Consuming Events class UserService{ //use method name 'mailRegistration' as topic name //can also use custom topic name using topic arg: @Listener(topic='test') @grails.events.Listener def mailRegistration(User user){ sendMail{ to user.mail subject "Confirmation" html g.render(template:"userMailConfirmation") } } //Can also receive an EventMessage to get more information on this particular event) @grails.events.Listener(topic="mailRegistration") def mailRegistration2(org.grails.plugin.platform.events.EventMessage msg){ sendMail{ to msg.data.mail subject "Confirmation" html g.render(template:"userMailConfirmation") } } }
  • 24. Events : Consuming Events class UserService{ //use method name 'mailRegistration' as topic name //can also use custom topic name using topic arg: @Selector(‘test') @reactor.spring.annotation.Selector def mailRegistration(User user){ sendMail{ to user.mail subject "Confirmation" html g.render(template:"userMailConfirmation") } } //Can also receive an Event to get more information on this particular event) @reactor.spring.annotation.Selector("mailRegistration") def mailRegistration2(reactor.event.Event msg){ sendMail{ to msg.data.mail subject "Confirmation" html g.render(template:"userMailConfirmation") } } }
  • 25. Events : A new Artifact
  • 26. Reactor awesomeness : Selectors • Listen for arbitrary keys • import static reactor.event.selector.Selectors.*
  • 27. Reactor awesomeness : Stream API • Reactive Extensions programming style • Avoid callback hell
  • 28. Reactor awesomeness : Promise API • Grails 2.3 Promises become a Reactor Promises • Benefits from Dispatcher overriding • Powerful once Combined with Consumers
  • 29. Reactor awesomeness : Routing • During event dispatching, consumers list is selected • Publish Subscribe is the default • Possible to assign different routing strategy
  • 30. Reactor awesomeness : Extensibility • Main extension points: – Dispatcher, Selector, Registry, EventRouter • Metadata in Reactor Events DSL: – ext(„someExtension‟, [ „doStuff‟ : true ])
  • 31. GORM events • GORM is now an extension – Using ext(‘gorm’, true) on any candidate reactor – Applicable Selectors: simple topic form (beforeInsert...) – A boolean reply is evaluated as a cancel directive
  • 33. An elegant solution to browser push • Powered by Atmosphere 2 • Automatically picks an adapted protocol: – WebSockets, ServerSideEvent, Streaming, Polling… • Consumer bridges for server-to-client push • Reactor bridge for client-to-server push • Javascript library
  • 34. Installing Grails Events Push 1. Install Grails Events plugin 2. Install Grails Events Push plugin
  • 36. React on server side events
  • 38. DEMO Burn some idols for the demo gods please
  • 40. The Bad Stuff • events-si : Events API on top of Spring Integration – Not here (just) yet • events-vertx : Abandoned experiment – Working around Distributed Reactor • Stream DSL could be optimized – Reducing the number of objects
  • 41. Roadmap • events: – Document, especially for Migration from Platform Core – Stick with latest awesome features from Reactor • Still Many API to expose: Processors, Buffer, TCP, Queues, Sequencer… • events-push -> events-atmosphere : – More robust subscription mech – Update atmosphere client – Add support for replyTo – Add support for binary
  • 42. Roadmap • events-sockjs: – Involves Reactor work here • events-si: – Supports new events plugin • events-xx: – The plugin where you are the hero
  • 43. Learn More. Stay Connected. • Follow-up – Reactor repository: http://github.com/reactor/ – Mail: @smaldini / smaldini@gopivotal.com • Talk to us on Twitter: @springcentral • Find Session replays on YouTube: spring.io/video

Editor's Notes

  1. Challenge long* Long is sometimes ok or a necessary evil.
  2. Synchronized block