标签: DSL

  • 使用Java DSL配置Spring Integration

    Spring Integration是Spring下的一个项目,主要为了扩展Spring现有的模型已支持Enterprise Integration Patterns。

    Spring Integration还和其他项目结合紧密,比如Spring XD就可以使用其作为输入来源。

    Spring Integration可以完全依赖于xml工作,即意味着一个核心系统完成后,可以只单单更改xml配置本身来完成相关功能变更。

     

    但是xml配置也有不便利的地方,特别是在项目开发初期,对于开发人员而言,xml的表达能力自然不如java,在需要功能扩展的时候也必须需要java代码才行。

    而Spring的一个新的子项目spring-integration-java-dsl就可以实现使用java dsl来配置相关功能。

    以最简单的消费atom源为例,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 http://www.springframework.org/schema/integration/feed/spring-integration-feed.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
    http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
    <feed:inbound-channel-adapter id="news" url="https://spring.io/blog.atom">
    <int:poller fixed-rate="5000"/>
    </feed:inbound-channel-adapter>
    <int:transformer