Slide 1

Slide 1 text

ENTERPRISE INTEGRATION PATTERNS: SPRING WAY Dragan Gajic

Slide 2

Slide 2 text

INTEGRATION • Creating a single, monolite app to cover all aspects of business is hard • Enterpises are comprised of applications which can be: custom build, 3rd party, legacy • Connecting computer systems, companies or people • Share data and processes

Slide 3

Slide 3 text

INTEGRATION CHALLENGES • Networks: unreliable & slow • Differences: language, platform & data format • Changes • Limited control • Standards • Maintenance

Slide 4

Slide 4 text

INTEGRATION STYLES • File transfer • Shared DB • RMI • Messaging • asyncronous • reliable transfer • common format (messages) • Loose coupling

Slide 5

Slide 5 text

MESSAGE AND CHANNEL • Message • Header – information about the data • Payload (body) – the data being transmitted • Channel • Point-to-Point • Publish-Subscribe Header Payload Header Payload Header Payload Consumer Producer Header Payload Header Payload

Slide 6

Slide 6 text

PIPES AND FILTERS Persist Pipe Create validation email Pipe Pipe Filter Filter Send validation email SMTP Pipe Filter USER Registration • Divide complex processing • Filters – independent processing steps • Pipes – connect filters into a sequence • Fundamental architectural style for messaging • Pipe = Channel • Filter = Endpoint

Slide 7

Slide 7 text

SPRING INTEGRATION • Top-level project in spring.io • Enables lightweight messaging • Combines DI, POJO and Messaging • Implements most of EIP • Includes wide selection of channel adapters • SI != MOM, ESB

Slide 8

Slide 8 text

EXAMPLE: USER REGISTRATION • After user registration validate email address by sending confirmation link to email and notify moderators about new profile • In steps: • Generate confirmation link (UUID) • Store userId -> UUID • Send confirmation email • Notify site moderators about the new profile SMTP ADMIN REST API

Slide 9

Slide 9 text

CHANNEL ADAPTER @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public ProfileResource register(@Valid @RequestBody RegistrationResource registration) { Profile profile = profileService.save(regResToProfile.convert(registration)); publisher.publishEvent(new RegistrationEvent(this, profile)); return profileToProfileResource.convert(profile); }

Slide 10

Slide 10 text

ENRICHER

Slide 11

Slide 11 text

WIRE-TAP

Slide 12

Slide 12 text

PIPING IT ALL TOGETHER

Slide 13

Slide 13 text

COMPOSITE PROCESSOR

Slide 14

Slide 14 text

SPLITTER & ROUTER public Object[] split(RegistrationEvent event) { Profile profile = event.getProfile(); return new Object[] {profile.getId(), profile}; }

Slide 15

Slide 15 text

SERVICE ACTIVATOR & TRANSLATOR public boolean pending(String uuid, Long id) { return confirmations.put(uuid, id) == null; }

Slide 16

Slide 16 text

AGGREGATOR & MAIL ADAPTER public String aggregate(List> messages) { return (String) messages .stream() .filter(p -> p.getPayload() instanceof String) .findFirst().orElse(null).getPayload(); }

Slide 17

Slide 17 text

MESSAGING SYSTEM message SMTP ADMIN REST API

Slide 18

Slide 18 text

DEMO https://gitlab.levi9.com/d.gajic/eip/tree/code3

Slide 19

Slide 19 text

RESOURCES • Book • Enterprise Integration Patterns • Gregor Hohpe, Bobby Woolf • Spring Integration • http://projects.spring.io/spring-integration • Samples • https://gitlab.levi9.com/d.gajic/eip.git • Patterns • http://www.enterpriseintegrationpatterns.com

Slide 20

Slide 20 text

Q&A