have you seen spring lately?

105
Josh Long (之春) @starbuxman joshlong.com [email protected] slideshare.net/joshlong github.com/joshlong http://spring.io HAVE YOU SEEN LATELY? http://joshlong.github.io/have-you-seen-spring-lately/

Upload: josh-long

Post on 10-May-2015

2.943 views

Category:

Technology


12 download

DESCRIPTION

It's been an amazing year for Spring! 2013 saw the Spring family join Pivotal where - along with Cloud Foundry and our data driven technologies (the Pivotal HD Hadoop distribution, the GemFire data grid, and the RabbitMQ message broker) - Spring supports today's application workloads and profiles. Today's Spring embraces Java 8, Scala, Groovy, provides a best-in-class REST stack, supports the open web, mobile applications, big-data applications and batch workloads. Today's Spring is easy to get started with, easy to learn, and embraces conventions over configuration. Today's Spring is part of the Spring.IO platform. Today's Spring is...Pivotal. Join Spring developer advocate Josh Long as he re-introduces you to today's Spring, a Spring you may not have seen yet. There is a video for this talk, as well: http://www.youtube.com/watch?v=_twyZL_AGCI - Enjoy!

TRANSCRIPT

Page 1: Have You Seen Spring Lately?

Josh Long (⻰龙之春) @starbuxman joshlong.com

[email protected] slideshare.net/joshlong

github.com/joshlong http://spring.io

H AV E Y O U S E E N L AT E LY ?

http://joshlong.github.io/have-you-seen-spring-lately/

Page 2: Have You Seen Spring Lately?

I AM…

Spring Developer AdvocateJosh Long (⻰龙之春)

@starbuxman [email protected] |

Jean Claude van Damme! Java mascot Duke some thing’s I’ve authored...

Page 3: Have You Seen Spring Lately?

THE SPRING IO PLATFORM (SOME “MARCHITECTURE”)

Deploy to Cloud or on premise

Big, Fast,

Flexible Data Web,

Integration, Batch

CoreModel

GemFire

Page 4: Have You Seen Spring Lately?

THE SPRING IO PLATFORM (SOME ARCHITECTURE)

WEB

Controllers, REST,WebSocket

INTEGRATION

Channels, Adapters,Filters, Transformers

BATCH

Jobs, Steps,Readers, Writers

BIG DATA

Ingestion, Export,Orchestration, Hadoop

DATA

NON-RELATIONALRELATIONAL

CORE

GROOVYFRAMEWORK SECURITY REACTOR

GRAILS

Full-stack, Web

XD

Stream, Taps, Jobs

BOOT

Bootable, Minimal, Ops-Ready

Page 5: Have You Seen Spring Lately?

SPRING.IO

Page 6: Have You Seen Spring Lately?

SPRING.IO

Page 7: Have You Seen Spring Lately?

SPRING.IO

Page 8: Have You Seen Spring Lately?

SPRING.IO

Page 9: Have You Seen Spring Lately?

SPRING.IO

Page 10: Have You Seen Spring Lately?

SPRING.IO IS BEST-PRACTICES ORIENTED

Page 11: Have You Seen Spring Lately?

WE’RE ON GITHUB

Page 12: Have You Seen Spring Lately?

SPRING BOOT IS ABOUT PRODUCTIVITY

Boot

Autoconfigure

Starters

CLI

Actuator

Tools

Samples

Bootstrap your productivity

Page 13: Have You Seen Spring Lately?

i

SPRING BOOT IS CONCISE (AND TWEETABLE!)

Page 14: Have You Seen Spring Lately?

D E M O : A G R O O V Y B O O T A P P

Page 15: Have You Seen Spring Lately?
Page 16: Have You Seen Spring Lately?

D E M O : B O O T, G E T T I N G S TA R T E D G U I D E S , & S T S

Page 17: Have You Seen Spring Lately?
Page 18: Have You Seen Spring Lately?

SPRING LOVES THE JVM

Spring loves the JVM: Java (5,6,7, and 8), Groovy, Scala, etc.

Page 19: Have You Seen Spring Lately?

SPRING SCALA

