SlideShare uma empresa Scribd logo
1 de 52
Introduction to Spring Integration
Katowice, 04.02.2016
Dominik Strzyżewski
Logistics
• Around 2-2.5 hours
• On site presentation & webinar
• Questions at the end
Agenda
• High-level view
• Anatomy of an message and types of channels
• Endpoints
• Basic enterprise integration patterns
• Adapters
• Errors handling
• Extras *
High-level view
Main concepts
• Components can communicate using in-memory messaging
• Adapters to integrate with external systems
• Use of Spring framework programming model
• Based on Enterprise Integration Patterns book
• http://projects.spring.io/spring-integration
Sample workflow
http://docs.spring.io/autorepo/docs/spring-integration/2.0.x/reference/htmlsingle/images/cafe-eip.png
Adapters
• Application components are separated
from integration details
• External systems (file system, JMS) can
produce new message
• Implementation details not important for
components
• Payload is important! (and metadata)
• Spring Integration message can create
an external event (SOAP, JDBC)
http://www.javacodegeeks.com/2015/09/spring-integration-fundamentals.html
Hello World demo
Benefits
• Loose coupling
• Separation of concerns
• EDA
Competitors
• Apache Camel
• ESB:
• Mule ESB
• Apache ServiceMix
• Red Hat Fuse ESB
• IBM WebSphere ESB
• Oracle Enterprise Service Bus
• TIBCO ESB
http://www.infoq.com/articles/ESB-Integration
Anatomy of an message and types of
channels
Basic interaction
• An endpoint sends a message
• Endpoints are connected using MessageChannels
• Endpoints can receive messages from channels by:
• Subscribing (passive)
• Polling (active)
Message
• Messages are immutable
• GenericMessage
• MessageBuilder
• Payload is a Java object
• Headers:
• Predefined – always present
• Predefined – specific for each
component/adapter
• Custom
• From Spring 4: spring-messaging module
Message channel
• Connects endpoints
• No persistence (in-memory)
• Can be backed by messages store:
• JDBC
• MongoDB
• Redis
• Gemfire
• JMS (special channels defined in JMS namespace)
Types of message channels
• Pollable channels
• Buffer messages
• Poller is necessary
• Subscribable channels
• Call message handlers
Lubos Krnac „Pivotal Certified Spring Enterprise Integration Specialist Exam A Study Guide”, Apress, p. 350
Point-to-point channels
• Only one receiver
• DirectChannel
• Default
• Use sender’s thread
• Blocking
• Dispatcher can be configured
• QueueChannel
• Internal queue for messages
• Different threads (no transaction and security
context propagation)
• Not blocking
<int:channel id="directChannel"/>
<int:channel id="queueChannel">
<int:queue capacity="20"/>
</int:channel>
Point-to-point channels
• PriorityChannel
• Priority queue
• Use priority header
• Or custom comparator
• RendezvousChannel
• Use SynchronousQueue
• Sender knows that some receiver has accepted the message
• Request-reply operations
• ExecutorChannel
• Like DirectChannel
• Use TaskExecutor to dispatch – different thread
• NullChannel (disarded messages)
<int:channel id="rendezvousChannel">
<int:rendezvous-queue/>
</int:channel>
<int:channel id="priorityChannel">
<int:priority-queue capacity="10"/>
</int:channel>
<int:channel id="executorChannel">
<int:dispatcher task-executor="taskExecutor"/>
</int:channel>
Publish-subscribe
• Multiple receivers
• PublishSubscribeChannel – synchronous, using sender’s thread, default
• Parallel using TaskExecutor – different threads
<int:publish-subscribe-channel id="synchronousChannel"/>
<int:publish-subscribe-channel id="asynchronousChannel" task-executor="taskExecutor"/>
<task:executor id="taskExecutor" pool-size="10"/>
Publish-subscribe demo
Channel interceptors
• ChannelInterceptor interface
• Defined per channel
• Global
<int:channel id="testChannel">
<int:interceptors>
<ref bean="someCustomInterceptor"/>
</int:interceptors>
</int:channel>
<int:channel-interceptor ref="someCustomInterceptor" pattern="test*"/>
Wire tap
• Special type of interceptor
• Sends a message to another channel without affecting original flow
• Useful for monitoring and debugging
• Often combined with logging channel adapter
<int:channel id="testChannel">
<int:interceptors>
<int:wire-tap channel="logChannel"/>
</int:interceptors>
</int:channel>
<int:channel id="logChannel"/>
<int:logging-channel-adapter channel="logChannel" level="INFO" />
<int:wire-tap channel="logChannel" pattern="*"/>
Endpoints
Types of endpoints
• Messaging components
• Adapters (inbound and outbound) – covered in more detail later
• Gateways (inbound and outbound)
• Service Activator
• Message routing (filter, router, splitter, agregator, resequencer…)
• Message transformation (content enricher, claim check…)
• And much more…
Adapters
• One way integration
• Inbound
• Used to generate new messages with a poller (file system, Spring bean)
• Accept external input (JMS, HTTP)
• Outbound – send an event to an external system
<int:inbound-channel-adapter id="generator" channel="numbers" ref="numberGenerator" method="getRandomNumber">
<int:poller fixed-rate="1000"/>
</int:inbound-channel-adapter>
<int-jms:inbound-channel-adapter id="jmsIn" destination="queue" channel="testChannel">
<int:poller fixed-rate="1000"/>
</int-jms:inbound-channel-adapter>
Gateways
• Two way integration
• Inbound Gateway - deliver message into application and waits for a response
• Outbound Gateway - invokes external system and gets a response
• Categories
• Generic messaging gateway – proxy between Java code and Spring Integration infrastructure
• Technology-specific messaging gateways – handle communication with external systems (JDBS, JMS,
SOAP, HTTP)
Messaging gateway
• Proxy for sending messages from Java code
• Temporary reply channel created automatically
• Converts a parameter to a message payload
• May return Future (asynchronous) or void
public interface HRService {
Status doubleSalary(Person person);
}
<int:gateway id="hrService" service-interface="com.hr.HRService" default-request-channel="people" />
Service Activator
• Invoke bean method
• Return value becomes a message
• method attribute (or @ServiceActivator) if there are more methods
public class MessageProcessor {
Status process(Data data) {
…
}
}
<int:service-activator ref="messageProcessor" input-channel="input" output-channel="output"/>
<bean id="messageProcessor" class="test.MessageProcessor">
Demo: rest controller + gateway + JMS
Basic enterprise integration patterns
Bridge
• Connects two channels (pollable to subscribable channel)
• Connects two channel adapters
<int:bridge input-channel="inputChannel" output-channel="outputChannel">
<int:poller fixed-delay="1000"/>
</int:bridge>
Message transformer
• Payload conversion
• Header enriching
• Generic transformer
• Support for maps, XML, JSON…
<int:transformer input-channel="inputChannel" output-channel="outputChannel" expression="payload.toUpperCase()"/>
Filter
• Decides to allow message processing
• Default: drop message
• Exception on rejection
• Discard channel
<int:filter input-channel="inputChannel" output-channel="outputChannel"
ref="filterBean" method="filter"
discard-channel="invalidData"/>
Router
• Choose next channel
• Calls bean’s method and treats return value as channel name, other options available
• List of names
• Channel or list of channels
• Additional routers based on
• Payload type
• Header value
• Exception type
• SpEL
• Recipients list
• XPath
<int:router input-channel="inputChannel" ref="router" method="route"/>
Splitter
• Input – one message
• Output – many messages
<int:splitter input-channel="orders" output-channel="items" ref="orderSplitter" method="split"/>
List<LineItem> split(Order order) {
return order.getItems();
}
Adapters
Plenty of them…
• Files/FTP/FTPS/SFTP
• JDBC/JPA
• MongoDB
• Redis
• JMS/AMQP
• RSS
• HTTP/WebSockets/SOAP/RMI
• Mails
• MQTT
• Twitter
• That’s not all!
JDBC
• Could be used to retrieve or write data
• Backing Message Channels
<int-jdbc:inbound-channel-adapter query="select * from item where status=2"
channel="dataChannel" data-source="dataSource"
update="update item set status=10 where id in (:id)">
<int:poller fixed-rate="1000">
<int:transactional/>
</int:poller>
</int-jdbc:inbound-channel-adapter>
Files support
• AcceptOnceFileListFilter – default, in memory
• FileSystemPersistentAcceptOnceFileListFilter – use of MetadataStore
<int-file:inbound-channel-adapter id="filesIn1"
directory="file:${input.directory}" prevent-duplicates="true"/>
<int-file:inbound-channel-adapter id="filesIn2"
directory="file:${input.directory}"
filter="customFilterBean" />
<int-file:inbound-channel-adapter id="filesIn3"
directory="file:${input.directory}"
filename-pattern="test*" />
<int-file:inbound-channel-adapter id="filesIn4"
directory="file:${input.directory}"
filename-regex="test[0-9]+.txt" />
JMS
• Inbound/Outbound Channel Adapter
• Message-Driven Channel Adapter (uses MessageListener container)
• Inbound/Outbound Gateway
• JMS Backed Message Channels
Demo: JDBC in + JMS channel +splitter +
MongoDB out
Errors handling
Synchronous call (sender’s thread)
• Sender receives a MessageHandlingException
• It wraps original exception
• Exception is also returned for a bidirectionl asynchronous call
Unidirectional asynchronous call
• Message is sent to error channel
• Use of error channel header
• Use global channel named „errorChannel”
• errorChannel
• publish-subscribe
• Could be overriden
• exception-type-router
<int:exception-type-router input-channel="inputChannel"
default-output-channel="defaultChannel">
<int:mapping exception-type="java.lang.IllegalArgumentException"
channel="illegalChannel"/>
<int:mapping exception-type="java.lang.NullPointerException"
channel="npeChannel"/>
</int:exception-type-router>
Extras
Chaining endpoints
• Only last element can define output channel
• Intermediates steps have to return a message (or null)
• If last endpoint returns sth, output channel or replyChannel in a message have to be
defined
• Implicit use of direct channels - elements in a chain can’t be active
<int:chain input-channel="input" output-channel="output">
<int:filter ref="someSelector" throw-exception-on-rejection="true"/>
<int:header-enricher error-channel="customErrorChannel">
<header name="foo" value="bar"/>
</int:header-enricher>
<int:service-activator ref="someService" method="someMethod"/>
</int:chain>
Java Configuration/Annotations
• @Bean annotation do declare i.e. channels
• Component scanning: @MessageEndpoint, @ServiceActivator, @Filter, @Router etc.
@Bean
public MessageChannel channel() {
List<ChannelInterceptor> interceptors = /* ... */
final PublishSubscribeChannel channel = new PublishSubscribeChannel(executor());
channel.setInterceptors(interceptors);
return channel;
}
@Filter(inputChannel = "input", outputChannel = "output", discardChannel = "dropped")
public boolean filter(final String message) {
return message.startsWith("prefix");
}
Java DSL
• https://github.com/spring-projects/spring-integration-java-dsl
@Bean
public IntegrationFlow myFlow() {
return IntegrationFlows.from(this.integerMessageSource(), c ->
c.poller(Pollers.fixedRate(100)))
.channel(this.inputChannel())
.filter((Integer p) -> p > 0)
.transform(Object::toString)
.channel(MessageChannels.queue())
.get();
}
Testing
• Unit testing – nothing special
• Use of standard Spring support for integration testing
• MessagingTemplate to interact with SI
Demo: simple testing example
Questions?
Thanks for listening
Dominik Strzyżewski
dominik.strzyzewski@gmail.com
Examples: https://github.com/krzyzol/spring-integration-presentation/

Mais conteúdo relacionado

Mais procurados

Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8RichardWarburton
 
Apache Camel - The integration library
Apache Camel - The integration libraryApache Camel - The integration library
Apache Camel - The integration libraryClaus Ibsen
 
Introduction to Kafka with Spring Integration
Introduction to Kafka with Spring IntegrationIntroduction to Kafka with Spring Integration
Introduction to Kafka with Spring IntegrationBorislav Markov
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Python and cassandra
Python and cassandraPython and cassandra
Python and cassandraJon Haddad
 
Introduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityIntroduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityBruno Henrique Rother
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPEberhard Wolff
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!Jakub Kubrynski
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 formsEyal Vardi
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JSCakra Danu Sedayu
 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaEdureka!
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyVMware Tanzu
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The BasicsJeff Fox
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Tom Brander
 

Mais procurados (20)

Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8Pragmatic functional refactoring with java 8
Pragmatic functional refactoring with java 8
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
Apache Camel - The integration library
Apache Camel - The integration libraryApache Camel - The integration library
Apache Camel - The integration library
 
Introduction to Kafka with Spring Integration
Introduction to Kafka with Spring IntegrationIntroduction to Kafka with Spring Integration
Introduction to Kafka with Spring Integration
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Python and cassandra
Python and cassandraPython and cassandra
Python and cassandra
 
Introduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring SecurityIntroduction to JWT and How to integrate with Spring Security
Introduction to JWT and How to integrate with Spring Security
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQP
 
The basics of fluentd
The basics of fluentdThe basics of fluentd
The basics of fluentd
 
Introduction to Spring Boot!
Introduction to Spring Boot!Introduction to Spring Boot!
Introduction to Spring Boot!
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
Python Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | Edureka
 
How to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor NettyHow to Avoid Common Mistakes When Using Reactor Netty
How to Avoid Common Mistakes When Using Reactor Netty
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Django, What is it, Why is it cool?
Django, What is it, Why is it cool?Django, What is it, Why is it cool?
Django, What is it, Why is it cool?
 

Destaque

Spring Integration and EIP Introduction
Spring Integration and EIP IntroductionSpring Integration and EIP Introduction
Spring Integration and EIP IntroductionIwein Fuld
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationAntoine Rey
 
Atlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring IntegrationAtlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring IntegrationGunnar Hillert
 
Enterprise Integration Patterns with Spring integration!
Enterprise Integration Patterns with Spring integration!Enterprise Integration Patterns with Spring integration!
Enterprise Integration Patterns with Spring integration!hegdekiranr
 
S2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring BatchS2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring BatchGunnar Hillert
 
Mule ESB
Mule ESBMule ESB
Mule ESBniravn
 
The Technical SEO Renaissance
The Technical SEO RenaissanceThe Technical SEO Renaissance
The Technical SEO RenaissanceMichael King
 
fabric8 ... and Docker, Kubernetes & OpenShift
fabric8 ... and Docker, Kubernetes & OpenShiftfabric8 ... and Docker, Kubernetes & OpenShift
fabric8 ... and Docker, Kubernetes & OpenShiftroland.huss
 

Destaque (13)

Spring integration
Spring integrationSpring integration
Spring integration
 
Spring Integration
Spring IntegrationSpring Integration
Spring Integration
 
Spring Integration and EIP Introduction
Spring Integration and EIP IntroductionSpring Integration and EIP Introduction
Spring Integration and EIP Introduction
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Workshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring IntegrationWorkshop Spring - Session 5 - Spring Integration
Workshop Spring - Session 5 - Spring Integration
 
Atlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring IntegrationAtlanta JUG - Integrating Spring Batch and Spring Integration
Atlanta JUG - Integrating Spring Batch and Spring Integration
 
Enterprise Integration Patterns with Spring integration!
Enterprise Integration Patterns with Spring integration!Enterprise Integration Patterns with Spring integration!
Enterprise Integration Patterns with Spring integration!
 
S2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring BatchS2GX 2012 - Introduction to Spring Integration and Spring Batch
S2GX 2012 - Introduction to Spring Integration and Spring Batch
 
Mule ESB
Mule ESBMule ESB
Mule ESB
 
Wso2 esb
Wso2 esbWso2 esb
Wso2 esb
 
Mulesoft ppt
Mulesoft pptMulesoft ppt
Mulesoft ppt
 
The Technical SEO Renaissance
The Technical SEO RenaissanceThe Technical SEO Renaissance
The Technical SEO Renaissance
 
fabric8 ... and Docker, Kubernetes & OpenShift
fabric8 ... and Docker, Kubernetes & OpenShiftfabric8 ... and Docker, Kubernetes & OpenShift
fabric8 ... and Docker, Kubernetes & OpenShift
 

Semelhante a Spring integration

Semelhante a Spring integration (20)

Red Hat Open Day JBoss Fuse
Red Hat Open Day JBoss FuseRed Hat Open Day JBoss Fuse
Red Hat Open Day JBoss Fuse
 
