Spring消息通信:Spring Integration

jopen 11年前發布 | 64K 次閱讀 Spring JEE框架

Spring Integration能在基于Spring的應用中進行簡單的消息通信,并通過簡單的適配器與外部系統集成。這些適配器提供了一個更高級別的抽象,超越 了Spring對遠程調用、消息和調度的支持。其主要目標是在保持關注點分離的同時,為構建企業集成解決方案提供一個簡單的模型,該模型對產出可維護、可 測試的代碼來說是必不可少的。
功能特性:

  • Implementation of most of the Enterprise Integration Patterns
    • Endpoint
    • Channel (Point-to-point and Publish/Subscribe)
    • Aggregator
    • Filter
    • Transformer
    • Control Bus
    • ...
  • Integration with External Systems
    • ReST/HTTP
    • FTP/SFTP
    • 推ter
    • WebServices (SOAP and ReST)
    • TCP/UDP
    • JMS
    • RabbitMQ
    • Email
    • ...
  • The framework has extensive JMX support
    • Exposing framework components as MBeans
    • Adapters to obtain attributes from MBeans, invoke operations, send/receive notifications

public class Main {

    public static void main(String... args) throws Exception {
        ApplicationContext ctx =
            new ClassPathXmlApplicationContext("context.xml");
        // Simple Service
        TempConverter converter =
            ctx.getBean("simpleGateway", TempConverter.class);
        System.out.println(converter.fahrenheitToCelcius(68.0f));
        // Web Service
        converter  = ctx.getBean("wsGateway", TempConverter.class);
        System.out.println(converter.fahrenheitToCelcius(68.0f));
    }
}
public interface TempConverter {

    float fahrenheitToCelcius(float fahren);

}
<!-- Simple Service -->

<int:gateway id="simpleGateway"
    service-interface="foo.TempConverter"
    default-request-channel="simpleExpression" />

<int:service-activator id="expressionConverter"
    input-channel="simpleExpression"
    expression="(payload - 32) / 9 * 5"/>

<!-- Web Service -->

<int:gateway id="wsGateway" service-interface="foo.TempConverter"
    default-request-channel="viaWebService" />

<int:chain id="wsChain" input-channel="viaWebService">
    <int:transformer
       expression="'&lt;FahrenheitToCelsius xmlns=''http://tempuri.org/''&gt;&lt;Fahrenheit&gt;XXX&lt;/Fahrenheit&gt;&lt;/FahrenheitToCelsius&gt;'.replace('XXX', payload.toString())" />
    <int-ws:header-enricher>
        <int-ws:soap-action value="http://tempuri.org/FahrenheitToCelsius"/>
    </int-ws:header-enricher>
    <int-ws:outbound-gateway
        uri="http://www.w3schools.com/webservices/tempconvert.asmx"/>
    <int-xml:xpath-transformer
        xpath-expression="/*[local-name()='FahrenheitToCelsiusResponse']/*[local-name()='FahrenheitToCelsiusResult']"/>
</int:chain>

項目主頁:http://www.baiduhome.net/lib/view/home/1385599336906

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!