val applicationContext = new FunctionalConfigApplicationContext( classOf[ServiceConfiguration]) !// ServiceConfiguration.scala class ServiceConfiguration extends FunctionalConfiguration { importClass(classOf[DataSourceConfiguration]) ! val dataSource : DataSource = getBean(“dataSource”) ! val jdbcTemplate = bean() { new JdbcTemplate( dataSource ) } val jdbcTransactionManager = bean(“txManager”) { new JdbcTransactionManager(dataSource) } }

Scala

Page 20: Have You Seen Spring Lately?

GROOVY BEAN BUILDER

def bb = new BeanBuilder() bb.loadBeans("classpath:*SpringBeans.groovy") def applicationContext = bb.createApplicationContext()

! // MySpringBeans.groovy import o.sf.jdbc.core.JdbcTemplate import o.sf.jdbc.datasource.DataSourceTransactionManager !beans { ! jdbcTemplate(JdbcTemplate) { dataSource = dataSource } ! transactionManager(DataSourceTransactionManager) { dataSource = dataSource } } !

Groovy

Page 21: Have You Seen Spring Lately?

JAVA CONFIGURATION

ApplicationContext applicationContext = new AnnotationConfigApplicationContext( ServiceConfiguration.class); !!// ServiceConfiguration.java @Configuration @ComponentScan @Import(DataSourceConfiguration.class) @EnableTransactionManagement class ServiceConfiguration { @Bean public JdbcTemplate jdbcTemplate(DataSource dataSource) throws Exception { return new JdbcTemplate( dataSource ); } ! @Bean public PlatformTransactionManager jdbcTransactionManager(DataSource dataSource){ return new JdbcTransactionManager (dataSource ); } }

Java

Page 22: Have You Seen Spring Lately?

SPRING 4 IS JAVA 8 READY

Java 8a quick note on Delayed again! from 09/2013 to as late as 03/2014!

!Meanwhile, even has lambas...

...C++

Page 23: Have You Seen Spring Lately?

BUT ARE THE IDES JAVA 8 READY?

Java 8a quick note on IDE Support:

IntelliJ IDEA has had Java 8 support for a year Eclipse won’t have any until June 2014 (..!!) Eclipse-based Spring Tool Suite (STS) has beta Java 8 support. !!

Page 24: Have You Seen Spring Lately?

JAVA 8 METHOD REFERENCES ARE A GREAT FIT FOR SPRING

Java 8a quick note on Spring 4.0 to be GA against Developer Preview by end of 2013.

!Method references are a great fit for Spring!

JdbcTemplate jdbcTemplate; !// method references private Customer map(ResultSet rs, int rowNum) throws SQLException { return new Customer( rs.getString("name"), rs.getInt("age") ); } !// let it satisfy the `RowMapper` functional interface Customer customer = jdbcTemplate.queryForObject( "select name, age from customers ", this::map);

Page 25: Have You Seen Spring Lately?

JAVA 8 LAMBAS ARE A GREAT FIT FOR SPRING

Java 8a quick note on Spring 4.0 to be GA against Developer Preview by end of 2014.

!lambas are a great fit for Spring and Twitter!

Page 26: Have You Seen Spring Lately?

SPRING 4 AND JAVA 8

Java 8a quick note on JSR-310 - Date and Time

// declarative date format import java.time.*; import org.springframework.format.annotation.*; !public class Customer { ! @DateTimeFormat(iso=ISO.DATE) private LocalDate birthDate; ! @DateTimeFormat(pattern="M/d/yy h:mm") private LocalDateTime lastContact; !}

Page 27: Have You Seen Spring Lately?

SPRING 4 AND JAVA 8

Java 8a quick note on Repeatable Annotations

@Scheduled(cron = "0 0 12 * * ?") @Scheduled(cron = "0 0 18 * * ?") public void performTempFileCleanup() { ... }

Page 28: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

dumb clients roamed the earth... like dinosaurs

LET’S TURN OUR GAZE TO A TIME, LONG AGO, WHEN…

Page 29: Have You Seen Spring Lately?

1989magic happens: Tim Berners Lee & Robert Cailliau create the world wide web

THEN MAGIC HAPPENED…