Global Scale ESB with Mule
Global Scale ESB with MuleGlobal Scale ESB with Mule
Global Scale ESB with Mule
 
An introduction to Apache Camel
An introduction to Apache CamelAn introduction to Apache Camel
An introduction to Apache Camel
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
Sprintintegration ajip
Sprintintegration ajipSprintintegration ajip
Sprintintegration ajip
 
EIP In Practice
EIP In PracticeEIP In Practice
EIP In Practice
 
Mule enterprise service bus
Mule enterprise service busMule enterprise service bus
Mule enterprise service bus
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
 
Servlet1.ppt
Servlet1.pptServlet1.ppt
Servlet1.ppt
 
Adding Support for Networking and Web Technologies to an Embedded System
Adding Support for Networking and Web Technologies to an Embedded SystemAdding Support for Networking and Web Technologies to an Embedded System
Adding Support for Networking and Web Technologies to an Embedded System
 
Mule overview
Mule overviewMule overview
Mule overview
 
Mule Overview
Mule OverviewMule Overview
Mule Overview
 
Mule overview
Mule overviewMule overview
Mule overview
 
signalr
signalrsignalr
signalr
 
Building RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPIBuilding RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPI
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 
Overview of Mule
Overview of MuleOverview of Mule
Overview of Mule
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
 
Debugging the Web with Fiddler
Debugging the Web with FiddlerDebugging the Web with Fiddler
Debugging the Web with Fiddler
 

Último

MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Último (20)

MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

