Top Banner
Composable Software Architecture with Spring Sam Brannen @sam_brannen Java Breeze | Odessa, Ukraine | 18 May 2013
75
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Composable Software Architecture with Spring

Composable Software Architecture with Spring Sam Brannen @sam_brannen

Java Breeze | Odessa, Ukraine | 18 May 2013

Page 2: Composable Software Architecture with Spring

2

Sam Brannen

•  Spring and Java Consultant @ Swiftmind (Zurich)

•  Developing Java for over 15 years

•  Spring Framework Core Committer since 2007

•  Spring Trainer •  Presenter on Spring, Java, OSGi, and testing

Page 3: Composable Software Architecture with Spring

3

Swiftmind

Your experts for Enterprise Java Areas of expertise •  Spring Framework •  Java EE •  OSGi •  Agile Methodologies •  Software Engineering Best Practices

Headquarters •  Zurich, Switzerland •  @swiftmind •  http://www.swiftmind.com

Page 4: Composable Software Architecture with Spring

4

Agenda

•  Enterprise Applications

•  What we’ve learned as a community

•  Composable Software Architecture

•  Java EE + Open Source •  How Spring fits into the picture

•  Spring 4.0 Roadmap

Page 5: Composable Software Architecture with Spring

5

Modern Enterprise Applications

Page 6: Composable Software Architecture with Spring

6

What does "enterprise" mean?

Enterprise software is software used in organizations, such as in a business or government, as opposed to software used by individuals. Enterprise software is an integral part of a (computer based) Information System. -Wikipedia

Page 7: Composable Software Architecture with Spring

7

OK, sure... but what does that mean to developers?

Page 8: Composable Software Architecture with Spring

8

Furthermore …

Enterprise software typically has interfaces to other enterprise software and is centrally managed. - Wikipedia

Page 9: Composable Software Architecture with Spring

9

Ahh, now we’re getting somewhere!

Page 10: Composable Software Architecture with Spring

10

Typical Enterprise Application

•  Supports enterprise business process

•  Is relatively large

•  Should be robust, scalable, and offer high performance

•  Does not run in isolation

•  Interacts with multiple external systems and services …

Page 11: Composable Software Architecture with Spring

11

RDBMS

Page 12: Composable Software Architecture with Spring

12

LDAP

Page 13: Composable Software Architecture with Spring

13

SMTP

Page 14: Composable Software Architecture with Spring

14

FTP, FTP, SSH

Page 15: Composable Software Architecture with Spring

15

JMS, AMQP

Page 16: Composable Software Architecture with Spring

16

SOAP Web Services, REST Web Services

Page 17: Composable Software Architecture with Spring

17

Web and Mobile clients, etc.

Page 18: Composable Software Architecture with Spring

18

But each of these has its own APIs and potentially different protocols and exchange formats!

Page 19: Composable Software Architecture with Spring

19

So how should we design such enterprise applications?

Page 20: Composable Software Architecture with Spring

20

What we’ve learned as a community

Page 21: Composable Software Architecture with Spring

21

Things to avoid

•  Tight coupling to the container or frameworks

•  Tight coupling to protocols and exchange formats in our service layer

•  Monolithic deployment units

•  Anemic domain models

•  Bloated transaction scripts

•  Code tangling and scattering

Page 22: Composable Software Architecture with Spring

22

What we should aim for

•  Modularity

•  Layered architecture with –  a canonical domain model –  a dedicated orchestration layer

•  Separation of concerns

•  Externalized environment-specific configuration •  Design for testability

Page 23: Composable Software Architecture with Spring

23

How we achieve it

•  OOA / OOD / OOP

•  (@)POJO Programming Model

•  Marshaling and automatic type conversion

•  Dependency Injection (DI)

•  Inversion of Control (IoC)

•  AOP / Interceptor Model

•  Automated out-of-container testing and CI

Page 24: Composable Software Architecture with Spring

24

Composable Software Architecture

Page 25: Composable Software Architecture with Spring

25

Composability

Composability is a system design principle that deals with the inter-relationships of components. A highly composable system provides recombinant components that can be selected and assembled in various combinations to satisfy specific user requirements. (Wikipedia) •  Self-contained (modular) •  Typically stateless

Page 26: Composable Software Architecture with Spring

26

But it's not just about modularity and statelessness.

Page 27: Composable Software Architecture with Spring

27

It's a different way of thinking,

Page 28: Composable Software Architecture with Spring

