SlideShare une entreprise Scribd logo
1  sur  37
Télécharger pour lire hors ligne
Reactive Grails
 Event-driven architecture made easy




Stephane Maldini – Consultant @ SpringSource/VMware*




                                           * Changes may apply in the next couple of months
WHY ?!!!!!!!!!!!!!!!!



                        2
In Memory use cases


•  Loosely coupled
  – Plugin oriented
  – Testable handlers without mocking


•  Declarative logic
  – Workflow by contract


•  Threading scalability
  – Scale to multicores without digging too deep in your code




                                                                3
In Cloud use cases


•  Sharing workload
  – And on demand !
  – One machine can handle the task: using a shared work queue


•  Synchronizing
  – All machines need to work: Cache invalidation, indexing...


•  Communicating with Service API
  – Layering at machine level instead of software level



                                                                 4
The big picture


    Application
                                    Service Listener



        Service Listener                 Point to point


                               Events
                                Bus               Service Listener




            Service Listener
                                            Service Listener




                                                                     5
The big picture


    Application
                                    Service Listener



        Service Listener                 Publish/Subscribe


                               Events
                                Bus               Service Listener




            Service Listener
                                            Service Listener




                                                                     6
The big picture


    Cloud
                                 App



            App                  Publish/Subscribe


                        Events
                         Bus                   App




                  App
                                         App




                                                     7
Boring




  Robert Fletcher




                    8
Grails on bus : current plugins

•  Spring Events
  – Use ApplicationContext to propagate ApplicationEvents
  – Code boilerplate


•  Routing (Apache Camel)
  – Super flexible
  – Simple but powerful
  – Routing DSL but not so Grailsy


•  Falcone Utils
  – Fully integrated with Grails
  – Not maintained

                                                            9
Platform-Core

•  This plugin purpose is to provide key features for todays
   application development and plugin oriented architecture

•  Provided by Marc Palmer and your guest

•  Initiated mid 2012, currently version 1.0.RC2:
  – Nearly complete API stabilization
  – Integrated with grails development


•  Fully extensible, API driven design



                                                               10
Platform-Core: API




                      Configuration
      Navigation

                                Security
     Injection
                   Events




                                           11
Platform-Core : Events




                         12
Platform-Core : Events

•  Grails Apps and Plugins can use Platform-Core/Events to:

  – Listen for plugins/app events

  – Avoid topic name conflicts using namespacing support

  – Do in-memory eventing

  – Do Asynchronous calls (default)

  – Increase in flexibility if required



                                                              13
Platform-Core : Events




•  Add this to your BuildConfig RIGHT NOW :

  – compile :platform-core:1.0.RC2




                                              14
Events : Sending Events
                                                                                                                                                        	
  
 class	
  UserController{	
  
 	
  	
  
 	
  	
  	
  def	
  registration(){	
  
 	
  	
  	
  	
  	
  	
  	
  	
  	
  def	
  user	
  =	
  new	
  User(params).save()	
  
 	
  	
  	
  	
  	
  	
  	
  	
  	
  if(user){	
  
 	
  	
  
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //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')	
  
 	
  	
  	
  	
  	
  	
  	
  	
  	
  }else{	
  
 	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  render(view:'errorRegistration')	
  
 	
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
 	
  	
  }	
  
 }	
  


                                                                                                                                                        15
Events : Listening 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")	
  
  	
  	
  	
  	
  	
  	
  	
  	
  }	
  
  	
  	
  }	
  
  }	
  



                                                                                                                                      16
Events : DSL