Page 30: Have You Seen Spring Lately?

WE TRIED TO ‘FIX’ HTTP. THIS REMINDS ME OF A STORY…

Page 31: Have You Seen Spring Lately?

FINALLY, WE GOT OUR ACT TOGETHER

Page 32: Have You Seen Spring Lately?

JAVASCRIPT BOOTS LINUX!

Page 33: Have You Seen Spring Lately?

when someone uses SOAP because it’s “simple”

SO HOW DO OUR SMART CLIENTS CONNECT TO OUR SERVICES?

Page 34: Have You Seen Spring Lately?

USE REST, OF COURSE!

!• URI’s identify resources • HTTP verbs describe a limited set of operations that can be used to manipulate

a resource – GET – DELETE – PUT – POST – less used other verbs

• Headers help describe the messages

REST Is..

Page 35: Have You Seen Spring Lately?

WHAT IS REST? (…BABY DON’T HURT ME, NO MORE…)

Level 0: swamp of POXUses HTTP mainly as a tunnel through one URI e.g., SOAP, XML-RPC Usually features on HTTP verb (POST)

The Richardson Maturity Model

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 36: Have You Seen Spring Lately?

LEVEL 1: URIS TO DISTINGUISH NOUNS

Level 1: resourcesMultiple URIs to distinguish related nouns e.g., /articles/1, /articles/2, vs. just /articles

The Richardson Maturity Model

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 37: Have You Seen Spring Lately?

LEVEL 2: GROUND ZERO USING SPRING MVC

Level 2: HTTP verbs leverage transport-native properties to enhance service e.g., HTTP GET and PUT and DELETE and POSTUses idiomatic HTTP controls like status codes, headers

The Richardson Maturity Model

http://martinfowler.com/articles/richardsonMaturityModel.html

Page 38: Have You Seen Spring Lately?

TANGENT: A QUICK PRIMER ON SPRING MVC

DispatcherServlet controller

view template

delegate request

delegate rendering of

response

render response

return control

model

model

incoming requests

return response

Page 39: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

import static ...RequestMethod.* ; import static ...MediaType.* ; !@RestController @RequestMapping (value = “/users/”) class UserController { ! @RequestMapping (method = DELETE, value = “/{user}”) User delete(@PathVariable Long user) { return crmService.removeUser(user); } @RequestMapping (method = GET, value = “/{user}”) User read(@PathVariable Long user) { return crmService.findById(user); } .. }

Page 40: Have You Seen Spring Lately?

D E M O : B U I L D I N G R E S T W E B S E R V I C E S

Page 41: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Page 42: Have You Seen Spring Lately?

LEVEL 3: HATEOAS, OR THE UNPRONOUNCEABLE ACRONYM

Level 3: Hypermedia Controls (aka, HATEOAS) No a priori knowledge of service requiredNavigation options are provided by service and hypermedia controlsPromotes longevity through a uniform interface

The Richardson Maturity Model

http://martinfowler.com/articles/richardsonMaturityModel.html http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

Page 43: Have You Seen Spring Lately?

METADATA == LINKS

Level 3: Hypermedia Controls (aka, HATEOAS) Links provide possible navigations from a given resource Links are dynamic, based on resource state. !<link href=“http://...:8080/users/232/customers” rel= “customers”/>

The Richardson Maturity Model

http://martinfowler.com/articles/richardsonMaturityModel.html http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

Page 44: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

import static ...RequestMethod.* ; import static ...MediaType.* ; !@RestController @RequestMapping (value = “/users/” ) class UserController { ! @Inject ResourceAssembler<User, Resource<User>> userResourceAssembler; ! @RequestMapping (method = DELETE, value = “/{user}”) Resource<User> delete(@PathVariable Long user) { return userResourceAssembler.toResource( crmService.removeUser(user) ); } @RequestMapping (method = DELETE, value = “/{user}”) Resource<User> read(@PathVariable Long user) { return userResourceAssembler.toResource( crmService.findById(user)); } .. }

Page 45: Have You Seen Spring Lately?