Spring integration

  • 1.
  • 2. Introduction to Spring Integration Katowice, 04.02.2016 Dominik Strzyżewski
  • 3. Logistics • Around 2-2.5 hours • On site presentation & webinar • Questions at the end
  • 4. Agenda • High-level view • Anatomy of an message and types of channels • Endpoints • Basic enterprise integration patterns • Adapters • Errors handling • Extras *
  • 6. Main concepts • Components can communicate using in-memory messaging • Adapters to integrate with external systems • Use of Spring framework programming model • Based on Enterprise Integration Patterns book • http://projects.spring.io/spring-integration
  • 8. Adapters • Application components are separated from integration details • External systems (file system, JMS) can produce new message • Implementation details not important for components • Payload is important! (and metadata) • Spring Integration message can create an external event (SOAP, JDBC) http://www.javacodegeeks.com/2015/09/spring-integration-fundamentals.html
  • 10. Benefits • Loose coupling • Separation of concerns • EDA
  • 11. Competitors • Apache Camel • ESB: • Mule ESB • Apache ServiceMix • Red Hat Fuse ESB • IBM WebSphere ESB • Oracle Enterprise Service Bus • TIBCO ESB http://www.infoq.com/articles/ESB-Integration
  • 12. Anatomy of an message and types of channels
  • 13. Basic interaction • An endpoint sends a message • Endpoints are connected using MessageChannels • Endpoints can receive messages from channels by: • Subscribing (passive) • Polling (active)
  • 14. Message • Messages are immutable • GenericMessage • MessageBuilder • Payload is a Java object • Headers: • Predefined – always present • Predefined – specific for each component/adapter • Custom • From Spring 4: spring-messaging module
  • 15. Message channel • Connects endpoints • No persistence (in-memory) • Can be backed by messages store: • JDBC • MongoDB • Redis • Gemfire • JMS (special channels defined in JMS namespace)
  • 16. Types of message channels • Pollable channels • Buffer messages • Poller is necessary • Subscribable channels • Call message handlers Lubos Krnac „Pivotal Certified Spring Enterprise Integration Specialist Exam A Study Guide”, Apress, p. 350
  • 17. Point-to-point channels • Only one receiver • DirectChannel • Default • Use sender’s thread • Blocking • Dispatcher can be configured • QueueChannel • Internal queue for messages • Different threads (no transaction and security context propagation) • Not blocking <int:channel id="directChannel"/> <int:channel id="queueChannel"> <int:queue capacity="20"/> </int:channel>
  • 18. Point-to-point channels • PriorityChannel • Priority queue • Use priority header • Or custom comparator • RendezvousChannel • Use SynchronousQueue • Sender knows that some receiver has accepted the message • Request-reply operations • ExecutorChannel • Like DirectChannel • Use TaskExecutor to dispatch – different thread • NullChannel (disarded messages) <int:channel id="rendezvousChannel"> <int:rendezvous-queue/> </int:channel> <int:channel id="priorityChannel"> <int:priority-queue capacity="10"/> </int:channel> <int:channel id="executorChannel"> <int:dispatcher task-executor="taskExecutor"/> </int:channel>
  • 19. Publish-subscribe • Multiple receivers • PublishSubscribeChannel – synchronous, using sender’s thread, default • Parallel using TaskExecutor – different threads <int:publish-subscribe-channel id="synchronousChannel"/> <int:publish-subscribe-channel id="asynchronousChannel" task-executor="taskExecutor"/> <task:executor id="taskExecutor" pool-size="10"/>
  • 21. Channel interceptors • ChannelInterceptor interface • Defined per channel • Global <int:channel id="testChannel"> <int:interceptors> <ref bean="someCustomInterceptor"/> </int:interceptors> </int:channel> <int:channel-interceptor ref="someCustomInterceptor" pattern="test*"/>
  • 22. Wire tap • Special type of interceptor • Sends a message to another channel without affecting original flow • Useful for monitoring and debugging • Often combined with logging channel adapter <int:channel id="testChannel"> <int:interceptors> <int:wire-tap channel="logChannel"/> </int:interceptors> </int:channel> <int:channel id="logChannel"/> <int:logging-channel-adapter channel="logChannel" level="INFO" /> <int:wire-tap channel="logChannel" pattern="*"/>
  • 24. Types of endpoints • Messaging components • Adapters (inbound and outbound) – covered in more detail later • Gateways (inbound and outbound) • Service Activator • Message routing (filter, router, splitter, agregator, resequencer…) • Message transformation (content enricher, claim check…) • And much more…
  • 25. Adapters • One way integration • Inbound • Used to generate new messages with a poller (file system, Spring bean) • Accept external input (JMS, HTTP) • Outbound – send an event to an external system <int:inbound-channel-adapter id="generator" channel="numbers" ref="numberGenerator" method="getRandomNumber"> <int:poller fixed-rate="1000"/> </int:inbound-channel-adapter> <int-jms:inbound-channel-adapter id="jmsIn" destination="queue" channel="testChannel"> <int:poller fixed-rate="1000"/> </int-jms:inbound-channel-adapter>
  • 26. Gateways • Two way integration • Inbound Gateway - deliver message into application and waits for a response • Outbound Gateway - invokes external system and gets a response • Categories • Generic messaging gateway – proxy between Java code and Spring Integration infrastructure • Technology-specific messaging gateways – handle communication with external systems (JDBS, JMS, SOAP, HTTP)
  • 27. Messaging gateway • Proxy for sending messages from Java code • Temporary reply channel created automatically • Converts a parameter to a message payload • May return Future (asynchronous) or void public interface HRService { Status doubleSalary(Person person); } <int:gateway id="hrService" service-interface="com.hr.HRService" default-request-channel="people" />
  • 28. Service Activator • Invoke bean method • Return value becomes a message • method attribute (or @ServiceActivator) if there are more methods public class MessageProcessor { Status process(Data data) { … } } <int:service-activator ref="messageProcessor" input-channel="input" output-channel="output"/> <bean id="messageProcessor" class="test.MessageProcessor">
  • 29. Demo: rest controller + gateway + JMS
  • 31. Bridge • Connects two channels (pollable to subscribable channel) • Connects two channel adapters <int:bridge input-channel="inputChannel" output-channel="outputChannel"> <int:poller fixed-delay="1000"/> </int:bridge>
  • 32. Message transformer • Payload conversion • Header enriching • Generic transformer • Support for maps, XML, JSON… <int:transformer input-channel="inputChannel" output-channel="outputChannel" expression="payload.toUpperCase()"/>
  • 33. Filter • Decides to allow message processing • Default: drop message • Exception on rejection • Discard channel <int:filter input-channel="inputChannel" output-channel="outputChannel" ref="filterBean" method="filter" discard-channel="invalidData"/>
  • 34. Router • Choose next channel • Calls bean’s method and treats return value as channel name, other options available • List of names • Channel or list of channels • Additional routers based on • Payload type • Header value • Exception type • SpEL • Recipients list • XPath <int:router input-channel="inputChannel" ref="router" method="route"/>
  • 35. Splitter • Input – one message • Output – many messages <int:splitter input-channel="orders" output-channel="items" ref="orderSplitter" method="split"/> List<LineItem> split(Order order) { return order.getItems(); }
  • 37. Plenty of them… • Files/FTP/FTPS/SFTP • JDBC/JPA • MongoDB • Redis • JMS/AMQP • RSS • HTTP/WebSockets/SOAP/RMI • Mails • MQTT • Twitter • That’s not all!
  • 38. JDBC • Could be used to retrieve or write data • Backing Message Channels <int-jdbc:inbound-channel-adapter query="select * from item where status=2" channel="dataChannel" data-source="dataSource" update="update item set status=10 where id in (:id)"> <int:poller fixed-rate="1000"> <int:transactional/> </int:poller> </int-jdbc:inbound-channel-adapter>
  • 39. Files support • AcceptOnceFileListFilter – default, in memory • FileSystemPersistentAcceptOnceFileListFilter – use of MetadataStore <int-file:inbound-channel-adapter id="filesIn1" directory="file:${input.directory}" prevent-duplicates="true"/> <int-file:inbound-channel-adapter id="filesIn2" directory="file:${input.directory}" filter="customFilterBean" /> <int-file:inbound-channel-adapter id="filesIn3" directory="file:${input.directory}" filename-pattern="test*" /> <int-file:inbound-channel-adapter id="filesIn4" directory="file:${input.directory}" filename-regex="test[0-9]+.txt" />
  • 40. JMS • Inbound/Outbound Channel Adapter • Message-Driven Channel Adapter (uses MessageListener container) • Inbound/Outbound Gateway • JMS Backed Message Channels
  • 41. Demo: JDBC in + JMS channel +splitter + MongoDB out
  • 43. Synchronous call (sender’s thread) • Sender receives a MessageHandlingException • It wraps original exception • Exception is also returned for a bidirectionl asynchronous call
  • 44. Unidirectional asynchronous call • Message is sent to error channel • Use of error channel header • Use global channel named „errorChannel” • errorChannel • publish-subscribe • Could be overriden • exception-type-router <int:exception-type-router input-channel="inputChannel" default-output-channel="defaultChannel"> <int:mapping exception-type="java.lang.IllegalArgumentException" channel="illegalChannel"/> <int:mapping exception-type="java.lang.NullPointerException" channel="npeChannel"/> </int:exception-type-router>
  • 46. Chaining endpoints • Only last element can define output channel • Intermediates steps have to return a message (or null) • If last endpoint returns sth, output channel or replyChannel in a message have to be defined • Implicit use of direct channels - elements in a chain can’t be active <int:chain input-channel="input" output-channel="output"> <int:filter ref="someSelector" throw-exception-on-rejection="true"/> <int:header-enricher error-channel="customErrorChannel"> <header name="foo" value="bar"/> </int:header-enricher> <int:service-activator ref="someService" method="someMethod"/> </int:chain>
  • 47. Java Configuration/Annotations • @Bean annotation do declare i.e. channels • Component scanning: @MessageEndpoint, @ServiceActivator, @Filter, @Router etc. @Bean public MessageChannel channel() { List<ChannelInterceptor> interceptors = /* ... */ final PublishSubscribeChannel channel = new PublishSubscribeChannel(executor()); channel.setInterceptors(interceptors); return channel; } @Filter(inputChannel = "input", outputChannel = "output", discardChannel = "dropped") public boolean filter(final String message) { return message.startsWith("prefix"); }
  • 48. Java DSL • https://github.com/spring-projects/spring-integration-java-dsl @Bean public IntegrationFlow myFlow() { return IntegrationFlows.from(this.integerMessageSource(), c -> c.poller(Pollers.fixedRate(100))) .channel(this.inputChannel()) .filter((Integer p) -> p > 0) .transform(Object::toString) .channel(MessageChannels.queue()) .get(); }
  • 49. Testing • Unit testing – nothing special • Use of standard Spring support for integration testing • MessagingTemplate to interact with SI
  • 52. Thanks for listening Dominik Strzyżewski dominik.strzyzewski@gmail.com Examples: https://github.com/krzyzol/spring-integration-presentation/