events	
  =	
  {	
  
	
  	
  	
  	
  //prevents	
  any	
  events	
  in	
  gorm	
  namespace	
  
	
  	
  	
  	
  '*'	
  namespace:'gorm',	
  disabled:true	
  
	
  	
  
	
  	
  	
  	
  //filters	
  any	
  events	
  on	
  'testTopic'	
  where	
  data	
  <=	
  2	
  
	
  	
  	
  	
  testTopic	
  filter:{it	
  >	
  2}	
  
	
  	
  
	
  	
  	
  	
  //filters	
  any	
  events	
  on	
  'testTopic2'	
  where	
  data	
  is	
  not	
  a	
  TestTopic	
  class	
  type	
  
	
  	
  	
  	
  testTopic2	
  filter:TestTopic	
  
	
  	
  
	
  	
  	
  	
  //filters	
  any	
  events	
  on	
  'testTopicX'	
  using	
  boolean	
  method	
  from	
  service	
  
	
  	
  	
  	
  testTopicX	
  filter:ctx.myService.&someMethod	
  
	
  	
  
	
  	
  	
  	
  //only	
  if	
  using	
  events-­‐push	
  plugin,	
  allows	
  client-­‐side	
  listener	
  on	
  this	
  topic	
  
	
  	
  	
  	
  testTopic3	
  browser:true	
  
	
  	
  
	
  	
  	
  	
  //Default	
  Error	
  Handling,	
  Global	
  Reply	
  Handling,	
  timeout	
  and	
  fork	
  
	
  	
  	
  	
  testTopicD	
  onError:{},	
  onReply:{},	
  timeout:1000l	
  
	
  	
  	
  	
  testTopicD2	
  fork:false	
  
	
  	
  
	
  	
  
}	
  


                                                                                                                                 17
Platform-Core : Events, more!

•  Listen to GORM events
  – using the same API


•  Reply handlers
  – Return values from your listeners to pass them back to caller


•  Errors handler
  – Listen for any exceptions




                                                                    18
Platform-Core : Simplicity Wins!




                                   19
Events : Plugins

•  Leveraging and enriching the Platform-core API

•  May update events registering/dispatching engine

•  Combine them and achieve kool kombos

•  Currently 3 plugins in development
  – Events-SI : Spring Integration backed events
  – Events-Push : Events to the browser using Atmosphere
  – Vertx : Vertx integration and platform-core backed events



                                                                20
grails-events-si

•  Change in-memory default mechanism:

  – @Listener now generates a channel + endpoint

  – event methods now send through Spring Integration gateway

  – This channel can be overriden using the naming convention

  – Super flexible, connect to the world




                                                                21
grails-events-si

•  SI => Spring Integration
  – Implements Enterprise Integration Patterns




                                                 22
grails-events-si + Groovy DSL

•  Based on the excellent module from David Turanski:
  – https://github.com/SpringSource/spring-integration-dsl-groovy


•  Integration with Events plugin registry and publishing
  – Easy to add queuing behavior
  – Easy to transform Pub/Sub to Point 2 Point
  – Additional declarative logic (filtering, system integration etc)


•  Still possible to fallback to standard BeanBuilder




                                                                       23
grails-events-si + Groovy DSL




                                24
How to send through RabbitMQ in minutes

With this in BuildConfig :
  runtime ":rabbitmq:1.0.0 "
  runtime ":events-si:1.0.M4-SNAPSHOT"


beans = { !
    xmlns siAmqp: 

'http://www.springframework.org/schema/integration/amqp' !
 !
    siAmqp.'publish-subscribe-channel'(id: 'gorm://afterInsert') !
 !
    siAmqp.'publish-subscribe-channel'(id: 'gorm://afterDelete') !
 !
    siAmqp.'publish-subscribe-channel'(id: 'gorm://afterUpdate') !
 !
}!




                                                               25
grails-events-push

•  And if you want to listen for events... in Javascript
  – Like Socket.IO or Vertx

  – Like a free bird

  – But not so free, prevent from listening everything

  – But which damn protocol using ??




                                                           26
grails-events-push




   ATMOSPHERE
   SAVES
   THE
   WORLD




                     27
React on server side events




                              28
grails-events-push : Whitelist




                                 29
grails-vertx : Hipster time




                              30
grails-vertx

•  No hands clustering
  – Using Vert.x Hazelcast support


•  Super scalable events processor
  – Mom’ said Event loop is darn good at handling high concurrent
    load


•  Deploying features as verticles
  – WIN for hot reloading plugins/services




                                                                    31
grails-vertx

•  vertxService bean (vertx instance, container)

•  Grails dedicated language factory:
  – Verticle Hot reloading
  – Classloader access




                                                   32
grails-vertx




               33
Roadmaps

•  Platform-Core
  – Work Queue / Point to Point eventing
  – Response Streaming


•  Events-SI
  – Overridable listeners with Queue channels


•  Events-Push
  – More on filtering
  – ... per request security (with PlatformCore security)




                                                            34
Roadmaps

•  Some more Vertx love:
  – Better integration

  – Specific DSL to manage verticles

  – SockJS support

  – request dispatching
    •  Vertx Back / Grails Front
    •  Vertx Front / Grails Back ?


  – Rename it Testx


                                       35
Demos!




         36
More info

•  w: http://bit.ly/platform-core-docs
•  w: http://github.com/smaldini

•  Grails Todos source:
   https://github.com/smaldini/grailsTodos




•  t: @smaldini




                                             37

Contenu connexe

Similaire à Eventsggx

Kubernetes walkthrough
Kubernetes walkthroughKubernetes walkthrough
Kubernetes walkthroughSangwon Lee
 
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless OverviewOpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless OverviewMaría Angélica Bracho
 
Building 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesBuilding 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesJakarta_EE
 
Leveraging the power of SolrCloud and Spark with OpenShift
Leveraging the power of SolrCloud and Spark with OpenShiftLeveraging the power of SolrCloud and Spark with OpenShift
Leveraging the power of SolrCloud and Spark with OpenShiftQAware GmbH
 
OpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integrationOpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integrationMichiel Kalkman
 
Live Coding 12 Factor App
Live Coding 12 Factor AppLive Coding 12 Factor App
Live Coding 12 Factor AppEmily Jiang
 
Deep Dive: Strategic Importance of BaaS
Deep Dive: Strategic Importance of BaaSDeep Dive: Strategic Importance of BaaS
Deep Dive: Strategic Importance of BaaSApigee | Google Cloud
 
Episode 4: Operating Kubernetes at Scale with DC/OS
Episode 4: Operating Kubernetes at Scale with DC/OSEpisode 4: Operating Kubernetes at Scale with DC/OS
Episode 4: Operating Kubernetes at Scale with DC/OSMesosphere Inc.
 
Enterprise wide publish subscribe with Apache Kafka
Enterprise wide publish subscribe with Apache KafkaEnterprise wide publish subscribe with Apache Kafka
Enterprise wide publish subscribe with Apache KafkaJohan Louwers
 
Microservice 微服務
Microservice 微服務Microservice 微服務
Microservice 微服務YOU SHENG CHEN
 
The 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWAREThe 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWAREFIWARE
 
The Serverless Paradigm, OpenWhisk and FIWARE
The Serverless Paradigm, OpenWhisk and FIWAREThe Serverless Paradigm, OpenWhisk and FIWARE
The Serverless Paradigm, OpenWhisk and FIWAREAlex Glikson
 
GigaSpaces CCF 4 Xap
GigaSpaces CCF 4 XapGigaSpaces CCF 4 Xap
GigaSpaces CCF 4 XapShay Hassidim
 
Is 12 Factor App Right About Logging
Is 12 Factor App Right About LoggingIs 12 Factor App Right About Logging
Is 12 Factor App Right About LoggingPhil Wilkins
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfKAI CHU CHUNG
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and PracticesLaunchAny
 
4156 Twist and cloud-how ibm customers make cics dance
4156 Twist and cloud-how ibm customers make cics dance4156 Twist and cloud-how ibm customers make cics dance
4156 Twist and cloud-how ibm customers make cics dancenick_garrod
 
Gatekeeper: API gateway
Gatekeeper: API gatewayGatekeeper: API gateway
Gatekeeper: API gatewayChengHui Weng
 

Similaire à Eventsggx (20)

Ss2gx
Ss2gxSs2gx
Ss2gx
 
Kubernetes walkthrough
Kubernetes walkthroughKubernetes walkthrough
Kubernetes walkthrough
 
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless OverviewOpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
OpenShift Meetup - Tokyo - Service Mesh and Serverless Overview
 
Building 12-factor Cloud Native Microservices
Building 12-factor Cloud Native MicroservicesBuilding 12-factor Cloud Native Microservices
Building 12-factor Cloud Native Microservices
 
Leveraging the power of SolrCloud and Spark with OpenShift
Leveraging the power of SolrCloud and Spark with OpenShiftLeveraging the power of SolrCloud and Spark with OpenShift
Leveraging the power of SolrCloud and Spark with OpenShift
 
OpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integrationOpenShift/Kubernetes to Splunk log integration
OpenShift/Kubernetes to Splunk log integration
 
Live Coding 12 Factor App
Live Coding 12 Factor AppLive Coding 12 Factor App
Live Coding 12 Factor App
 
Deep Dive: Strategic Importance of BaaS
Deep Dive: Strategic Importance of BaaSDeep Dive: Strategic Importance of BaaS
Deep Dive: Strategic Importance of BaaS
 
Episode 4: Operating Kubernetes at Scale with DC/OS
Episode 4: Operating Kubernetes at Scale with DC/OSEpisode 4: Operating Kubernetes at Scale with DC/OS
Episode 4: Operating Kubernetes at Scale with DC/OS
 
Enterprise wide publish subscribe with Apache Kafka
Enterprise wide publish subscribe with Apache KafkaEnterprise wide publish subscribe with Apache Kafka
Enterprise wide publish subscribe with Apache Kafka
 
Microservice 微服務
Microservice 微服務Microservice 微服務
Microservice 微服務
 
The 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWAREThe 'Serverless' Paradigm, OpenWhisk and FIWARE
The 'Serverless' Paradigm, OpenWhisk and FIWARE
 
The Serverless Paradigm, OpenWhisk and FIWARE
The Serverless Paradigm, OpenWhisk and FIWAREThe Serverless Paradigm, OpenWhisk and FIWARE
The Serverless Paradigm, OpenWhisk and FIWARE
 
GigaSpaces CCF 4 Xap
GigaSpaces CCF 4 XapGigaSpaces CCF 4 Xap
GigaSpaces CCF 4 Xap
 
Is 12 Factor App Right About Logging
Is 12 Factor App Right About LoggingIs 12 Factor App Right About Logging
Is 12 Factor App Right About Logging
 
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdfDevfest 2023 - Service Weaver Introduction - Taipei.pdf
Devfest 2023 - Service Weaver Introduction - Taipei.pdf
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and Practices
 
Monitoring in 2017 - TIAD Camp Docker
Monitoring in 2017 - TIAD Camp DockerMonitoring in 2017 - TIAD Camp Docker
Monitoring in 2017 - TIAD Camp Docker
 
4156 Twist and cloud-how ibm customers make cics dance
4156 Twist and cloud-how ibm customers make cics dance4156 Twist and cloud-how ibm customers make cics dance
4156 Twist and cloud-how ibm customers make cics dance
 
Gatekeeper: API gateway
Gatekeeper: API gatewayGatekeeper: API gateway
Gatekeeper: API gateway
 

Plus de 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
 
Reactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-finalReactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-finalStéphane Maldini
 

Plus de Stéphane Maldini (15)

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
 
Reactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-finalReactor spring one2gx_2013_0902-final
Reactor spring one2gx_2013_0902-final
 

Eventsggx

  • 1. Reactive Grails Event-driven architecture made easy Stephane Maldini – Consultant @ SpringSource/VMware* * Changes may apply in the next couple of months
  • 3. In Memory use cases •  Loosely coupled – Plugin oriented – Testable handlers without mocking •  Declarative logic – Workflow by contract •  Threading scalability – Scale to multicores without digging too deep in your code 3
  • 4. In Cloud use cases •  Sharing workload – And on demand ! – One machine can handle the task: using a shared work queue •  Synchronizing – All machines need to work: Cache invalidation, indexing... •  Communicating with Service API – Layering at machine level instead of software level 4
  • 5. The big picture Application Service Listener Service Listener Point to point Events Bus Service Listener Service Listener Service Listener 5
  • 6. The big picture Application Service Listener Service Listener Publish/Subscribe Events Bus Service Listener Service Listener Service Listener 6
  • 7. The big picture Cloud App App Publish/Subscribe Events Bus App App App 7
  • 8. Boring Robert Fletcher 8
  • 9. Grails on bus : current plugins •  Spring Events – Use ApplicationContext to propagate ApplicationEvents – Code boilerplate •  Routing (Apache Camel) – Super flexible – Simple but powerful – Routing DSL but not so Grailsy •  Falcone Utils – Fully integrated with Grails – Not maintained 9
  • 10. Platform-Core •  This plugin purpose is to provide key features for todays application development and plugin oriented architecture •  Provided by Marc Palmer and your guest •  Initiated mid 2012, currently version 1.0.RC2: – Nearly complete API stabilization – Integrated with grails development •  Fully extensible, API driven design 10
  • 11. Platform-Core: API Configuration Navigation Security Injection Events 11
  • 13. Platform-Core : Events •  Grails Apps and Plugins can use Platform-Core/Events to: – Listen for plugins/app events – Avoid topic name conflicts using namespacing support – Do in-memory eventing – Do Asynchronous calls (default) – Increase in flexibility if required 13
  • 14. Platform-Core : Events •  Add this to your BuildConfig RIGHT NOW : – compile :platform-core:1.0.RC2 14
  • 15. Events : Sending Events   class  UserController{            def  registration(){                    def  user  =  new  User(params).save()                    if(user){                              //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')                    }else{                          render(view:'errorRegistration')                    }      }   }   15
  • 16. Events : Listening 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")                  }      }   }   16
  • 17. Events : DSL events  =  {          //prevents  any  events  in  gorm  namespace          '*'  namespace:'gorm',  disabled:true              //filters  any  events  on  'testTopic'  where  data  <=  2          testTopic  filter:{it  >  2}              //filters  any  events  on  'testTopic2'  where  data  is  not  a  TestTopic  class  type          testTopic2  filter:TestTopic              //filters  any  events  on  'testTopicX'  using  boolean  method  from  service          testTopicX  filter:ctx.myService.&someMethod              //only  if  using  events-­‐push  plugin,  allows  client-­‐side  listener  on  this  topic          testTopic3  browser:true              //Default  Error  Handling,  Global  Reply  Handling,  timeout  and  fork          testTopicD  onError:{},  onReply:{},  timeout:1000l          testTopicD2  fork:false           }   17
  • 18. Platform-Core : Events, more! •  Listen to GORM events – using the same API •  Reply handlers – Return values from your listeners to pass them back to caller •  Errors handler – Listen for any exceptions 18
  • 20. Events : Plugins •  Leveraging and enriching the Platform-core API •  May update events registering/dispatching engine •  Combine them and achieve kool kombos •  Currently 3 plugins in development – Events-SI : Spring Integration backed events – Events-Push : Events to the browser using Atmosphere – Vertx : Vertx integration and platform-core backed events 20
  • 21. grails-events-si •  Change in-memory default mechanism: – @Listener now generates a channel + endpoint – event methods now send through Spring Integration gateway – This channel can be overriden using the naming convention – Super flexible, connect to the world 21
  • 22. grails-events-si •  SI => Spring Integration – Implements Enterprise Integration Patterns 22
  • 23. grails-events-si + Groovy DSL •  Based on the excellent module from David Turanski: – https://github.com/SpringSource/spring-integration-dsl-groovy •  Integration with Events plugin registry and publishing – Easy to add queuing behavior – Easy to transform Pub/Sub to Point 2 Point – Additional declarative logic (filtering, system integration etc) •  Still possible to fallback to standard BeanBuilder 23
  • 25. How to send through RabbitMQ in minutes With this in BuildConfig : runtime ":rabbitmq:1.0.0 " runtime ":events-si:1.0.M4-SNAPSHOT" beans = { ! xmlns siAmqp: 
 'http://www.springframework.org/schema/integration/amqp' ! ! siAmqp.'publish-subscribe-channel'(id: 'gorm://afterInsert') ! ! siAmqp.'publish-subscribe-channel'(id: 'gorm://afterDelete') ! ! siAmqp.'publish-subscribe-channel'(id: 'gorm://afterUpdate') ! ! }! 25
  • 26. grails-events-push •  And if you want to listen for events... in Javascript – Like Socket.IO or Vertx – Like a free bird – But not so free, prevent from listening everything – But which damn protocol using ?? 26
  • 27. grails-events-push ATMOSPHERE SAVES THE WORLD 27
  • 28. React on server side events 28
  • 31. grails-vertx •  No hands clustering – Using Vert.x Hazelcast support •  Super scalable events processor – Mom’ said Event loop is darn good at handling high concurrent load •  Deploying features as verticles – WIN for hot reloading plugins/services 31
  • 32. grails-vertx •  vertxService bean (vertx instance, container) •  Grails dedicated language factory: – Verticle Hot reloading – Classloader access 32
  • 34. Roadmaps •  Platform-Core – Work Queue / Point to Point eventing – Response Streaming •  Events-SI – Overridable listeners with Queue channels •  Events-Push – More on filtering – ... per request security (with PlatformCore security) 34
  • 35. Roadmaps •  Some more Vertx love: – Better integration – Specific DSL to manage verticles – SockJS support – request dispatching •  Vertx Back / Grails Front •  Vertx Front / Grails Back ? – Rename it Testx 35
  • 36. Demos! 36
  • 37. More info •  w: http://bit.ly/platform-core-docs •  w: http://github.com/smaldini •  Grails Todos source: https://github.com/smaldini/grailsTodos •  t: @smaldini 37