Spring消息通信:Spring Integration

jopen 6年前

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.open-open.com/lib/view/home/1385599336906