REST DESIGN WITH SPRING!@Component class UserResourceAssembler implements ResourceAssembler<User, Resource<User>> { ! public Resource<User> toResource(User user) { Resource<User> userResource = new Resource<User>(user); Collection<Link> links = new ArrayList<Link>(); ! Link toPhoto = linkTo( methodOn(UserProfilePhotoController.class) .loadUserProfilePhoto( user.getId() )) .withRel(“photos”); Link toSelf = linkTo( methodOn( UserController.class)) .loadUser( user.getId() )) .withSelfRel(); Resource<User> userResource = new Resource<User>(user, Arrays.asList(toSelf, toPhoto));

Page 46: Have You Seen Spring Lately?

D E M O : E M B R A C I N G H Y P E R M E D I A

Page 47: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Page 48: Have You Seen Spring Lately?

SPRING’S WEBSOCKETS SUPPORT

WebSockets delegating to implementations on app servers like GlassFish, Tomcat, and Jetty !Supports Sock.js server, superset of WS. !higher level STOMP supported on WS !supports JSR 356 (javax.websocket.*) support.

Page 49: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Handling WebSocket Subscription@Controller class PortfolioController { … @MessageMapping("/app/trade") void handleTradeOrder(Trade trade, Principal principal) { trade.setUsername(principal.getName()); tradeService.executeTrade(trade); }   @SubscribeEvent("/app/positions") List<PortfolioPosition> subscribeToPortfolios(Principal principal) {     String user = principal.getName();     Portfolio portfolio = portfolioService.findPortfolio(user);     return portfolio.getPositions(); } }

Page 50: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Handling Messages Over STOMP!@Controller public class GreetingController { ! // Mapping based on "destination" header ! @MessageMapping("/greeting") @SendTo("/topic/greetings") public String greet(@MessageBody String greeting) { return "[" + getTimestamp() + "]: " + greeting; } !}

Page 51: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Configuring a STOMP WebSocket broker@Configuration @EnableWebSocketMessageBroker public class Config implements WebSocketMessageBrokerConfigurer { !! @Override public void registerStompEndpoints(StompEndpointRegistry r) { r.addEndpoint("/portfolio"); // WebSocket URL prefix } ! @Override public void configureMessageBroker(MessageBrokerConfigurer c) { c.enableSimpleBroker("/topic/"); // destination prefix } !}

Page 52: Have You Seen Spring Lately?

D E M O : W E B S O C K E T S

Page 53: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Page 54: Have You Seen Spring Lately?

SECURITY

• OAuth • sign in / out & “Remember Me” support • Kerbreros • CAS • pam • ActiveDirectory / LDAP • Encryption (TLS/SSL integration) • x509 certificates • OpenID

Spring Security is a modern security framework for a modern age !

Page 55: Have You Seen Spring Lately?

SECURITY

Spring Security is a modern security framework for a modern age !

Authentication is valid?

Authentication Mechanism

collects the details

client submits authentication

credentials

Store Authentication in SecurityContextHolder

No - retry!

Yesprocess original request

Page 56: Have You Seen Spring Lately?

SECURITY

Spring Security is a modern security framework for a modern age !

Authentication is valid?

Authentication Mechanism

collects the details

client submits authentication

credentials

Store Authentication in SecurityContextHolder

No - retry!

Yesprocess original request

Authentication Mechanism collects the details!!AuthenticationRequest is sent to AuthenticationManager!!(passes it through a chain of AuthenticationProviders)!!AuthenticationProvider asks a UserDetailsService for a UserDetails!!The UserDetails object is used to build an Authentication object!!!

Page 57: Have You Seen Spring Lately?

SECURITY

Spring Security features a clean Java configuration API

!@Configuration @EnableWebSecurity class SecurityConfig extends WebSecurityConfigurerAdapter { ! @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user").password("password").roles("USER"); } ! @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/").permitAll() .antMatchers("/api/*").authenticated(); http.formLogin() .loginPage("/login") .passwordParameter("pw") .usernameParameter("user"); http.x509(); } }

Page 58: Have You Seen Spring Lately?

A CONNECTED WORLD WITH SPRING SOCIAL

3125 photos uploaded 7630

messages sent

7610 searches 2MM

videos viewed

2000 checkins

175k tweets

1090 visitors

700k messages sent

* source: visual.ly/60-seconds-social-media

A Connected World in 00:60 seconds

Page 59: Have You Seen Spring Lately?

CONNECTING USING OAUTH

Page 60: Have You Seen Spring Lately?

REST DESIGN WITH SPRINGCONNECTING USING OAUTH

Page 61: Have You Seen Spring Lately?

REST DESIGN WITH SPRINGCONNECTING USING OAUTH

Page 62: Have You Seen Spring Lately?

SPRING SOCIAL’S THIRD PARTY APIS

Page 63: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

@Configuration @EnableJdbcConnectionRepository @EnableFacebook(appId="${facebook.clientId}", appSecret="${facebook.clientSecret}") @EnableTwitter(appId=“${twitter.consumerKey}", appSecret="${twitter.consumerSecret}") @EnableLinkedIn(appId="${linkedin.consumerKey}", appSecret="${linkedin.consumerSecret}") public class SocialConfig { // ...

Setting up Spring Social

Page 64: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Setting up Spring Social@Controller class FacebookFriendsController { ! @Inject Facebook facebook; ! @RequestMapping(value="/facebook/friends", method=GET) public String showFeed(Model model) { model.addAttribute("friends", facebook.friendOperations().getFriendProfiles()); return "facebook/friends"; } } !

Page 65: Have You Seen Spring Lately?

D E M O : C O N N E C T I N G A P P L I C AT I O N S T O U S E R S W I T H S P R I N G S O C I A L

Page 66: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Page 67: Have You Seen Spring Lately?

MOBILE FIRST APPLICATIONS

http://www.idc.com/getdoc.jsp?containerId=prUS24257413

units (in millions) of units of each type of platform shipped

2Q 2012

2Q 2013

0 50 100 150 200

Linux PhoneBlackBerrySymbianWindows MobileiOSAndroid

Page 68: Have You Seen Spring Lately?

MOBILE FIRST APPLICATIONS

Spring Android brings Spring core’s RestTemplate. Spring Social and Spring HATEOAS work as well.

Page 69: Have You Seen Spring Lately?

D E M O : S M A R T E R M O B I L E C L I E N T S

Page 70: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Page 71: Have You Seen Spring Lately?

SPRING SUPPORTS JAVA EE

Spring works well in Java EE environments !Supports Java EE 7: Date/Time API, JTA 1.2, JMS 2.0, JPA 2.1, Bean Validation 1.1, the new concurrency API in JSR-236, Servlet 3.1, and WebSockets (JSR 356) !Even participated in a few JSRs: the websocket JSR (356) and the Batch JSR (352)

Page 72: Have You Seen Spring Lately?

SPRING WORKS WELL IN THE CLOUD

Page 73: Have You Seen Spring Lately?

SPRING PROFILES MAKE IT EASY TO ADAPT

@Configuration @Profile("cloud") public class CloudConfig { ! @Bean public Cloud cloud() throws CloudException { CloudFactory cloudFactory = new CloudFactory(); return cloudFactory.getCloud(); }   @Bean public DataSource dataSource() {             return cloud().getSingletonServiceConnector(DataSource.class, null);        } }

Page 74: Have You Seen Spring Lately?

YOU MIGHT CHECK OUT, FOR EXAMPLE, THE SPRING MUSIC APP

Page 75: Have You Seen Spring Lately?

CLOUD FOUNDRY COMES WITH BATTERIES INCLUDED

Page 76: Have You Seen Spring Lately?

…AND A RICH ECOSYSTEM OF THIRD PARTY INTEGRATIONS

Page 77: Have You Seen Spring Lately?

SPRING IS THE LEADING COMPONENT MODEL

0 15 30 45 60

GlassfishWebsphereWebLogicJBossJettyApache Tomcat

% of survey of 1800 Java developers.

Multiple choices.

Source: ZeroTurnaround Developer Productivity Report 2012

Page 78: Have You Seen Spring Lately?

SPRING INTEGRATION MAKES EIP EASY

• hard to get right • patterned after “EIP book” patterns • supports numerous adapters and gateways for external

systems

Integration !

Page 79: Have You Seen Spring Lately?

AVOID RUBE GOLDBERG MACHINES

Page 80: Have You Seen Spring Lately?

BATCH AND INTEGRATION

<?xml version="1.0" encoding="UTF-8"?> <beans ...> ! <int:channel id="jobsToLaunch"/> <int:channel id="filesReceived"/> <int:channel id="jobExecutions"/> ! <file:inbound-channel-adapter auto-create-directory="true" channel="filesReceived" directory="#{systemProperties['user.home']}/Desktop/in"> <int:poller fixed-rate="1000"/> </file:inbound-channel-adapter> ! <int:transformer ref="fileBatchJobRequestTransformer" input-channel="filesReceived" output-channel="jobsToLaunch"/> ! <int:service-activator input-channel="jobsToLaunch" ref="jobMessageHandler" output-channel="jobExecutions"/> ! <stream:stdout-channel-adapter id="jobsPrinted" append-newline="true" channel="jobExecutions"/> !</beans>

Page 81: Have You Seen Spring Lately?

BATCH AND INTEGRATION

@Configuration @Import(BatchConfiguration.class) @ComponentScan @ImportResource("/com/joshlong/spring/walkingtour/services/integration/context.xml") class IntegrationConfiguration { ! @Bean JobLaunchingMessageHandler jobMessageHandler( JobLauncher jobLauncher) throws Exception { return new JobLaunchingMessageHandler(jobLauncher); } !}

Page 82: Have You Seen Spring Lately?

BATCH AND INTEGRATION

• avoids idle computing resources • allows the system to use different priorities for batch and

interactive work • supports numerous sinks and sources • supports JSR 352 - Batch Applications

Batch Processing... !

Page 83: Have You Seen Spring Lately?

BATCH AND INTEGRATION

Page 84: Have You Seen Spring Lately?

BATCH AND INTEGRATION

Job Step

JobInstance step scope

JobExecution StepExecution

*

*

**

reader, processor?, writer

Page 85: Have You Seen Spring Lately?

BATCH AND INTEGRATION

@Bean Job customerLoaderJob( JobBuilderFactory jobs, Step csvToRDBMS ) { return jobs.get(“customerLoaderJob”) .flow(csvToRDBMS).end().build(); } ! @Bean Step csvToRDBMS( StepBuilderFactory stepBuilderFactory, PlatformTransactionManager platformTransactionManager, ItemReader <Customer> itemReader, ItemProcessor <Customer, Customer> itemProcessor, ItemWriter <Customer> itemWriter) { ! StepBuilder builder = stepBuilderFactory.get(“csvToRDBMS”); ! return builder.<Customer, Customer>

chunk(3) .reader(itemReader) .processor(itemProcessor) .writer(itemWriter) .transactionManager(platformTransactionManager) .build(); } !

JdbcBatchItemWriter

FlatFileItemReader

Page 86: Have You Seen Spring Lately?

D E M O : U S I N G S P R I N G B AT C H & I N T E G R AT I O N

Page 87: Have You Seen Spring Lately?
Page 88: Have You Seen Spring Lately?

SPRING SUPPORTS ALL THE DATA!

Spring supports all the SQLs: NoSQL, NOSQL, and SQL !

Page 89: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

!import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.repository.annotation.RestResource; !import java.util.List; !@RestResource (path = "users", rel = "users") public interface UserRepository extends PagingAndSortingRepository<User, Long> { !

// select * from users where username = ? User findByUsername(@Param("username") String username); !// select * from users where firstName =? or lastName = ? or username = ? List<User> findUsersByFirstNameOrLastNameOrUsername( @Param("firstName") String firstName, @Param("lastName") String lastName, @Param("username") String username); !

}

Page 90: Have You Seen Spring Lately?

PROJECT REACTOR

The future is Reactive ! Reactor: foundational

library. Drives drivers, servers, data integration libraries, domain integration libraries, and evented architectures !Used in: Spring Integration, websocket => STOMP support, Grails, etc.

Page 91: Have You Seen Spring Lately?

PROJECT REACTOR

Environment env = new Environment(); !Reactor reactor = Reactors.reactor() .env(env) .dispatcher(RING_BUFFER) .get(); !reactor.on($(“topic”), (Event<String> ev) -> { System.out.println(“Hello “ + ev.getData()); }); !reactor.notify(“topic”, Event.wrap(“John Doe”));

without SpringThreadPoolExecutorDispatcher BlockingQueueDispatcher … RingBufferDispatcher

Page 92: Have You Seen Spring Lately?

PROJECT REACTOR

@EnableReactor @Configuration @ComponentScan class ReactorConfiguration { ! @Bean Reactor reactor(Environment env) { return Reactors.reactor().env(env) .dispatcher( Environment.RING_BUFFER) .get(); } }

@Component class EvenConsumer { ! @Selector("test.topic") public void onTestTopic(String s) { log.info("onTestTopic: {}", s); } } !@Service class EventPublisher { ! @Autowired Reactor reactor; public void fire(String msg) { reactor.notify( "test.topic", Event.wrap( msg )); } }

with Spring

Page 93: Have You Seen Spring Lately?

PROJECT REACTOR

Stream <String> str = …; !str.map(String::toUpperCase) .filter(new Predicate<String>() { public boolean test(String s) { … } }) .consume(s → log.info(“consumed string {}”, s));

Streams like Netflix RxJava Observable, JDK 8 Stream

Page 94: Have You Seen Spring Lately?

PROJECT REACTOR

Did I mention it’s fast?

https://github.com/reactor/reactor-si-quickstart

Page 95: Have You Seen Spring Lately?

SPRING WORKS WELL WITH

Surviving the Big Data Wild-West with Spring for Hadoop

Page 96: Have You Seen Spring Lately?

Getting Data into the System is Hard@metamarkets founder Michael E. Driscoll:

SPRING XD AND STREAM PROCESSING

Page 97: Have You Seen Spring Lately?

SPRING XD AND STREAM PROCESSING

Introducing Spring XD

sour

ces

sink

s

xd:> stream create --definition "time | log" --name ticktock

Page 98: Have You Seen Spring Lately?

D E M O : S P R I N G F O R H A D O O P A N D S P R I N G X D

Page 99: Have You Seen Spring Lately?

REST DESIGN WITH SPRING

Page 100: Have You Seen Spring Lately?

S O M E S P R I N G U S E R S

Page 101: Have You Seen Spring Lately?

“ ”

* source: http://www.infoq.com/news/2012/12/interview-taobao-tmall

http://spring.io/blog/2013/03/04/spring-at-china-scale-alibaba-group-alipay-taobao-and-tmall/

on 11/11/2012 (the “Double Sticks” promotion day), Tmall and Taobao witnessed 147 million user visits, purchases of 30 million people and nearly 100 million paid orders. At 0:00, more than 10 million users were concurrently online

china

Page 102: Have You Seen Spring Lately?

Spring and RabbitMQ: powering India’s 1.2 B Person Biometric DB

• 1.2 billion residents • ~75% literacy • less than 3% pay incomes taxes • less than 20% banking • 800 million mobile, ~200-300 million migrant

workers !

• Government spends about $25-40 billion on direct attributes • residents have no standard identity • most programs plagued with ghost and multiple

identities causing leakage of 30-40%

india

Page 103: Have You Seen Spring Lately?

• traded on JASDAQ • largest Java consultancy in Japan • Spring Batch

– handles customer profile information and real-time ad matching system

• Spring is agile enabler – production control system – just-in-time production is really the heart of manufacturing – cost decreased 30%

japan

Page 104: Have You Seen Spring Lately?

• 1.3 billion people in China • Google is either mostly blocked or - from Hong

Kong - very slow !

• Baidu has its own Android operating system, cloud services (like GMail, Dogs, etc.) !

• Built micro service architecture that builds on top of Spring !

• Custom web frameworks using Spring XML namespaces as global integration API

china

Page 105: Have You Seen Spring Lately?

Any Questions

@starbuxman @springcentral [email protected]

[email protected] github.com/joshlong

slideshare.net/joshlong

?

http://blog.gopivotal.com/products/have-you-seen-spring-lately