Вячеслав Блинов: "Spring Integration as an Integration Patterns Provider"
-
Upload
anna-shymchenko -
Category
Technology
-
view
171 -
download
4
Transcript of Вячеслав Блинов: "Spring Integration as an Integration Patterns Provider"
April 13, 2023
Spring Integration
Blynov Viacheslav
Dnepropetrovsk
April 13, 2023 2
Introduction
3 April 13, 2023
Spring Integration Goals Provide a simple model for implementing complex enterprise
integration solutions.
Facilitate asynchronous, message-driven behavior within a Spring-based application.
Promote intuitive, incremental adoption for existing Spring users.
Spring Integration Introduction
4 April 13, 2023
Spring Integration Features Implementation of most of the Enterprise Integration Patterns
– Endpoint
– Channel
– Aggregator
– Filter
– …
Integration with External Systems
– REST/HTTP
– FTP
– JMS
– …
The framework has extensive JMX support
– exposing framework components as MBeans
– adapters to obtain attributes from MBeans, invoke operations, send/receive notifications
Spring Integration Introduction
5 April 13, 2023
Spring Integration Endpoints
AMQP
Spring Application Events
File System
FTP
Gemfire
HTTP/REST
JDBC
JMX
JPA
MongoDB
Redis
RMI
TCP
UDP
XMPP
Spring Integration Introduction
April 13, 2023 6
Main Components
7 April 13, 2023
Main Components Message Message Channel Message Endpoint
– Transformer
– Filter
– Router
– Splitter
– Aggregator
– Service Activator
– Channel Adapter
– Gateway
Spring Integration Main Components
8 April 13, 2023
Spring Integration Main Components
Message Message is a generic
wrapper for any Java object combined with metadata used by the framework while handling that object
9 April 13, 2023
Spring Integration Main Components
Message Channel Point-To-Point Channel Publish/Subscribe Channel Pollable Channels Message-Driven Channels
10 April 13, 2023
Spring Integration Main Components
Message Endpoint
Encapsulates communication-specific details:
converts/extracts business data to/from message
sends/receives messages to/from message channel
11 April 13, 2023
Spring Integration Main Components
Transformer Message Transformer is
responsible for converting a Message's content or structure and returning the modified Message
12 April 13, 2023
Spring Integration Main Components
Filter Message Filter determines
whether a Message should be passed to an output channel at all
13 April 13, 2023
Spring Integration Main Components
Splitter Splitter is another type of
Message Endpoint whose responsibility is to accept a Message from its input channel, split that Message into multiple Messages, and then send each of those to its output channel.
14 April 13, 2023
Spring Integration Main Components
Service Activator
Service Activator is a generic endpoint for connecting a service instance to the messaging system.
The input Message Channel must be configured, and if the service method to be invoked is capable of returning a value, an output Message Channel may also be provided.
15 April 13, 2023
Spring Integration Main Components
Gateway
The Gateway encapsulates messaging-specific code (e.g., the code required to send or receive a message) and separates it from the rest of the application code. The Messaging Gateway exposes a business function to the rest of the application so that instead of requiring the application to set properties like Message.
April 13, 2023 16
Example
17 April 13, 2023
Task We receive JMS messages with some CompoundObject in JSON format
CompoundObject is-a list of some Objects
We need to extract all Objects from CompoundObject and save them to database (possibly performing some other business logic)
Those Objects which are considered “good” (verified against some rule) should be sent via JMS to another queue in JSON format
Spring Integration Example
18 April 13, 2023
Spring Integration Example
We need to add the following dependencies in pom.xml
19 April 13, 2023
Spring Integration Example
Specify JMS connection factory
20 April 13, 2023
Spring Integration Example
Configure Spring Integration context
21 April 13, 2023
Spring Integration Example
Configure Spring Integration context
CompObjectDTO parseCompoundObject(String payload)
22 April 13, 2023
Spring Integration Example
Configure Spring Integration context
CompObjectDTO parseCompoundObject(String payload)
List<ObjectDTO> splitCompound(CompObjectDTO dto)
23 April 13, 2023
Spring Integration Example
Configure Spring Integration context
CompObjectDTO parseCompoundObject(String payload)
List<ObjectDTO> splitCompound(CompObjectDTO dto)
Object convertToEntity(ObjectDTO dto)
24 April 13, 2023
Spring Integration Example
Configure Spring Integration context
CompObjectDTO parseCompoundObject(String payload)
List<ObjectDTO> splitCompound(CompObjectDTO dto)
Object convertToEntity(ObjectDTO dto)
Object saveEntity(Object obj)
25 April 13, 2023
Spring Integration Example
Configure Spring Integration context
CompObjectDTO parseCompoundObject(String payload)
List<ObjectDTO> splitCompound(CompObjectDTO dto)
Object convertToEntity(ObjectDTO dto)
Object saveEntity(Object obj)
boolean isGoodObject(Object obj)
26 April 13, 2023
Spring Integration Example
Configure Spring Integration context
CompObjectDTO parseCompoundObject(String payload)
List<ObjectDTO> splitCompound(CompObjectDTO dto)
Object convertToEntity(ObjectDTO dto)
Object saveEntity(Object obj)
boolean isGoodObject(Object obj)
ObjectDTO convertToDTO(Object obj)
27 April 13, 2023
Spring Integration Example
Configure Spring Integration context
CompObjectDTO parseCompoundObject(String payload)
List<ObjectDTO> splitCompound(CompObjectDTO dto)
Object convertToEntity(ObjectDTO dto)
Object saveEntity(Object obj)
boolean isGoodObject(Object obj)
ObjectDTO convertToDTO(Object obj)
String serializeObjectDTO(ObjectDTO obj)
28 April 13, 2023
Spring Integration Example
Receiving messages via HTTP REST
29 April 13, 2023
Another option: JMS backed message channels
Channel adapter are intended for applications that are integrating with other external systems. There are cases where both the producer and consumer for a given JMS Destination are intended to be part of the same application, running within the same process.
<int-jms:channel id="jmsChannel" queue="exampleQueue"/>
<int-jms:publish-subscribe-channel id="jmsChannel" topic="exampleTopic"/>
Support of transactions (“transaction-manager” atrribute) Support for connection (session, consumer) cache Concurrency (number of concurrent sessions/consumers to start for
each listener)
Spring Integration Example
30 April 13, 2023
Summary Built on the top of Spring JMS
Every element of the chain – just a simple POJO
High cohesion
Easy to cover with unit-tests
“Convention over configuration” – bean with name “connectionFactory” will be found automatically
Spring Integration Example
April 13, 2023 31
Spring Integration VS Apache Camel
32 April 13, 2023
Both projects aim to fill similar need: light-weight integration library with full implementations of EIP
Apache Camel introduces DSL (Java, Scala, Groovy). Spring Integration - only XML
Apache Camel supports longer list of technologies
Apache Camel offers rich support for both integration and unit-testing. Spring Integration supports just generic Spring Test
Apache Camel Community is larger, documentation is better
Spring Integration Spring Integration VS Apache Camel
33 April 13, 2023
Apache Camel Java DSL Example
final JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
jaxbDataFormat.setContextPath(“test.ns.oxm");
jaxbDataFormat.setPartClass(“test.ns.oxm.ABSPartnerChangesEventType");
from("activemq:incoming.partner")
.log("log:test.log")
.choice() .when(header("EVENTTYPE").isEqualTo(“TESTVALUE")).to("direct:createPartner“) .when(header("EVENTTYPE").isEqualTo(“TESTVALUE2")).to("direct:updatePartner");
from("direct:createPartner")
.errorHandler(noErrorHandler())
.unmarshal(jaxbDataFormat)
.beanRef(“partnerChangeHandler", "createPartner");
from("direct:updatePartner")
.errorHandler(noErrorHandler())
.unmarshal(jaxbDataFormat)
.beanRef(“partnerChangeHandler", "updatePartner");
Spring Integration Spring Integration VS Apache Camel
April 13, 2023 34
Questions?