DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

  1. DZone
  2. Refcards
  3. Spring Integration
refcard cover
Refcard #197

Spring Integration

Core Components of the Leading Java Framework

Covers core components, messaging channels, message routing and transformation of this Java- based framework.

Download Refcard
Free PDF for Easy Reference
refcard cover

Written By

author avatar Soby Chacko
Software Engineer, CCAD LLC
author avatar Chris Schaefer
Consultant, VMWare/SpringSource
Table of Contents
► About Spring Integration ► Core Components ► Messaging Channels ► Message Transformation ► Message Endpoints ► Management ► Message History
Section 1

About Spring Integration

by: Soby Chacko and Chris Schaefer

Spring Integration provides a Java-based framework with support for Enterprise Integration Patterns (http://www.eaipatterns.com) and is built on top of the popular Spring Framework. Spring Integration provides messaging capabilities within Spring applications as well as external system integration by way of integration adapters. By using Spring Integration in your application you benefit from a simple programming model for integration patterns, asynchronous message-driven behavior, and loose coupling for modularity and testing purposes. The Spring Integration project home page can be found at:

http://projects.spring.io/spring-integration

As well as the most current Spring Integration documentation located at:

http://docs.spring.io/spring-integration/docs/latest-ga/reference/html

And the source code can be found on GitHub at:

https://github.com/spring-projects/spring-integration

Section 2

Core Components

Message-driven architectures are similar to application architectures but, rather than being "vertical" layers, message-driven architectures are more "horizontal". Messaging systems typically implement a "pipes-and-filters" approach where the "filters" are components that produce or consume messages and the "pipes" transport messages to achieve loose coupling.

Message

Message-driven architectures are similar to application architectures but, rather than being "vertical" layers, message-driven architectures are more "horizontal". Messaging systems typically implement a "pipes-and-filters" approach where the "filters" are components that produce or consume messages and the "pipes" transport messages to achieve loose coupling.

Message Channel

In a messaging system, producers send messages to a channel and consumers receive those messages from a channel. In a message-driven architecture, a Message Channel represents the "pipe" of the "pipes-and-filters" model described above. Not only do Message Channels provide a place through which to produce and consume messages, they also provide the ability for other components to tap into the message flow for interception and monitoring of messages. Message Channels use either a Point-to-Point or Publish/Subscribe model. Point-to-Point messages are used when only one consumer should receive each message from a channel and the Publish/Subscribe channel model will broadcast the message to any subscriber listening to that channel. With Spring Integration, the channel is a "first class citizen" typically endpoints don't know the type of channels they are subscribed to, or publish to. This makes it very easy to reconfigure applications as needs change. This is one of the most important distinctions between Spring Integration and other messaging frameworks.

Message Endpoint

Message Endpoints are components that connect your domain-specific code to the Spring Integration messaging infrastructure. Message Endpoints abstract away the need for application code to be aware of or construct any low-level objects such as Messages or Message Channels. As with the Message Channel, the Message Endpoint makes up the “filters” side of the “pipes-and-filters” architecture in the messaging system. Adapter endpoints provide one-way integration where as gateway endpoints provide two-way request/response integration. This applies for both inbound and outbound endpoints.

Section 3

Messaging Channels

Messaging Channels decouple message producers from message consumers. Message Channels can be Pollable or Subscribable. In this section we look at the Message Channel types provided out of the box by Spring Integration.

Channels

To create a Channel that allows you to broadcast Messages to any of its subscribers, you use the publish-subscribe-channel element from the core Spring Integration XML name space.

​x
1
int:publish-subscribe-channel id="exampleChannel"/>
2
​
3
​

If you want to have a Channel in which a consumer can poll for messages, you create channel with a queue. Even if this channel has multiple consumers, only one of them will receive any Message sent to that channel. You can configure a queue channel in the following way.

4
1
 int:channel id="queueChannel"
2
    queue capacity="25"
3
​
4
​

If you want to have Messages sent based on a priority, you can configure a priority channel.

5
1
 int:channel id="priorityChannel">
2
    int:priority-queue capacity="20"
3
int:channel
4
​
5
​

A priority value in the message header is used for prioritizing messages. However, you can also provide a comparator to customize prioritization.

If you want to have a Channel with a queue associated with it, but at the same time want to also make sure that a Message is being handed off to a consumer before accepting new Messages, you need to create a rendezvous channel. The sending thread will be blocked until a consumer receives the messages. Here is how you may create one.

5
1
 int:channel id="rendezvousChannel"
2
    int:rendezvous-queue
3
int:channel
4
​
5
​

The default channel provided by Spring Integration is called the Direct Channel. It allows you to dispatch any Messages sent to it to a single subscriber, thus blocking the sender thread until the Message is subscribed. It is fairly simple to create a Direct Channel.

3
1
 int:channel id="directChannel"
2
​
3
​

Direct Channel can also be configured with a load-balancing strategy (default uses a round-robin strategy) and supports failover. In some cases, you want to have a Channel that can be subscribed, but at the same time can also scale. In this case, Spring Integration allows you to attach a task executor with the channel definition. This Channel then essentially becomes an Executor Channel. This allows for crafting send methods that don't block and therefore the handler invocation most likely will not occur in the sender's thread. An example is below.

5
1
 int:channel id="executorChannel"
2
    int:dispatcher task-executor="someExecutor"
3
int:channel
4
​
5
​

MessageChannels can be further customized to restrict messages based on certain data types and scope. Here is an example of creating a Direct Channel that only dispatches messages of the type java.lang.String. Also, if a Spring conversion service is registered with the application context, an attempt will be made to convert the payload if an appropriate converter is available.

3
1
 int:channel id="numberChannel" datatype="java.lang.Number"
2
​
3
​

Data types can be grouped together also, as in the following.

4
1
 int:channel id="stringOrNumberChannel"
2
             datatype="java.lang.String,java.lang.Number
3
​
4
​

Channel Adapter

A Channel Adapter is a Message Endpoint that connects a single sender or receiver to a Message Channel. Spring Integration provides adapters for a number of popular technologies, which we will briefly introduce later. However, there are two core channel adapters provided by core Spring Integration that provide you with Method-invoking Chanel Adapter support. On the inbound side, it is simply called the Inbound Chanel Adapter and on the outbound side, it is the Outbound Channel Adapter.

An Inbound Channel Adapter can invoke methods on a Spring-managed bean and send non-null values to a Message Channel as Spring Integration Messages. Here are some examples of configuring an Inbound Channel Adapter.

9
1
 int:inbound-channel-adapter ref="source1" method="method1" 
2
   channel="channel1"
3
int:inbound-channel-adapter
4
​
5
int:inbound-channel-adapter ref="source2" method="method2" 
6
  channel="channel2"
7
int:channel-adapter
8
​
9
​

An Outbound Channel Adapter takes message payloads sent to a channel and invokes methods on a consumer POJO. Here is an example.

5
1
 int:outbound-channel-adapter channel="channel" ref="target" 
2
  method="handle"
3
int:outbound-channel-adapter
4
​
5
​

All Channel Adapters can be created without a channel attribute, in which case it implicitly instantiates a Direct Channel. The Channel name will be the ID of the Channel Adapter. Therefore, either the channel attribute or ID is required on the Channel Adapter.

Message Bridge

Oftentimes it is necessary to connect two types of Message Channels. For example, you might want to connect a PollableChannel to a SubscribableChannel and don't want the subscribing endpoint to deal with a Poller. To achieve this, you use a special type of endpoint called the Messaging Bridge, which will provide the Poller. By setting the max-messages-per-poll and other scheduling attributes appropriately, Messaging Bridge can be used to throttle inbound Messages. Configuring a Messaging Bridge is really simple. Here is an example of connecting a PollableChannel to a SubscribableChannel using a Messaging Bridge that is enabled with throttling by appropriately choosing Poller attributes.

5
1
 int:bridge input-channel="pollable" output-channel="subscribable"
2
     int:poller max-messages-per-poll="10" fixed-rate="5000"
3
int:bridge
4
​
5
​

Routers

Payload Type Router

A Payload Type Router allows you to send messages to a specific channel based on the payload type.

6
1
 int:payload-type-router input-channel="routingChannel">
2
    int:mapping type="java.lang.String" channel="stringChannel"
3
    int:mapping type="java.lang.Integer" channel="integerChannel"
4
int:payload-type-router
5
​
6
​

Header Value Router

A Recipient List Router sends each message to a list of statically defined Message Channels. Recipients can also have an optional selector-expression, which can be used to determine which recipients will receive the message.

7
1
 int:header-value-router input-channel="routingChannel" 
2
  header-name="testHeader"
3
    int:mapping value="someHeaderValue" channel="channelA"
4
    int:mapping value="someOtherHeaderValue" channel="channelB"
5
int:header-value-router
6
​
7
​

Recipient List Router

A Recipient List Router sends each message to a list of statically defined Message Channels. Recipients can also have an optional selector-expression, which can be used to determine which recipients will receive the message.

7
1
 int:header-value-router input-channel="routingChannel" 
2
  header-name="testHeader"
3
    int:mapping value="someHeaderValue" channel="channelA"
4
    int:mapping value="someOtherHeaderValue" channel="channelB"
5
int:header-value-router
6
​
7
​

Generic Router

A generic custom router can be created by extending a Spring Integration class called AbstractMessageRouter. In the following configuration, the ref attribute references the bean name of the custom Router implementation.

4
1
 < int:router ref="customRouter" input-channel="input1"
2
  default-output-channel="defaultOutput1" />
3
​
4
​

Filter

Filter is another endpoint akin to a Router. However, a Filter will not make any decision as to where the Message should be routed; rather it determines whether the Message is sent to its output channel based on certain criteria. The following illustrates the common way of configuring a Filter.

4
1
 < int:filter input-channel="input" output-channel="output"
2
         ref="exampleObject" method="someBooleanReturningMethod" />
3
​
4
​

The referenced method must return a Boolean value. If it returns true, the message will be sent to the output channel; otherwise, it will not be sent. If it is false, you can set the throw-exception-on-rejection attribute to true so an exception will be thrown. Additionally if you want rejected messages to be routed to a specific channel, you can provide a reference to the channel using the discard-channel attribute. You can use SpEL (Spring Expressions Language) expressions as well in a Filter to avoid using helper methods in a bean as in the following.

3
1
 < int:filter input-channel="input" expression="payload.equals('ok')" />
2
​
3
​

Splitter

A Splitter is a component that splits a Message into several parts to be processed independently. In Spring Integration, any POJO can function as a Splitter, given that it has a method that takes a single input argument and return a single, collection or array of Message (or non-Message) objects. Although you can use the Spring Integration API to accomplish splitting, this is the recommended approach as this decouples the application from any Spring Integration knowledge. Here is how you may configure a Splitter using XML.

6
1
 < int:splitter id="splitter" ref="messageSplitterBean" 
2
  method="splitMessage" 
3
  input-channel="inputChannel" 
4
  output-channel="outputChannel" />      
5
​
6
​

In this configuration, the splitMessage method in the object referenced by messageSplitterBean would split the incoming Message into different parts. If no ref or method attribute is provided it would be expected that the incoming payload is already a Collection.

Aggregator

An Aggregator is the reverse of a Splitter, but it is more complex than a Splitter as it needs to maintain state and know when Messages can be combined to form a single Message. Any POJO can act like an Aggregator as long as it has a method that can accept a single java.util.List. Below is an example of configuring an Aggregator using a Spring bean.

10
1
 < int:aggregator                  
2
  input-channel="inputChannel" 
3
  output-channel="outputChannel" 
4
  discard-channel="throwAwayChannel" 
5
  message-store="messageStore" 
6
  ref="aggregatorBean" 
7
  method="aggregate" 
8
  expire-groups-upon-completion="false" />
9
​
10
​

The message-store attribute is used to store messages until the message aggregation is completed. By default, a volatile in-memory store is used. When using a ref/bean combination for aggregation, the method must implement the logic for aggregation. By default, the aggregated Messages will be part of the output payload if no bean available to implement an aggregation logic. If the expire-groups-upon-completion attribute is set to true, the completed groups will be removed from the MessageStore.

Correlation and release strategies can be used with an Aggregator to combine Messages. With the default correlation strategy, Messages with the same CORRELATION_ID in the header are combined. You can override this behavior by implementing the CorrelationStrategy interface. The following is an example of using a correlation strategy with the provided method. For brevity, all other attributes are omitted.

4
1
 < int:aggregator correlation-strategy="correlationStrategyBean" 
2
                correlation-strategy-method="correlate" />
3
​
4
​

The following illustrates using a correlation strategy using a SpEL expression. Remember that you can use one or the other, not both.

4
1
 < int:aggregator correlation-strategy="correlationStrategyBean" 
2
                correlation-strategy-expression="headers['foo']" />
3
​
4
​

Similar to the correlation strategy, either the ref/bean or SpEL can be used, but not both at the same time.

You can add further statefulness to the aggregators by using the MessageGroupStore support available in Spring Integration.

Resequencer

A Resequencer is very similar to an Aggregator, but it does not do any processing on the Messages like an Aggregator does. It simply re-sequences the Messages based on the SEQUENCE-NUMBER header value. Both correlation and release strategy semantics are equivalent to that of the Aggregator. The XML configuration is mostly similar to that of the Aggregator. The namespace element used for resequencer is < int:resequencer>.

Message Handler Chain

The Message Handler Chain can be treated as a single endpoint. Using a Message handler chain, you can initiate a Spring Integration flow easily. It takes an input channel and if the final component is capable of producing a reply, an output channel can also be provided. Here is an example of a flow defined through a message handler chain. Some of the components used in this example will be explained later.

6
1
 < int:chain input-channel="input" output-channel="output">
2
    <int:filter ref="filtRef" />
3
    <int:service-activator ref="someService" method="someMethod" />
4
 </int:chain>
5
​
6
​

As you can see, you can put several components together as a single large endpoint using the Message handler chain support. You can even call other chains from within an outer chain.

Section 4

Message Transformation

Transformer

Message transformers are endpoint types that perform transformation logic on messages, allowing components to produce messages in their native format and not be concerned with the type of message the consumer expects. Transformers can simply be placed between these components and the transformer will take the responsibility for message transformation. An XML example of a Transformer may look similar to:

4
1
 < int:transformer id="myTransformer" ref="myTransformerBean" 
2
    input-channel="input" output-channel="output" method="transform"/>
3
​
4
​

In this example, you should have a Spring bean wired and referenced by the ref attribute along with a method implemented by the name of the method value.

SpEL is also supported using the expression attribute such as:

4
1
 < int:transformer id="myTransformer" input-channel="input" 
2
    output-channel="output" expression="payload.toUpperCase()"/>
3
​
4
​

Annotations are also supported by Transformers, by marking the method to be used as the transformation method with the @Transformer annotation. Method parameters can also be annotated with the @Header and @Headers annotations when values from the MessageHeaders should be mapped.

Spring integration also provides a number of commonly used transformers out of the box, for example:

Namespace Element Purpose
object-to-string-transformer Transforms an Object into its String representation.
payload-serializing-transformer Serializes an Object to a byte array.
payload-deserializing-transformer Serializes a byte array to an Object.
object-to-map-transformer Transforms an Object into a Map.
map-to-object-transformer Transforms a Map into an Object.
object-to-json-transformer Transforms an Object into its JSON representation.
json-to-object-transformer Transforms a JSON message into its Object representation.

In the event that you need to do a simple transformation (for example, removing header names from the output Message), you may do so with a header-filter instead of a full transformer. For example, in XML removing the Social Security Number (SSN) and Date of Birth (DOB) headers would like similar to the following:

3
1
 < int:header-filter input-channel="input" output-channel="output" header-names="ssn, dob"/>
2
​
3
​

Content Enrichers

When receiving a message from an external source, you may find additional information needs to be added to the message. Spring Integration provides this capability using the Content Enricher pattern and provides the following core enrichers as well as adapter-specific enrichers as part of the framework:

Enricher Purpose
Header Enricher Provides the ability to add Headers to a Message.
Payload Enricher Provides the ability to enrich the Message payload itself.
XPath Header Enricher (XML Module Adapter) Evaluates XPath expressions against the Message payload and inserts the result of the evaluation into the Message header.
Mail Header Enricher (Mail Module Adapter) Provides the ability to enrich the headers of a Mail message.
XMPP Header Enricher (XMPP Module Adapter) Provides the ability to enrich the headers of an XMPP message.

Header Enrichers

To simply add headers to a Message you can utilize the Header Enricher pattern support provided by Spring Integration. Adding headers to a Message using XML configuration could look similar to the following:

5
1
 < int:header-enricher input-channel="input" output-channel="output">
2
    < int:header name="static" value="staticValue"/>
3
< /int:header-enricher>
4
​
5
​

The header enricher namespace also provides support for well-known header names and can be configured using the following sub-elements:

10
1
 < int:header-enricher ….>
2
    < int:error-channel ref="errorChannel"/>
3
    < int:reply-channel ref="replyChannel"/>
4
    < int:correlation-id value="12345"/>
5
    < int:priority value="HIGHEST"/>
6
    < int:header name="customHeader" ref="beanName" 
7
      method="beanMethod"/>
8
</ int:header-enricher >
9
​
10
​

As indicated by the enricher subelement header, a Spring bean can be referenced to dynamically determine the value for the header. Simply define and reference a Spring bean by the name referred to in the ref attribute along with the target method to invoke in the method attribute.

Payload Enricher

Payload enrichers allow you to enrich the payload with additional information. It passes a Message to the provided request channel and expects a reply message, which is used to enrich the target message. No request channel is needed if the Message payload only needs to be enriched with static values or expressions:

8
1
 < int:enricher id="userLookupEnricher" 
2
  input-channel="input"
3
  request-channel="requestChannel">
4
    < int:property name="firstName"  
5
      expression="payload.firstName"/>
6
</int:enricher>
7
​
8
​

This configuration results in setting the payload value from requestChannel flow into the firstName property of the payload of target Message.

Claim Check

The Claim Check pattern allows you to store data in a known location, while only maintaining a pointer to that piece of data. The pointer to this location is stored in the payload of a Message allowing components to request the data when it actually needs it. This pattern is useful when a Message payload is very large and would cause a performance bottleneck or, potentially, a security risk.

A basic configuration of an incoming Claim Check Transformer would look similar to the following:

6
1
 < int:claim-check-in id="claimCheckIn"
2
  input-channel="input"
3
  output-channel="output
4
  message-store="messageStore"/>
5
​
6
​

Messages received on the input-channel will be persisted into the configured MessageStore implementation. Messages that are stored get assigned a generated ID (UUID) for Claim Check identification purposes. The returned payload will be the Claim Check ID that gets sent to the output-channel.

An Outgoing Claim Check Transformer is used to obtain the original Message payload. An example configuration would be similar to the following:

6
1
 < int:claim-check-out id="claimCheckOut"
2
  input-channel="input"
3
  output-channel="output"
4
  message-store="messageStore"/>
5
​
6
​

The input-channel should have a Claim Check as its payload. The original payload will be looked up in the MessageStore and then sent back to the output-channel.

Section 5

Message Endpoints

Message Endpoints are responsible for connecting messaging components to channels. Messaging endpoints have two types of consumers, one being polling consumers, the other being event-driven consumers.

Polling

Spring Integration provides a PollingConsumer that allows polling to be scheduled by either a simple interval or a CRON expression. Pollers have many options allowing you as the developer to configure a fixed delay and rate, the number of messages processed per poll, receive timeout and a task executor to use, to name a few. Poller configuration is very simple and a very basic fixed rate example would like something similar to the following:

5
1
 < int:transformer ….>
2
    < int:poller fixed-rate="1000"/>
3
</ int:transformer>
4
​
5
​

Or in the case of a CRON expression:

5
1
 < int:transformer ….>
2
   < int:poller cron="*/10 * * * * MON-FRI"/ >
3
< /int:transformer>
4
​
5
​

Pollers can also be configured as standalone, reusable components and referenced by their ID in the Poller's ref attribute. Global Pollers can be created by simply setting the poller attribute default to true.

Asynchronous Polling

Asynchronous polling can be achieved in the same way as the standard Poller configuration, but with the addition of a TaskExecutor to the configuration. TaskExecutors can also be configured through the Spring task namespace. A simple asynchronous Poller configuration would like similar to the following:

6
1
 < int:transformer ….>
2
    < int:poller fixed-rate="1000" task-executor="myTaskExecutor/>
3
</ int:transformer >
4
< task:executor id="myTaskExecutor" pool-size="5" queue-capacity="5"/>
5
​
6
​

Gateways

Message Gateways hide the underlying messaging API provided by Spring Integration to the client code. Using Message Gateways allows you to code to a standard Java interface rather than coupling your code to the Messaging API itself. By providing an interface, this allows your code to reference the interface and Spring the ability to create a proxy around it, supporting the Message Gateway behavior. A simple gateway configuration could look similar to the following:

5
1
 < int:gateway id="userService" 
2
  service-interface="com.example.UserService" 
3
  default-request-channel="requestChannel"/>
4
​
5
​

Methods of Gateway's service-interface can be configured via annotations by marking them with the @Gateway

Asynchronous gateways are also supported and simply require the return value of the interface referenced by the service-interface attribute to return a standard java.util.concurrent.Future.

Service Activator

A service activator in Spring Integration simply connects any existing Spring-managed bean to a channel. These Spring service beans may or may not return a result. In the event that a result is returned from the service method, it can be returned on the configured output-channel. Service activator configuration is simple, and may look something similar to the following:

7
1
 < int:service-activator 
2
  input-channel="input" 
3
  output-channel="output" 
4
  ref="serviceBean"
5
  method="serviceBeanMethod"/>
6
​
7
​

This will configure a service activator component which receives messages from the specified input-channel, calls the method declared by the method attribute on the provided bean configured via the ref attribute and returns its result to the defined output-channel.

Delayer

A delayer is a simple, but useful component in Spring Integration that allows you to delay a Message flow by a certain defined interval. When a Delayer is used, the sender is not blocked and messages to be delayed are scheduled for delivery by a standard Spring TaskScheduler. There are a few ways that a Delayer can be configured, most commonly to delay all messages by the defined interval or on a per-Message basis.

Using XML, to configure all messages to be delayed by a specific interval, a typical configuration may look like the following:

4
1
 < int:delayer id="delayer" input-channel="input" 
2
  output-channel="output" default-delay="1000"/>
3
​
4
​

Using XML again, to use a Delayer on a per-Message basis, a simple configuration may look like the following:

5
1
 < int:delayer id="delayer" input-channel="input" 
2
  output-channel="output" default-delay="1000" 
3
  delay-header-name="delay"/>
4
​
5
​

This configuration will create a delayer that delays any message by the value specified in the delay-header-name attribute. If this header value is not present, the delay amount will default to the value configured in the default-delay attribute.

Section 6

Management

JMX Support

Spring Integration provides monitoring support through JMX. It comes with both inbound and outbound channel adapters for JMX for receiving and publishing JMX notifications. The notification listening channel adapter is an inbound channel adapter that is used to listen for events for which an MBean is publishing data. A JMX MBean has to be configured through an attribute called object-name. Here is an example of a basic Notification listening channel adapter.

5
1
< int-jmx:notification-listening-channel-adapter id="adapter"
2
  channel="channel"
3
  object-name="example.domain:name=publisher"/>
4
​
5
​

The Notification publishing channel adapter is pretty much the same as the inbound listening adapter, but it has to be aware of the MBeanExporter in the context. Here is an example of configuring a JMX publishing channel adapter.

6
1
 < context:mbean:export/>
2
< int-jmx:notification-publishing-channel-adapter id="adapter"
3
  channel="channel"
4
  object-name="example.domain:name=publisher"/>
5
​
6
​

In addition to these, the JMX support also allows you to define an attribute polling channel adapter, which is used to periodically poll on values that are available through an MBean as a managed attribute. Additionally, there is an Operation-invoking channel adapter that allows you to invoke any managed operation exposed by an MBean. Using message payloads, you can pass arguments to the operations. Operation invoking outbound gateway allows you to create bi-directional gateways to extract the return value of the operation to a reply channel configured by the gateway.

Spring Integration components themselves can become MBeans and can be monitored directly. They will be exposed as MBeans when the IntegrationMBeanExporter is configured. Here is an example for exporting the components under the domain com.data.domain as MBeans.

8
1
 < int-jmx:mbean-export default-domain="com.data.domain" 
2
  server="mbeanServer"/>
3
< bean id="mbeanServer"  
4
  class="org.springframework.jmx.support.MBeanServerFactoryBean">
5
    < property name="locateExistingServerIfPossible" value="true"/>
6
</ bean>
7
​
8
​

Then you can start your application in the normal way that you start an application that needs JMX support and uses tools like JConsole to connect the MBeanServer and monitor components under the specified domain.

Section 7

Message History

Message History is a great way to trace a Message, especially when you want to troubleshoot certain issues. Each time a Message goes through a tracked component, it will add a header to the Message. The history data will be maintained as a collection in the header of the Message. Here is an example of configuring Message History.

3
1
 <int:message-history tracked-components="*Channel, router"/>
2
​
3
​

Message Store

Often times when you have components that save the message state, you probably want to persist those Messages using a message store. You can expose a message store through the message-store attribute on components that allow buffering. The default Message Store provided by Spring Integration is an in-memory-based one, but there are other persistent implementations available, such as JDBC, Redis, MongoDB, and Gemfire message stores.

Control Bus

Control Bus allows you to use the same messaging system for managing and monitoring messaging components such as channels and endpoints. You can therefore send a Message to invoke a method. Any Spring beans with methods annotated with either @ManagedAttribute or @ManagedOperation can be invoked through a control bus. You can send messages with payload as a SpEL expression to initiate the operations. Here is how you may configure a control bus:

3
1
 < int:control-bus input-channel="commandChannel"/>
2
​
3
​

The input channel contains Messages with a SpEL expression and the control bus will take this expression and invoke the corresponding operation.

Here is an example of how to build a Message that instructs to execute a method on a bean:

5
1
 Message command = MessageBuilder.withPayload("@commandBean.print()")
2
                 .build();
3
commandChannel.send(command)
4
​
5
​

Spring Integration Adapters

Spring Integration provides several adapters for various systems, protocols, and third-party components. Most of them come with inbound and outbound channel adapters and gateway components wherever applicable. The following table lists a short summary of the common adapters that are used widely.

Adapter Summary
AMQP Provides channel adapters for sending and receiving AMQP
Spring Application Event Inbound and outbound adapters for Spring Framework ApplicationEvents.
File Provides support for reading, writing, and transforming files. There are inbound and outbound channel adapters and an outbound gateway provided.
FTP/FTPS Provides inbound, outbound , outbound gateway, and session caching support for file transfer operations.
Gemfire Provides inbound and outbound channel adapters for the Gemfire distributed caching system.
HTTP Inbound and outbound gateways for HTTP request/response. Supports various HTTP methods.
TCP and UDP Channel adapters for sending and receiving messages over TCP and UDP.  Both of them provide one-way channel adapters and TCP provides a simple gateway support for two-way communication.
JDBC Channel adapters for sending and receiving messages over JDBC. Provided components are inbound and outbound channel adapters, outbound gateway, stored-procedure inbound and outbound channel adapters, and stored-procedure outbound gateway. 
JPA Adapters for performing various database operations using JPA. Inbound and outbound channel adapters as well as updating and retrieving outbound gateways are provided.
JMS Adapters for sending and receiving JMS messages. Two flavors of inbound channel adapter are provided: one using Spring’s JMSTemplate and the other based on a message-driven behavior. An outbound channel adapter is also provided.
Mail Adapters for sending and receiving mail messages. 
MongoDB Inbound and outbound channel adapters for MongoDB.
Redis Inbound and outbound channel adapters for Redis.
Resource An inbound channel adapter built on top of Spring’s Resource abstraction. 
RMI Provides RMI inbound and outbound gateways.
SFTP Inbound and outbound channel adapters and outbound gateway support for secure FTP.  
Stream Inbound and outbound channel adapters for streams.
Twitter Provides support for Twitter through various types of inbound channel adapters such as timeline, mentions, direct, and search. The outbound channel adapter provides update and direct channel  adapters.
Web Services Provides outbound and inbound webservice gateways.
XMPP Inbound and outbound channel adapters for XMPP/XMPP presence.

In addition to out of the box adapters provided by Spring Integration, there is also a community supported Spring Integration Extensions project. This project provides integration touch points with various technologies. Details about this project can be found at:
https://github.com/spring-projects/spring-integration-extensions

Spring Integration also has support for Scala and Groovy DSL's. You may find more details about these projects at the following URL's:

https://github.com/spring-projects/spring-integration-dsl-scala

https://github.com/spring-projects/spring-integration-dsl-groovy

Like This Refcard? Read More From DZone

related article thumbnail

DZone Article

Spring XD 1.2 GA, Spring XD 1.1.3 and Flo for Spring XD Beta Released
related article thumbnail

DZone Article

The Truth About AI and Job Loss
related article thumbnail

DZone Article

MySQL Formatter: How to Make Beautiful Code and Why You Need It
related article thumbnail

DZone Article

How to Improve Copilot's Accuracy and Performance in Power BI
related refcard thumbnail

Free DZone Refcard

GraphQL Essentials
related refcard thumbnail

Free DZone Refcard

API Integration Patterns
related refcard thumbnail

Free DZone Refcard

Getting Started With Cross-Platform Heterogeneous Computing
related refcard thumbnail

Free DZone Refcard

Introduction to Digital Asset Management via APIs

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: