Event-driven plugins with Grails 3. Göran Ehrsson, Technipelago AB



Similar documents
CUT YOUR GRAILS APPLICATION TO PIECES

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

Server-side OSGi with Apache Sling. Felix Meschberger Day Management AG 124

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

Paul Boisvert. Director Product Management, Magento

Chapter 1 - Web Server Management and Cluster Topology

Apache Traffic Server Extensible Host Resolution

<Insert Picture Here> Michael Hichwa VP Database Development Tools Stuttgart September 18, 2007 Hamburg September 20, 2007

No.1 IT Online training institute from Hyderabad URL: sriramtechnologies.com

ActiveVOS Server Architecture. March 2009

Oracle WebLogic Server 11g Administration

Database Migration Plugin - Reference Documentation

Build management & Continuous integration. with Maven & Hudson

Grails 1.1. Web Application. Development. Reclaiming Productivity for Faster. Java Web Development. Jon Dickinson PUBLISHING J MUMBAI BIRMINGHAM

JBoss AS Administration Console User Guide. by Shelly McGowan and Ian Springer

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

Overview. About Interstitial Ads: About Banner Ads: About Offer-Wall Ads: ADAttract Account & ID

Course Description. Course Audience. Course Outline. Course Page - Page 1 of 5

A Tool for Evaluation and Optimization of Web Application Performance

Portal Factory CMIS Connector Module documentation

Crystal Reports for Eclipse

JavaFX Session Agenda

Running and Testing Java EE Applications in Embedded Mode with JupEEter Framework

SwiftScale: Technical Approach Document

Scala Actors Library. Robert Hilbrich

JSR-303 Bean Validation

1Z Oracle Weblogic Server 11g: System Administration I. Version: Demo. Page <<1/7>>

Automatic Configuration of Slave Nameservers (BIND only)

Intruduction to Groovy & Grails programming languages beyond Java

IBM WebSphere Server Administration

Dynamic website development using the Grails Platform. Joshua Davis Senior Architect Cognizant Technology Solutions

WebSphere Server Administration Course

New SMTP client for sending Internet mail

Terms and Definitions for CMS Administrators, Architects, and Developers

1z0-102 Q&A. DEMO Version

Group Mail Lists. Group Mailing Lists. Populating a Global Mail Lists 4. The Problem 6. The Solution 8. Scheduling Regular Updates 17

Eclipse 4 RCP application Development COURSE OUTLINE

ITG Software Engineering

A Comparative Study on Vega-HTTP & Popular Open-source Web-servers

Web Applications and Struts 2

OpenESB Standalone Edition V3.0 Web admin console

MarkLogic Server. Reference Application Architecture Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

IBM Tivoli Composite Application Manager for Microsoft Applications: Microsoft Internet Information Services Agent Version Fix Pack 2.

CIA Lab Assignment: Web Servers

RESTful web applications with Apache Sling

WebView addjavascriptinterface Remote Code Execution 23/09/2013

Apache Karaf in real life ApacheCon NA 2014

Clustering a Grails Application for Scalability and Availability

Apache James: more than s in the cloud. Ioan Eugen Stan Berlin Buzzwords 2012

Thomas Röthlisberger IT Security Analyst

<Insert Picture Here> Building a Complex Web Application Using ADF and Siebel

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

Enterprise Recipes with Ruby and Rails

Listeners. Formats. Free Form. Formatted

To install Multifront you need to have familiarity with Internet Information Services (IIS), Microsoft.NET Framework and SQL Server 2008.

LDAPCON Sébastien Bahloul

MS Enterprise Library 5.0 (Logging Application Block)

CS506 Web Design and Development Solved Online Quiz No. 01

ZooKeeper. Table of contents

Developing Android Apps with the ArcGIS Runtime SDK for Android. Dan

About Me. Software Architect with ShapeBlue Specialise in. 3 rd party integrations and features in CloudStack

Manage all your Office365 users and licenses

Big Data Pipeline and Analytics Platform

Jive Connects for Microsoft SharePoint: Troubleshooting Tips

Building native mobile apps for Digital Factory

This documentation is made available before final release and is subject to change without notice and comes with no warranty express or implied.

Basic TCP/IP networking knowledge of client/server concepts Basic Linux commands and desktop navigation (if don't know we will cover it )

05.0 Application Development

Customize Mobile Apps with MicroStrategy SDK: Custom Security, Plugins, and Extensions

Getting Started with Telerik Data Access. Contents

Configuring the Active Directory Plug-in

Developing modular Java applications

CiviCRM for Joomla! Integration, Best Practices, Extensions, and More. Jeremy Proffitt // Brian Shaughnessy

Hadoop 只 支 援 用 Java 開 發 嘛? Is Hadoop only support Java? 總 不 能 全 部 都 重 新 設 計 吧? 如 何 與 舊 系 統 相 容? Can Hadoop work with existing software?

EPiServer Operator's Guide

Building a Continuous Integration Pipeline with Docker

Drupal CMS for marketing sites

Multithreading and Java Native Interface (JNI)!

Introduction to BlackBerry Smartphone Web Development Widgets

Using Apache Derby in the real world

ANDROID BASED MOBILE APPLICATION DEVELOPMENT and its SECURITY

Database Extension 1.5 ez Publish Extension Manual

Cross-domain Identity Management System for Cloud Environment

VMware Server 2.0 Essentials. Virtualization Deployment and Management

Filter NEW IN FIRSTCLASS CLIENT WHAT S NEW IN FIRSTCLASS 9.0. New Look. Login screen. List View Sort Order. Filtering Containers.

Architectures for massive data management

Using MySQL for Big Data Advantage Integrate for Insight Sastry Vedantam

Administration Guide. BlackBerry Enterprise Service 12. Version 12.0

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

InfoSphere Master Data Management operational server v11.x OSGi best practices and troubleshooting guide

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Oracle EXAM - 1Z Oracle Weblogic Server 11g: System Administration I. Buy Full Product.

Expanded contents. Section 1. Chapter 2. The essence off ASP.NET web programming. An introduction to ASP.NET web programming

Spring 3.1 to 3.2 in a Nutshell. Sam Brannen Senior Software Consultant

ArcGIS for Server: Administrative Scripting and Automation

Jitterbit Technical Overview : Microsoft Dynamics CRM

Sample copy. Introduction To WebLogic Server Property of Web 10.3 Age Solutions Inc.

Transcription:

Event-driven plugins with Grails 3 Göran Ehrsson, Technipelago AB

Göran Ehrsson, @goeh Grails enthusiast Founded Technipelago 2006 Custom business applications 90% of customer base running Grails apps Main contributor to GR8 CRM plugin collection

Custom business applications (web & mobile) Different industries but common requirements Customers Projects Tasks / Calendar Documents

Grails Plugins Plugins extend the platform. A plugin can: extend the data model add services provide static resources add command line scripts do a lot more The plugin framework provides lots of extension points

Separation of Concern Each plugin should focus on one task or domain A plugin should be tested isolated from others Grails plugins make the boundaries strong and well defined. They force the developer to stay inside the box

Keep services and UI in separate plugins Put logic in the service layer, not in view controllers You may want to have different user interface plugins for different requirements The same service plugin can be used in both the web-front application and in back-office without exposing admin UI to web-front You can use the same service plugin in rich client or micro service style applications

Communicate with events Spring has built-in support for both synchronous and asynchronous application events Spring Integration includes advanced event support Grails 2 platform-core plugin includes great event handling (synchronous, asynchronous, event reply) Grails 3 includes event support based on the Reactor library

plugin-grails-events Core plugin included in the Grails 3 distribution Based on the Reactor library Not the same as the grails-events plugin by @smaldini

Reactor Reactor is a foundational library for building reactive fastdata applications on the JVM. You can use Reactor to power an application that has a low tolerance for latency and demands extremely high throughput. It s really fast. On a recent laptop with a dual-core processor, it's possible to process over 25,000,000 events per second in a single thread. It is an implementation of the Reactive Streams Specification.

Reactive Streams Reactive Streams is a standard and specification for Stream-oriented libraries for the JVM that; process a potentially unbounded number of elements in sequence asynchronously passing elements between components with mandatory non-blocking backpressure

Grails 3 Events API Grails events plugin statically injects Events API methods in Grails Controllers and Services using a trait called Events. You can implement this trait in other artefacts. Consume events on(key) { /* handle event */ Publish events notify(key, data) sendandreceive(key, data) { reply -> /* handle reply */ def event = eventfor(map headers, Object data) notify(key, event)

Spring Reactor Support @reactor.spring.context.annotation.consumer @reactor.spring.context.annotation.selector reactor.spring.context.annotation.selectortype SelectorType.OBJECT (default) SelectorType.REGEXP SelectorType.URI SelectorType.JSON_PATH

class WebOrderService { @Transactional void confirm(long id) { def orderinstance = WebOrder.get(id) if(orderinstance) { orderinstance.status = OrderStatus.CONFIRMED if(orderinstance.save()) { notify( order.confirmed, [order: id, email: orderinstance.customeremail]) render "Thank you for ordering!"

@Consumer class MyApplicationService { @Selector("order.confirmed") void sendconfirmationemail(event<map> event) { Map data = event.getdata() String subj = "Order confirmation" String text = parsetemplate("order.template", data) sendmail { to: data.email from: "info@company.com" subject: subj body: text

Selecting events based on regular expression @Selector(value = /(.+)\.created/, type = SelectorType.REGEX) void somethingwascreated(event<object> event) { println "${event.headers.group1 was just created"

Event replies Consumers should return void and use event.reply(data) to reply results back to the sender. def userlist(string department) { List result = [] CountDownLatch latch = new CountDownLatch(1) sendandreceive("user.list", department) { Event reply -> result = reply.data latch.countdown() latch.await(5, TimeUnit.SECONDS) [list: result]

Transactions class WebOrderService { @Transactional void confirm(long id) { def orderinstance = WebOrder.get(id) if(orderinstance) { orderinstance.status = OrderStatus.CONFIRMED if(orderinstance.save()) { notify( order.confirmed, [order: id, email: orderinstance.customeremail]) render "Thank you for ordering!"

Transaction bound events Spring 4.2 (planned release July 2015) will have the ability to bind event listeners to a phase of the transaction. Unfortunately Spring's application events are not based on Reactor, so we will still have two different event implementations in Grails.

Send event after commit @Transactional WebOrder createorder() { final WebOrder orderinstance = new WebOrder() // populate order items and save. aftercommit { notify( order.created', orderinstance.id) return orderinstance private void aftercommit(final Closure task) { TransactionSynchronizationManager.registerSynchronization( new TransactionSynchronizationAdapter() { @Override void aftercommit() { task() )

Migrating from Grails 2 to Grails 3 Grails 3.0 is a complete ground up rewrite of Grails and introduces new concepts and components for many parts of the framework. Based on Spring Boot Gradle is now used to build your Grails application Project structure differences File location differences Configuration differences Package name differences Legacy Gant Scripts Changes to Plugins See https://grails.github.io/grails-doc/latest/guide/upgrading.html

Migrating plugins The plugin descriptor which was previously located in the root of the plugin directory should be moved to the src/main/groovy directory under an appropriate package Same file structure changes as with applications It s recommended to publish public/official plugins to Bintray

migrate2-grails3 plugin The migrate2-grails3 plugin performs a partial migration of a Grails 2 plugin or app to Grails 3 gvm use grails (latest 3.x version) grails create-plugin myplugin gvm use grails (your 2.x plugin/application version) BuildConfig.groovy in the Grails 2.x project: compile :migrate2-grails3:<latest version>" grails migrate../../grails3/myplugin

Migrating from platform-core events to Grails 3 (reactor) events // Publishing events with platform-core event(for: "order", topic: confirmed", data: [order: order.id, email: customeremail]) // Publishing events with Grails 3 notify( order.confirmed", [order: order.id, email: customeremail])

Migrating from platform-core events to Grails 3 (reactor) events // Consuming events with platform-core class FooService { @Listener(namespace = "order", topic = "confirmed") def sendconfirmationemail(data) {... // Consuming events with Grails 3 @Consumer class FooService { @Selector("order.confirmed") def sendconfirmationemail(event<map> event) {...

Plugin authors Start your migration engines!

Misc caveats pluginexcludes does not work the same way in Grails 3.0.1. But you can add jar excludes in build.gradle instead. jar { exclude "com/demo/**/**" exclude "demo/**"

Misc caveats If domain mapping declares 'cache' options you must add cache region factory in application.yml. static mapping = { cache 'nonstrict-read-write' hibernate: cache: use_second_level_cache: true provider_class: net.sf.ehcache.hibernate.ehcacheprovider region: factory_class: org.hibernate.cache.ehcache.ehcacheregionfactory

GR8 CRM gr8crm.github.io 40+ Grails plugins for rapid development of customer relationship management applications crm-contact & crm-contact-ui crm-content & crm-content-ui crm-task & crm-task-ui crm-campaign & crm-campaign-ui All GR8 CRM plugins are open source with the Apache 2.0 License crm-sales & crm-sales-ui crm-product & crm-product-ui crm-blog & crm-blog-ui

gr8crm.github.io github.com/goeh github.com/technipelago grails.org/plugin/migrate2-grails3 projectreactor.io @goeh goran@technipelago.se www.technipelago.se linkedin.com/in/gehrsson