Enterprise Service Bus (ESB) Overviewwith Spring Integration – Messages – Channels



Enterprise Service Bus (ESB) Overviewwith Spring Integration – Messages – Channels

0 0


ESB-Presentation

A presentation on Enterprise Service Bus (ESB) with Spring Integration

On Github mnimer / ESB-Presentation

Enterprise Service Bus (ESB) Overviewwith Spring Integration

Presented by: Mike Nimer@mnimer http://mnimer.github.io/ESB-Presentation

Imagine

  • Breaking up large processes into small discrete steps (easily to code, easy to test)
  • Scaling an application with thread pools, in-memory queues, or external queues (JMS). (In configuration, not code.)
  • Ability to quickly change the flow of the application. (Adding steps, rearrange steps, split, etc..)

Enterprise Service Bus (ESB)

based on

Components

  • Messages
  • Channels
  • Routers
  • Transformers
  • Adapters
  • Services
  • Gateways

Software Packages

  • Spring Integration
  • MULE
  • WS02
  • Apache: Service Mix, Synapse, Camel
  • JBoss, Oracle, IBM
  • and more...

Examples

  • Cloud Logging
  • REST Services
  • RSS Reader
  • Importing Files

Cloud Logging (Log4j)

REST Service (image metadata)

RSS Reader

Importing Files

Components

  • Messages
  • Channels
  • Routers
  • Transformers
  • Adapters
  • Services
  • Gateways
i

Messages

The common object that everything understands and passes around.

  • Made up of 2 parts:
    • Header (key/value)
    • Payload (serializable)

Message Builder

Java

Message message1 = MessageBuilder.withPayload("test") .setHeader("foo", "bar") .build();

Java

Message message2 = MessageBuilder.fromMessage(message1).build();

Channels

The message pipe in and out of other components (services, adapters, etc).

Point to Point

"A Point-to-Point Channel ensures that only one receiver consumes any given message"

XML

<int:channel id="exampleChannel"/>

Publish-Subscribe

"One input channel that splits into multiple output channels, one for each subscriber."

XML

<int:publish-subscribe-channel id="exampleChannel"/>

Dead Letter Channel

"When a messaging system determines that it cannot or should not deliver a message, it may elect to move the message to a Dead Letter Channel."

XML

<int:service outputChannel="nullChannel"/>

Interceptors

XML

<int:channel id="exampleChannel">     <interceptors>         <wire-tap channel="logger"/>     </interceptors> <int:channel>

Queues & Thread Pools

Queue

<int:channel id="exampleChannel">     <queue capacity="25"/>/> </int:channel>

Thread Pool

<int:channel id="exampleChannel">     <task:executor id="executorWithPoolSizeRange" pool-size="5" queue-capacity="100"/> </int:channel>

Routers

Routers control the different process flows.

  • Header Routers
  • Content / Payload Routers
  • Splitters
  • Aggregators

Header Router

XML

<header-value-router input-channel="inChannel" header-name="library">     <mapping value="drewNoakes" channel="drewParser" />     <mapping value="apacheCommons" channel="apacheParser" /> </header-value-router>

Payload Type Router

XML

<bean id="payloadTypeRouter" class="org.springframework.integration.router.PayloadTypeRouter"> <property name="payloadTypeChannelMap">     <map>         <entry key="com.data.User" value-ref="userChannel"/>         <entry key="com.data.Product" value-ref="productChannel"/>     </map> </property> </bean>

Custom Routers

Takes in a Message and returns the name (String) of the channel to route the message to.

XML

<router input-channel="inChannel" default-output-channel="jsonChannel"method="route" >     <beans:bean class="com.foo.FileRouter"/> </router>

Java

public String route(Message message){...}

Splitters

Takes in a single Message and returns a list of message.

XML

<splitter input-channel="inChannel" output-channel="outChannel"method="split">     <beans:bean class="com.foo.FileSplitter"/> </spliter>

Java

public List<Post> split(Message message){...}

Aggregators

Uses the auto-generated header values for: correlation id, sequence number and sequence size

XML

<aggregator input-channel="inChannel" output-channel="outChannel" method="validate" >     <beans:bean class="org.foo.FileAggregator"/> </aggregator>

Java

public Message verifyFiles(List<Message> message){...}

Transformers

Transforms message from one format to another.

  • String Transfromers
    • object-to-string-transformer (toString())
  • Json Transformers
    • object-to-json-transformer
    • json-to-object-transformer
  • XML Transformers
    • UnmarshallingTransformer
    • MarshallingTransformer
    • XsltPayloadTransformer

Transformers (cont.)

  • Map Transformers
    • object-to-map-transformer
    • map-to-object-transformer
  • File Transformers
    • file-to-bytes-transformer
    • file-to-string-transformer

Custom Transformer

XML

<transformer id="testTransformer" input-channel="inChannel" output-channel="outChannel"method="transform"> <beans:bean class="org.foo.CustomTransformer"/> </transformer>

Java

public Message transform(Message message){...}

Adapters

Used to connect the message bus to an external system and to perform any required mapping between the external system and the ESB messages.

  • Out of the box
    • JDBC Adapter
    • JMS Adapter
    • TCP & UDP Adapters
    • Email Adapter
    • HTTP Adapter
    • Web Service Adapter
    • JMX Adapter
    • XMPP Adapter

HTTP Adapter Example

XML

<http:outbound-gateway id="example"     request-channel="requests"     reply-channel="replies"     url="http://localhost/test"     http-method="POST"     extract-request-payload="false"     expected-response-type="java.lang.String"     charset="UTF-8"     request-factory="requestFactory"     request-timeout="200"/>

Mail Adapter Example

XML

<int-mail:inbound-channel-adapter id="imapAdapter"     store-uri="imaps://[username]:[password]@imap.gmail.com/INBOX"     java-mail-properties="javaMailProperties"     channel="recieveChannel"     should-delete-messages="true"     should-mark-messages-as-read="true"     auto-startup="true">         <int:poller max-messages-per-poll="1" fixed-rate="5000"/> </int-mail:inbound-channel-adapter>

Custom Adapter

XML

    <inbound-channel-adapter channel="outChannel" method="process" >         <beans:bean class="org.bar.Foo"/>         <poller fixed-rate="5000"/>     </inbound-channel-adapter>

XML

<outbound-channel-adapter channel="inChannel" method="send">     <beans:bean class="org.bar.Foo"/> </outbound-channel-adapter>

Services

Generic endpoint to connect a service to the messaging system. (The output channel is optional)

Example

Java

public Message execute(Message message){...}

Java

public void execute(Message message){...}

Gateway

Simple interface to allow code outside of the ESB to interact with the ESB, with zero dependenct on the Spring Integration API

Configuration

XML

<si:gateway id="imageMetadataGateway"service-interface="apiserver...ImageMetadataGateway" default-reply-channel="imageMetadataChannelReplyChannel" default-reply-timeout="60">     <int:method name="getMetadataSync" request-channel="imageMetadataChannelRequestChannel">         <int:header name="library" value="drewNoakes"/>     </int:method>     <int:method name="getMetadataAsync" request-channel="imageMetadataChannelRequestChannel">         <int:header name="library" value="drewNoakes"/>     </int:method> </si:gateway>

Code

JAVA

public interface ImageMetadataGateway {     Map getMetadataSync(ImageDocumentJob args);     Future<Map> getMetadataAsync(ImageDocumentJob args); }

Resources

Extra Credit: Javascript ESB

msgs.js part of cujoJS Inspired by Spring Integration (same developers)