Steps to work with Spring Integration

Spring Integration

Steps to work with Spring Integration

Агляд

Spring integration can solve many problems faced at the enterprise integration levels. When enterprise applications aim to interact with one another, they can face various problems such as technology incompatibility, communication problems and data parsing or conversion problems. Solving such problems can take a lot of resources which could potentially have been invested in more productive work. Spring integration solves such problems and allows enterprises to focus on more important tasks. Spring integration, which owes its origins to the open source spring framework commissioned by SpringSource, leverages a lot of its capabilities from Spring Framework. Though there is an argument that Spring Framework can solve enterprise integration problems that is not true.








What is Spring Integration?

Spring integration is a framework used to integrate different services to constitute a business solution. The different services are loosely coupled and based on business requirements, could be changed. The ability to modify services easily is a defining feature of the Spring architecture. In a business solution where the Spring integration is involved, the service integration layer is located immediately above the service layer.

The Spring integration architecture follows the popular pipes and filters approach. You can think of the filters as information processing units and the pipes as the conduits of information.

Genesis of Spring Integration

The inspiration behind Spring Integration can be said to be the various patterns that emerge when enterprise application integration is attempted. The key to successful integration lies in understanding and successfully implementing the patterns. Though there are opinions that Spring integration was unnecessary because the Spring Framework has the potential to implement the patterns, the fact is that Spring framework provides just the building blocks for building enterprise applications and Spring integration is specifically meant to implement the patterns. For example, if you build a messaging application with the help of Spring integration, think of the pipes and filters as message channels and message endpoints. The network is carrying messages from one endpoint to another endpoint through channels. The message is validated, routed, раскол, consolidated, sequences re-arranged, reformatted and parsed and enriched as the different endpoints process the data.

Why is Spring Integration necessary?

There is an opinion that Spring framework is capable of enterprise application integration because of its wide array of capabilities. However, the Spring framework, for all its capabilities, is unable to address the unique enterprise integration problems. It is meant to offer building blocks for enterprise application development. To integrate diverse enterprise applications, you need to be able to capture the different unique patterns and solve the problems. Let us understand this with an example.








Let us assume that two applications, A and B need to share data between them. Application A can communicate with external applications only through a direct TCP connection while application B uses a simple web service for accepting reports. Відавочна, the information sharing and acceptance methods are different. To reconcile, you need to do probably several things such as writing a code and have it write periodically, set up a batch process, and parse the data to a format that application B understands. Doing such tasks means a lot of investment. Each of the tasks required to integrate application A and B could be outsourced to a capable application. Each of these tasks can be done by Spring integration. For example, Spring integration can offer a framework or library that connects a TCP and reading and writing streams.

In a nutshell, Spring integration offers services to comprehensively integrate enterprise applications, irrespective of the technology or platform. Secondly, it saves a lot of unnecessary investments on the part of the enterprise.

How does Spring Integration work?

The working of the Spring integration framework is explained below. The following image shows a typical Spring message components and message flow between producer and consumer. This is the simplest form of message and message flow. It can be more complicated based on the type of requirement.

  • Spring architecture can work with any business solution irrespective of their technology and platform. The entire framework is a flexible architecture which can be dynamically configured in a business solution.
  • Spring architecture is especially useful in the context of managing microservices architecture or solutions that have loosely coupled multiple services in the service layer. When you need to disengage one or more services from the architecture, it is easily manageable with the Spring integration capabilities.
  • Spring integration manages the entire gamut of integration activities.









рэалізацыя:

Following is a typical message handler code for XMPP messages. This is for outbound message flow. It also performs the processing part of the message.

Listing 1: Showing message handler

@Bean

@ServiceActivator(inputChannel = “inputchannel”)

public MessageHandler sendChatMsgHandlr(XMPPConnection xmppConn) {

ChatMessageSendingMessageHandler handlr = new ChatMessageSendingMessageHandler(xmppConn);

DefaultXmppHeaderMapper xmppHdrMpr = new DefaultXmppHeaderMapper();

xmppHdrMpr.setRequestHeaderNames(“Test”);

handlr.setHeaderMapper(xmppHdrMpr);

return handlr;

}

Similarly the inbound message flow can be made using polling and listening components. The poller configuration can be done by SourcePollingChannelAdapter, which is another AbstractEndpoint implementation.

Following is a sample configuration of inbound flow.

Listing 2: Sample code for inbound flow

@Bean

@InboundChannelAdapter(значэнне = “inboundChannel”, poller = @Poller(fixedDelay=”4000″))

public MessageSource<?> storedProc(DataSource dtaSrc) {

return new JdbcPollingChannelAdapter(dtaSrc, “SELECT * FROM TEST where status = y”);

}

Following is a sample XML for spring integration. It contains all the components and their bindings.

Listing 3: Sample XML for Spring integration

<?xml version=”1.0″ encoding=”UTF-8″?>

<beans:beans xmlns:int=”HTTP://www.springframework.org/schema/integration”

xmlns:xsi=”HTTP://www.w3.org/2001/XMLSchema-instance”

xmlns:beans=”HTTP://www.springframework.org/schema/beans”

xmlns:int-stream=”HTTP://www.springframework.org/schema/integration/stream”

xsi:schemaLocation=”HTTP://www.springframework.org/schema/beans

HTTP://www.springframework.org/schema/beans/spring-beans.xsd

HTTP://www.springframework.org/schema/integration

HTTP://www.springframework.org/schema/integration/spring-integration.xsd

HTTP://www.springframework.org/schema/integration/stream

HTTP://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd”>

<дзесятковага:gateway id=”testid” service-interface=”techalpine.samples.springint”/>

<дзесятковага:channel id=”classes”/>

<дзесятковага:splitter input-channel=”classes” ref=”classSplitter”

method=”раскол” output-channel=”school”/>

<beans:bean id=”teacher” class=”techalpine.samples.teacher”/>

<дзесятковага:poller id=”pollerid” default=”праўда” fixed-rate=”2000″/>

</beans:beans>








Заключэнне

The main incentive of adopting the Spring integration framework, other than the fact that it is a useful enterprise integration solution, is it is an open source framework. Enterprises can modify or tweak the source code and adapt it to their unique needs. Yet, the original capabilities of the framework will remain pristine and organizations will be able to integrate their software applications. There are also a few alternatives available in the market such as the Camel solution from Apache which is also able to capture the patterns of enterprise integration although overall, Spring integration has been more popular.

============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share