0% found this document useful (0 votes)
39 views59 pages

Spring Enterprise Integration: Professional Open Source™

int
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views59 pages

Spring Enterprise Integration: Professional Open Source™

int
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 59

Professional Open Source

Spring Enterprise Integration

JBoss, Inc. 2003, 2004.

07/17/04

What is Enterprise Application ?


Professional Open Source

Your application talking to another application over the network can


be considered an Enterprise application.

We want one Enterprise Application to integrate with other.

JBoss, Inc. 2003, 2004.

Professional Open Source

TRADITIONAL APPROACH

JBoss, Inc. 2003, 2004.

Professional Open Source

Lets consider an application that loads Trades from an external


system.
The requirements of processing these Trades are as follows:
Trades should be segregated based on Trade types (NEW,
CANCEL, UPDATE, etc).
Trades are then processed accordingly and persisted.
An auditor tool should be notified once the Trades are persisted

JBoss, Inc. 2003, 2004.

Professional Open Source

JBoss, Inc. 2003, 2004.

Professional Open Source

What if we have to add another workflow, such as


raising a notification for all big Trades or creating a task to collect
Trade patterns ?

So, how can we enhance the previous TradesLoader to adapt to


various scenarios that develop over a period of time?
One way is to use Messaging in our standalone application.

JBoss, Inc. 2003, 2004.

Professional Open Source

In this scenario, the TradesLoader fetches the Trades and posts them
onto an internal data structure (a queue) before exiting.
The relevant components, such as TradeProcessor, TradePersistor,
and TradeNotifier will be working on their respective jobs to satisfy the
workflow.

They all can work at their own pace and not be bothered by the
sequential processing anymore.

JBoss, Inc. 2003, 2004.

What is a Message ?
Professional Open Source

Messages are the objects that carry information between two


applications.
They are constructed at one end, usually the producer side of the
messaging application.
They are then consumed and deconstructed at the other end, the
consumer/subscriber side.

JBoss, Inc. 2003, 2004.

Professional Open Source

The Message consists of two parts


payload
header properties.
Following is the Message interface definition :

JBoss, Inc. 2003, 2004.

How to create a Message ?


Professional Open Source

JBoss, Inc. 2003, 2004.

10

What is a Message Channel?


Professional Open Source

the channel represents the location where it is being sent.


Simply put, the message ends up at a pre specified address called
channel
In Spring Integration, the channel is represented by a
MessageChannel interface

JBoss, Inc. 2003, 2004.

11

How to declare a channel ?


Professional Open Source

JBoss, Inc. 2003, 2004.

12

Endpoints
Professional Open Source

Endpoints are basically components that consume messages from an


input channel or deliver to an output channel.

JBoss, Inc. 2003, 2004.

13

ServiceActivator Endpoint
Professional Open Source

A Service Activator is a generic endpoint that invokes a method on a


bean when a message arrives at an input channel.

JBoss, Inc. 2003, 2004.

14

Professional Open Source

DEMO TO SEND A MESSAGE


TO CHANNEL AND CONSUME
MESSAGE USING
SERVICEACTIVATOR

JBoss, Inc. 2003, 2004.

15

Basics-beans.xml
Professional Open Source

JBoss, Inc. 2003, 2004.

16

Professional Open Source

JBoss, Inc. 2003, 2004.

17

Professional Open Source

JBoss, Inc. 2003, 2004.

18

Professional Open Source

MESSAGE CHANNELS IN
DETAILS

JBoss, Inc. 2003, 2004.

19

Professional Open Source

Message Channels Can be classified into 2 types :


Point to Point (p2p)
Publish Subscribe(pub/sub)
In Spring Integration we have to sub interfaces of MessageChannel
PollableChannel (p2p)
SubscribableChannel (pub/sub)

JBoss, Inc. 2003, 2004.

20

Professional Open Source

JBoss, Inc. 2003, 2004.

21

Professional Open Source

