目录

Introduction

Spring Integration Components

Message

Channel

EndPoint

Channel Adapter

Messaging Gateway

Service Activator

Router

Splitter

Aggregator

Messaging

Integrating systems

Get Started with Spring Integration

公司的案例

其他资源


官方文档: https://spring.io/projects/spring-integration

(有PDF:https://docs.spring.io/spring-integration/docs/current/reference/pdf/spring-integration-reference.pdf)

Get Started with Spring Integration: https://spring.io/guides/gs/integration/

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

书籍推荐:《Spring Integration in Action》;《Spring Integration Essentials》

Introduction

Spring Integration provides an extension of the Spring programming model to support the well-known enterprise integration patterns. It enables lightweight messaging within Spring-based applications and supports integration with external systems via declarative adapters. Those adapters provide a higher level of abstraction over Spring’s support for remoting, messaging, and scheduling.

ARCHITECTURE

  • Lightweight message-driven architecture
  • Passes messages using "pipes and filters"
  • No direct tie in to an enterprise service bus
  • Leverages task schedulers and task executers
  • Adapters facilitate communication between systems

Two areas of focus for Spring Integration: lightweight intra-application messaging and flexible interapplication integration

The figure contains several boxes, and those boxes are connected via pipes. Now substitute “filters” for boxes, and you have the classic pipes-and-filters architectural style.

Anyone familiar with a UNIX-based operating system can appreciate the pipes-and-filters style: it provides the foundation of such operating systems. Consider a basic example:

$> echo foo | sed s/foo/bar/
bar

You can see that it’s literally the pipe symbol being used to connect two commands (the filters). It’s easy to swap out different processing steps or to extend the chain to accomplish more complex tasks while still using these same building blocks (returns elided):

$> cat /usr/share/dict/words | grep ^foo | head -9 | sed s/foo/bar/
bar bard barder bardful bardless bardlessness bardstuff bardy barfaraw

Adapters are used to map the content from outbound messages into the format that some external system expects to receive and to map inbound content from those external systems into messages.

AVAILABLE ADAPTERS

  • Data stores (JDBC, MongoDB, JPA)
  • File stores (File system, FTP, SFTP)
  • HTTP
  • Mail (POP3 or IMAP for receiving, SMTP for sending)
  • Messaging (AMQP, JMS)
  • Twitter
  • Web Services (SOAP, REST, JSON)
  • User Datagram Protocol (UDP)
  • Transmission Control Protocol (TCP)
  • Java Management Extensions (JMX)
  • Remote Method Invocation (RMI)
  • Really Simple Syndication (RSS) feeds
  • Extensible Messaging and Presence Protocol (XMPP)

附:

JDBC: Java Database Connectivity。

SFTP: Secured File Transfer Protocol。

AMQP: Advanced Message Queuing Protocol,一个提供统一消息服务的应用层标准高级消息队列协议,是应用层协议的一个开放标准,为面向消息的中间件设计。

SOAP: Simple Object Access Protocol,简单对象访问协议,是交换数据的一种协议规范。

REST: Representational State Transfer, 表述性状态传递,REST API 也称为 RESTful API,是遵循 REST 架构规范的应用编程接口(API 或 Web API),支持与 RESTful Web 服务进行交互。

JSON: JavaScript Object Notation,Javascript 对象表示法。

除了Spring Integration,Spring还提供其他Options:

详情请参考:

https://spring.io/event-driven

Spring Integration Components

Message

Each message consists of headers and a payload. The header contains data that’s relevant to the messaging system, such as the Return Address or Correlation ID. The payload contains the actual data to be accessed or processed by the receiver. Messages can have different functions. For example, a Command Message tells the receiver to do something, an Event Message notifies the receiver that something has happened, and a Document Message transfers some data from the sender to the receiver.

The message is a representation of the contract between the sender and receiver. In some applications the message might be fine to send a reference to an object over the channel, but in others it might be necessary to use a more interoperable representation like an identifier or a serialized version of the original data.

Channel

Channels can be categorized based on two dimensions: type of handoff and type of delivery. The handoff can be either synchronous or asynchronous, and the delivery can be either point-to-point or publish-subscribe.

EndPoint

Message endpoints can be as simple as routing to another channel or as complicated as splitting the message into multiple parts or aggregating the parts back together. Connections to the application or the outside world are also endpoints, and these connections take the form of channel adapters, messaging gateways, or service activators.

Channel Adapter

Messaging Gateway

Service Activator

Router

Splitter

Aggregator

Messaging

  • Messages and channels

  • Message Endpoints

  • Splitting and aggregating message

  • Routing and filtering

Integrating systems

  • Handling messages with XML payloads

// Transforming between XML and Java
// Transforming XML using XSLT
// Routing and splitting with XPath
// Validating XML messages
  • Spring Integration and the Java Message Service (JMS)

  • Email-based integration

  • Filesystem integration

  • Spring Integration and web services

Get Started with Spring Integration

(Spring官网)

Using Spring Integration to create a simple application that retrieves data from an RSS Feed (Spring Blog), manipulates the data, and then writes it to a file. This guide uses traditional Spring Integration XML configuration. Other guides show how to use Java Configuration and DSL with and without JDK 8 Lambda expressions.

下载https://spring.io/guides/gs/integration/官网的zip包打开是这样的:

在新窗口单独打开"complete"这个project:

主要文件:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.6.3</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>integration-complete</artifactId><version>0.0.1-SNAPSHOT</version><name>integration-complete</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-integration</artifactId></dependency><dependency><groupId>org.springframework.integration</groupId><artifactId>spring-integration-feed</artifactId></dependency><dependency><groupId>org.springframework.integration</groupId><artifactId>spring-integration-file</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.integration</groupId><artifactId>spring-integration-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

IntegrationApplication.java

package com.example.integration;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ImportResource;@SpringBootApplication
@ImportResource("/integration/integration.xml")
public class IntegrationApplication {public static void main(String[] args) throws Exception {ConfigurableApplicationContext ctx = new SpringApplication(IntegrationApplication.class).run(args);System.out.println("Hit Enter to terminate");System.in.read();ctx.close();}}

integration.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:int="http://www.springframework.org/schema/integration"xmlns:file="http://www.springframework.org/schema/integration/file"xmlns:feed="http://www.springframework.org/schema/integration/feed"xsi:schemaLocation="http://www.springframework.org/schema/integration/feed https://www.springframework.org/schema/integration/feed/spring-integration-feed.xsdhttp://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/integration/file https://www.springframework.org/schema/integration/file/spring-integration-file.xsdhttp://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd"><feed:inbound-channel-adapter id="news" url="https://spring.io/blog.atom" auto-startup="${auto.startup:true}"><int:poller fixed-rate="5000"/></feed:inbound-channel-adapter><int:transformerinput-channel="news"expression="payload.title + ' @ ' + payload.link + '#{systemProperties['line.separator']}'"output-channel="file"/><file:outbound-channel-adapter id="file"mode="APPEND"charset="UTF-8"directory="/tmp/si"filename-generator-expression="'${feed.file.name:SpringBlog}'"/></beans>

Three integration elements are in play here:

  • <feed:inbound-channel-adapter>: An inbound adapter that retrieves the posts, one per poll. As configured here, it polls every five seconds. The posts are placed into a channel named news (corresponding to the adapter’s ID).

  • <int:transformer>: Transforms entries (com.rometools.rome.feed.synd.SyndEntry) in the news channel, extracting the entry’s title (payload.title) and link (payload.link) and concatenating them into a readable String (and adding a newline). The String is then sent to the output channel named file.

  • <file:outbound-channel-adapter>: An outbound channel adapter that writes content from its channel (named file) to a file. Specifically, as configured here, it appends anything in the file channel to a file at /tmp/si/SpringBlog.

FlowTests.java

package com.example.integration;import static org.assertj.core.api.Assertions.assertThat;import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;import org.junit.jupiter.api.Test;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;import com.rometools.rome.feed.synd.SyndEntryImpl;@SpringBootTest({ "auto.startup=false",     // we don't want to start the real feed"feed.file.name=Test" })   // use a different file
public class FlowTests {@Autowiredprivate SourcePollingChannelAdapter newsAdapter;@Autowiredprivate MessageChannel news;@Testpublic void test() throws Exception {assertThat(this.newsAdapter.isRunning()).isFalse();SyndEntryImpl syndEntry = new SyndEntryImpl();syndEntry.setTitle("Test Title");syndEntry.setLink("http://characters/frodo");File out = new File("/tmp/si/Test");out.delete();assertThat(out.exists()).isFalse();this.news.send(MessageBuilder.withPayload(syndEntry).build());assertThat(out.exists()).isTrue();BufferedReader br = new BufferedReader(new FileReader(out));String line = br.readLine();assertThat(line).isEqualTo("Test Title @ http://characters/frodo");br.close();out.delete();}}

Run the application:

If you use Gradle, you can run the application by using ./gradlew bootRun. Alternatively, you can build the JAR file by using ./gradlew build and then run the JAR file, as follows:

java -jar build/libs/gs-integration-0.1.0.jar

If you use Maven, you can run the application by using ./mvnw spring-boot:run. Alternatively, you can build the JAR file with ./mvnw clean package and then run the JAR file, as follows:

java -jar target/gs-integration-0.1.0.jar

Verification:

tail -f /tmp/si/SpringBlog

see the following sample output (though the actual news will differ):

Testing the application: (passed)

公司的案例

(后续整理)

其他资源

JMS Provider:ActiveMQ, Kafka, IBM WebSphere MQ, Solace,RabbitMQ, RocketMQ等

JMS,ActiveMQ,Solace和RxJava记录_Beth_Chan的博客-CSDN博客

Kafka记录_Beth_Chan的博客-CSDN博客

IBM WebSphere MQ_Beth_Chan的博客-CSDN博客

Java实时处理 - Spring Integration - MQ Message相关推荐

  1. #翻译NO.3# --- Spring Integration Framework

    为什么80%的码农都做不了架构师?>>>    2.4 Message Endpoints A Message Endpoint represents the "filte ...

  2. Spring Integration 快速入门教程

    本文通过小的实际示例介绍Spring Integration(SI)的核心概念.Spring Integration提供了许多功能强大的组件,这些组件可以极大地增强企业架构内系统和流程的互连互通. 它 ...

  3. spring集成mq_使用Spring Integration Java DSL与Rabbit MQ集成

    spring集成mq 我最近参加了在拉斯维加斯举行的2016年Spring大会 ,很幸运地看到了我在软件世界中长期敬佩的一些人. 我亲自遇到了其中的两个人,他们实际上合并了几年前我与Spring In ...

  4. 使用Spring Integration Java DSL与Rabbit MQ集成

    我最近参加了在拉斯维加斯举行的2016年Spring会议 ,很幸运地看到了我在软件世界中长期敬佩的一些人. 我亲自遇到了其中的两个人,他们实际上合并了几年前我与Spring Integration相关 ...

  5. mongodb dsl_具有Java DSL的Spring Integration MongoDB适配器

    mongodb dsl 1引言 这篇文章解释了如何使用Spring Integration从MongoDB数据库中保存和检索实体. 为了完成此任务,我们将使用Java DSL配置扩展来配置入站和出站M ...

  6. 带有Java DSL的Spring Integration MongoDB适配器

    1引言 这篇文章解释了如何使用Spring Integration从MongoDB数据库中保存和检索实体. 为了实现这一点,我们将使用Java DSL配置扩展来配置入站和出站MongoDB通道适配器. ...

  7. Spring Integration Java DSL示例

    现在已经为Spring Integration引入了新的基于Java的DSL ,这使得可以使用基于纯Java的配置而不是基于Spring XML的配置来定义Spring Integration消息流. ...

  8. java中channelmessage,MessageStore支持的QueueChannel与Spring Integration Java Config

    Spring Integration reference guide指的是使用MessageStore实现为QueueChannel提供持久性. 提到了很多次,但是所有示例都使用XML配置,即 但是Q ...

  9. Java开源项目:Spring Integration

    2019独角兽企业重金招聘Python工程师标准>>> Java开源项目:Spring Integration http://www.importnew.com/16538.html ...

最新文章

  1. App市场的“繁荣”背后 隐藏令人唏嘘的真相
  2. Silverlight与WCF之间的通信(4)silverlight以net.tcp方式调用console上寄宿的wcf服务
  3. 《游戏设计师修炼之道:数据驱动的游戏设计》一3.8小结
  4. leetcode1119. 删去字符串中的元音 小学难度
  5. 【STM32】高级定时器、通用定时器和基本定时器---配置寄存器产生PWM
  6. 【MySQL】MySQL常见的读写分离方法
  7. python整数运算_深入 Python (6) 整数对象的数学运算
  8. Eclipse下Pydev在线安装失败及解决办法
  9. python matplot模块
  10. Swift TouchId指纹解锁,FaceId面部解锁
  11. 卡巴斯基重新激活试用版的方法
  12. Java打印条码,使用热敏条码打印机
  13. python根据题库答案自动答题_直播答题助手 自动检测出题、搜索答案
  14. java pageoffice_JAVA调用PageOffice在线打开、编辑Word文档
  15. 六、Xbar-R、柏拉图管制分析
  16. python中fn是什么意思_按Fn键Python 3
  17. 腾讯加盟:Kafka-on-Pulsar 项目迎来 2 位腾讯 Maintainer!
  18. 阿里云云效平台配置持续集成--java篇
  19. matlab里正负号怎么表示,正负号符号上下一起怎么输入?
  20. PyQt5最全60 容器之QMdiArea和QMdiSubWindow容纳多文档的窗口

热门文章

  1. 用C#制作文本剧情游戏
  2. 输入nvidia-smi不能查看显卡NVIDIA型号的解决办法及快速查看电脑显卡NVIDIA型号信息
  3. 基于深度学习的印刷电路板瑕疵识别
  4. 什么镜头最适合拍风景_风景用什么镜头好
  5. 计算机网络中m的含义,宽带中的“M(兆)”是什么意思?
  6. python3---字符串
  7. vue 项目 webstrom IDE格式化代码规则遵循eslint设置
  8. 三星java世界x108_我对三星X100/X108的使用感受
  9. 《炬丰科技-半导体工艺》化学清洗过程中重金属污染的监测方法
  10. linux语言是什么意思,linux怎么读(linux什么意思,准确发音是什么)