28

a different way of designing,

Page 29: Composable Software Architecture with Spring

29

a different kind of architecture,

Page 30: Composable Software Architecture with Spring

30

with new possibilities…

Page 31: Composable Software Architecture with Spring

31

if done right.

Page 32: Composable Software Architecture with Spring

32

Think about different ways the same components can be...

Page 33: Composable Software Architecture with Spring

33

reused…

Page 34: Composable Software Architecture with Spring

34

repurposed…

Page 35: Composable Software Architecture with Spring

35

and composed…

Page 36: Composable Software Architecture with Spring

36

to meet different business requirements

Page 37: Composable Software Architecture with Spring

37

or to interact with different systems.

Page 38: Composable Software Architecture with Spring

38

Composable Architecture Visualized

Infrastructure

Repository

Service

Orchestration

Dom

ain

Mod

el

Page 39: Composable Software Architecture with Spring

39

How is this new?

•  To be honest, it’s not really new, –  if you just look at the diagram…

•  The web tier or presentation layer has always effectively been a type of orchestration layer.

•  The difference is that we re-use all of the other layers with multiple types of orchestration simultaneously!

Page 40: Composable Software Architecture with Spring

40

Orchestration Layer

•  Lies at the heart of a composable architecture

•  Orchestrates all interactions with the service layer –  potentially interacting directly with repositories (e.g.,

in batch processing)

•  Handles external protocols

•  Converts from external formats into our canonical domain model

•  Thereby… allowing application services to be composed in a multitude of different ways!

Page 41: Composable Software Architecture with Spring

41

Common Types of Orchestration

•  Web controller –  HTTP, HTTPS :: HTTP request and response

•  REST or SOAP Web Service endpoint –  HTTP/HTTPS :: XML, JSON, binary, …

•  JMS or AMQP listener (or message listener container) –  JMS Message types, domain entities, …

•  Messaging endpoint (e.g., gateway + service activator) –  Web service, FTP, file system, email, …

•  Batch component (e.g., reader, writer, processor) –  Files, SQL, …

Page 42: Composable Software Architecture with Spring

42

Java EE + Open Source

Page 43: Composable Software Architecture with Spring

43

What's good about Java EE?

•  Set of common enterprise standards for Java

•  Consistent across containers and vendors (mostly)

•  Great tooling and build support

•  Catching up with innovation in open source

–  Hibernate à JPA –  Spring DI / Guice / Seam à CDI

Page 44: Composable Software Architecture with Spring

44

Java EE is a one stop shop

Page 45: Composable Software Architecture with Spring

45

which is great…

Page 46: Composable Software Architecture with Spring

46

if everything you need is in that shop.

Page 47: Composable Software Architecture with Spring

47

But if Java EE doesn’t offer what you need…

Page 48: Composable Software Architecture with Spring

48

use open source frameworks

Page 49: Composable Software Architecture with Spring

49

either in a Java EE container

Page 50: Composable Software Architecture with Spring

50

or in an alternative light-weight container.

Page 51: Composable Software Architecture with Spring

51

Open Source Frameworks fill the Gaps

•  Web frameworks and UI components •  NoSQL •  Big Data •  AMQP •  Mobile •  Social Media •  Batch •  Enterprise Integration (EAI) •  …

Page 52: Composable Software Architecture with Spring

52

How Spring fits into the picture

Page 53: Composable Software Architecture with Spring

53

Core Spring (Framework)

•  DI + IoC + AOP

•  Declarative –  transactions, caching, validation, formatting

•  Spring MVC and REST

•  JMS Message Listener Container –  Message-driven POJOs

•  Testing framework

Page 54: Composable Software Architecture with Spring

54

Dependency Injection and Inversion of Control collectively decouple application code from the deployment environment

Page 55: Composable Software Architecture with Spring

55

DI + IoC à POJO Programming Model

Page 56: Composable Software Architecture with Spring

56

POJO Programming Model + AOP à Composability

Page 57: Composable Software Architecture with Spring

57

Spring is an Ecosystem

•  Spring MVC •  Spring REST •  Spring Web Flow •  Spring Security •  Spring Web Services •  Spring Batch •  Spring Integration •  Spring Data •  Spring Mobile •  Spring Social •  Spring AMQP •  …

Page 58: Composable Software Architecture with Spring

58

Spring MVC and REST

•  @Controller annotated components serve as MVC handler methods and REST endpoints

•  Automatic type conversion

•  Data binding to domain entities

•  Marshaling –  JSON, JAXB, Castor, XMLBeans, JiBX, XStream, …

•  Handler methods and endpoints orchestrate the service layer

Page 59: Composable Software Architecture with Spring

59

Spring Web Services

•  @Endpoint annotated components serve as SOAP Web Service endpoints

•  Marshaling (OXM)

–  JAXB, Castor, XMLBeans, JiBX, XStream

•  Endpoint methods orchestrate the service layer

Page 60: Composable Software Architecture with Spring

60

Spring JMS

•  Message listener containers (MLC) support –  JMS MessageListener API –  Message-driven POJOs

•  Automatic type conversion from JMS Message types into –  String, Map, Object, byte[] –  Customer converters also supported

•  Marshaling

–  Spring OXM, customer solutions, etc.

•  MLC orchestrates the service layer

Page 61: Composable Software Architecture with Spring

61

Spring Integration

•  Inbound and outbound messaging gateways –  Handle external protocols and APIs –  Too many to mention here!

•  Automatic type conversion for method arguments and return types in Service Activators

•  Marshaling and custom type conversion also supported

•  The service layer can be orchestrated via declarative configuration (e.g., service activators in XML)

Page 62: Composable Software Architecture with Spring

62

And the list goes on …

Page 63: Composable Software Architecture with Spring

63

Composable Architecture – with Spring

Infrastructure

Repository

Service

Dom

ain

Mod

el

Spring REST

Spring MVC

Spring JMS

Spring Integration

Spring Batch

Spring WS

Page 64: Composable Software Architecture with Spring

64

Composable Architecture Checklist

þ  Modularity þ  Layered architecture

þ Canonical Domain Model þ Orchestration: web, batch, integration, web services þ Service þ Repository þ Infrastructure

þ  POJO programming model þ  Separation of concerns þ  Externalized environment-specific configuration þ  Testability, automated testing, and CI

Page 65: Composable Software Architecture with Spring

65

Roadmap for Spring 4.0

Page 66: Composable Software Architecture with Spring

66

1st Class Support for Java 8 based apps

•  Language features such as lambda expressions –  for callbacks with templates –  for concurrent execution

•  think fork/join, map/reduce, etc.

•  APIs such as JSR-310 Date and Time –  Alongside Spring’s existing support for JodaTime

Page 67: Composable Software Architecture with Spring

67

Configuring Spring with Groovy 2

•  Configuring and implementing Spring-style applications using Groovy 2.x

•  Groovy-based bean definitions

•  Groovy as the language of choice for an entire application, as a direct and straightforward alternative to Java source files

•  Groovy 2.0's static compilation support completes the picture here

Page 68: Composable Software Architecture with Spring

68

Support for Key Java EE 7 Technologies

•  JMS 2.0

•  JPA 2.1

•  Bean Validation 1.1

•  Servlet 3.1

•  And fully covering JCache 1.0

Page 69: Composable Software Architecture with Spring

69

Enabling WebSocket-style Architectures

•  Support for JSR-356 compliant runtimes

•  Also supporting related technologies

Page 70: Composable Software Architecture with Spring

70

Fine-grained Eventing and Messaging

•  Introducing fine-grained eventing and messaging within the application

•  Building on our existing application event mechanism

•  Aligned with our JMS message listener mechanism

Page 71: Composable Software Architecture with Spring

71

Pruning and Dependency Upgrades

•  Removing a variety of deprecated packages across the framework –  See Spring Framework 3.2's deprecations!

•  Raising minimum dependencies to Java 6+ –  Java SE 6+ and Java EE 6+ –  with some compromises for EE 5++ servers

Page 72: Composable Software Architecture with Spring

72

In Closing…

Page 73: Composable Software Architecture with Spring

73

Further Resources

•  Spring Projects –  http://www.springsource.org/projects –  Reference Manuals –  Javadoc

•  Spring Forums –  http://forum.springframework.org

•  Spring JIRA –  http://jira.springframework.org

•  GitHub Repositories –  https://github.com/SpringSource

Page 74: Composable Software Architecture with Spring

74

Blogs

•  Swiftmind Team Blog –  http://www.swiftmind.com/blog/

•  SpringSource Team Blog –  http://blog.springsource.com/

Page 75: Composable Software Architecture with Spring

75

Q & A

Sam Brannen twitter: @sam_brannen www.slideshare.net/sbrannen www.swiftmind.com