PollableChannel has the following sub types :


QueueChannel
PriorityChannel,
RendezvousChannel.
SubscribableChannel has the following sub types :
DirectChannel
ExecutorChannel

JBoss, Inc. 2003, 2004.

22

QueueChannel
Professional Open Source

only one consumer will receive the message as it is P2P Channel


This channel also supports buffering messages as it uses a queue
data structure to hold the messages in memory

If capacity is not given like below, capacity is unlimited.

JBoss, Inc. 2003, 2004.

23

Professional Open Source

What happens to the sender if there is no room for any additional


messages to be published?

The sender will wait till there is room for message or will time out if
specified

JBoss, Inc. 2003, 2004.

24

Professional Open Source

The QueueChannel also provides a method to purge the channel with


a predefined selection criteria via the MessageSelector
implementation:

To purge the channel completely, simply pass null as the selector to


the method.

JBoss, Inc. 2003, 2004.

25

Priority Channel
Professional Open Source

The PriorityChannel is a subclass of QueueChannel with just one


additional characteristicprioritization of messages.
If you need to send a high-priority message immediately,
then PriorityChannel is the one to use.
The easiest way is to set the PRIORITY property on the
MessageHeader when creating a message.

JBoss, Inc. 2003, 2004.

26

Professional Open Source

Defining a priority Channel

JBoss, Inc. 2003, 2004.

27

Rendezvous Channel
Professional Open Source

Rendezvous Channel is a subclass of QueueChannel with queue


capacity as ZERO
This means that at any time, only one message can exist on the
channel.
When a producer sends a message, it will block until that message
is consumed by the consumer.
Similarly, a consumer will be blocked until a message
appears on the channel.

JBoss, Inc. 2003, 2004.

28

PublishSubscribeChannel
Professional Open Source

PublishSubscribeChannel is a SubscribableChannel
implementation

U can subscribe to pub sub channel as below :

JBoss, Inc. 2003, 2004.

29

Direct Channel
Professional Open Source

DirectChannel is a mixed type channel with both P2P and Pub/Sub


characteristics.
It implements SubscribableChannel so you need to have a concrete
implementation of MessageHandler subscribing to it.

Messages can be consumed by subscribed handlers,


but only one subscriber will be getting each message, thus displaying
P2P semantics
The framework uses the round-robin strategy to choose a recipient
from the multiple subscribers.

JBoss, Inc. 2003, 2004.

30

Professional Open Source

The production and consumption of the message are both executed


in the same thread.

U can declare a direct channel as below :

JBoss, Inc. 2003, 2004.

31

Professional Open Source

U can configure load-balancer and fail-over as below :

If multiple handlers are subscribed to the channel,load balancer will


use the configured strategy to select one of the handlers. Round-robin
is the default strategy.
If failover is set to true, it will let the subsequent handlers
process the messages if the initial chosen handler throws an
exception while handling the messages .

JBoss, Inc. 2003, 2004.

32

Executor Channel
Professional Open Source

The ExecutorChannel implements SubscribableChannel and is similar


to the DirectChannel, except that the dispatching of the message is
carried by a java.uti.concurrent.Executor instance.

The consumption of the message is processed in a separate thread


handled by the dispatcher.
The dispatcher invokes the executor for message processing by the
consumer.

JBoss, Inc. 2003, 2004.

33

Professional Open Source

ENDPOINTS

JBoss, Inc. 2003, 2004.

34

ServiceActivator
Professional Open Source

The Service Activator is a generic endpoint which invokes a method


on a bean whenever a message arrives on the channel.
If the method has a return value, then the value will
be sent to an output channel if the channel is configured.

If the bean class has only one method, then you do not have to
declare the method attribute

JBoss, Inc. 2003, 2004.

35

Professional Open Source

If output-channel is not configured method has a return value, then


the framework will use the message header property
called replyChannel to send the reply.

An exception will be thrown if no replyChannel header property is


found

JBoss, Inc. 2003, 2004.

36

Gateway
Professional Open Source

Observe the following code to send a message to channel :

Here we got the reference of channel in client code to send a


message.
So, Client code is tighly coupled to framework

JBoss, Inc. 2003, 2004.

37

Professional Open Source

To decouple client from framework specific classes, we can use


gateway
There are two types of Gateways:
Synchronous Gateway
Asynchronous Gateway
In Synchronous Gateway, the message call will be blocked until the
process is completed.
In Asynchronous Gateway, the message call is not blocked.

JBoss, Inc. 2003, 2004.

38

Synchronous Gateway
Professional Open Source

The first step in writing a gateway is to define an interface that


describes the interaction methods with the messaging system.

JBoss, Inc. 2003, 2004.

39

Professional Open Source

The frameworks GatewayProxyFactoryBean creates a proxy for


this service interface.

Following is the configuration :

JBoss, Inc. 2003, 2004.

40

Professional Open Source

Following is the client code which is sending message :

JBoss, Inc. 2003, 2004.

41

Asynchronous Gateway
Professional Open Source

The client in the previous example will be blocked until it gets a reply
from the processors.
If the clients requirement is to fire and continue, using
Asynchronous Gateway is the right choice.

In order to achieve the asynchronous behaviour, the service interface


is required to have the return type changed so it now returns a Future
object:

JBoss, Inc. 2003, 2004.

42

Delayer Endpoint
Professional Open Source

The Delayer endpoint is used to introduce delay between sender and


receiver.

If default delay is et to 0 or negative value, message will be


delivered immediately.

JBoss, Inc. 2003, 2004.

43

Professional Open Source

You can also use a header field to define the delay period for each
message.

JBoss, Inc. 2003, 2004.

44

Message Enricher
Professional Open Source

A Message Enricher component enriches the incoming message with


additional information and sends the updated object to the
downstream consumers.

There are 2 types of enrichers :


Header Enricher
Pay load Enricher

JBoss, Inc. 2003, 2004.

45

Header Enricher
Professional Open Source

You can add additional header attributes to the message using the
Header Enricher component

JBoss, Inc. 2003, 2004.

46

Professional Open Source

You can set a number of predefined properties such as priority, replychannel, errorchannel.

JBoss, Inc. 2003, 2004.

47

Professional Open Source

Framework also supports setting header properties using payload by


allowing the header-enricher s header property to refer to a bean:

JBoss, Inc. 2003, 2004.

48

Payload Enricher
Professional Open Source

The enricher tag in the integration namespace is used to configure


the payload enricher.

JBoss, Inc. 2003, 2004.

49

Professional Open Source

JBoss, Inc. 2003, 2004.

50

Professional Open Source

TRANSFORMERS

JBoss, Inc. 2003, 2004.

51

String Transformers
Professional Open Source

JBoss, Inc. 2003, 2004.

52

Map Transformers
Professional Open Source

If you need to convert the POJO to a name-value pair of Map, you


can use the Object to Map transformer.

JBoss, Inc. 2003, 2004.

53

Professional Open Source

JBoss, Inc. 2003, 2004.

54

JSON Transformers
Professional Open Source

JBoss, Inc. 2003, 2004.

55

XML Transformers
Professional Open Source

JBoss, Inc. 2003, 2004.

56

Professional Open Source

The marshalling-transformer takes an optional result-type which


decides the result type.
There are two built-in result types
javax.xml.transform.dom.DOMResult
org.springframework.xml.transform.StringResult

JBoss, Inc. 2003, 2004.

57

XPath Transformers
Professional Open Source

The XPath-transformer decodes the XML payload using XPath


expressions.
The transformer expects an XML payload on an input channel and
outputs the result to the output channel after applying the XPath
expression.

JBoss, Inc. 2003, 2004.

58

Custom Transformers
Professional Open Source

JBoss, Inc. 2003, 2004.

59

You might also like