【IT168 管理】SCA提供了实现面向服务的架构(SOA)的一个编程模型。
面向服务的架构已经在软件开发领域存在很多年了。但是当一些组织试图去定义最佳的实现和管理技能的时候,为一个特定组织开发一个SOA的细节却是难以捉摸的。在这篇文章里,我将介绍SOA的一种实现方式——服务-组件架构。
SOA在概念上来说是关于松耦合的行为。业务和系统功能作为大的独立服务被展现,使得它们以不同的方式在业务流的组合中被使用。这是一个简单的描述,但实现起来就相当的复杂了。任何使用EAI和分布式技术的人都能回忆起在一个企业里兜售业务功能的困难。
SOA原理是抽象的,独立于实现技术。从开发角度来看,定义SOA构成是有帮助的,它使得工程师可以无须求助于技术规范来用具体术语讨论开发实现。为了这个目标,开放面向服务的架构(OSOA)组织发布了服务组件架构(SCA)规范1.1(www.osoa.com)。
SCA已经被IBM,BEA,Sun,Software AG,IONA,SAP,和Oracle以及其他一些公司开发很多年了。可以在IBM,Rogue Wave,Oracle,Tibco,Apache Software Foundation(Tuscany)和Eclipse Foundation(SOA Tools Platform)获取实现。
SCA编程模型
SCA编程模型主要通过提供一个服务的开发,集合,部署的方法,来关注SOA的工程细节。为了和SOA原理一致,SCA通过元数据驱动,语言独立和容器独立来支持异构的实现。只要一个从SCA规范到技术的映射可以被定义,SCA就能被实现。于是,SCA被和多种语言和容器绑定;最近的一个C语言规范以及形成草案。
目前,SCA映射已经存在于Java,C++,Ruby,Spring,和BPEL及其他语言中。另外,SCA绑定也在web服务,JMS,JCA和其他通信机制中存在。SCA的目标是减少SOA的概念原理到可以在一个具体上下文中讨论的具体元素集合。
SCA的好处有:
·使用组件和组合简化SOA实现
·使用松耦合的组件和参考来支持敏捷特性
·通过一个综合的调用模型支持事件驱动的行为
·将开发和集合分开,允许技术不可知的组合
建立服务:程序集(Assembly)模型
程序集模型描述了服务是如何被定义和配置的。
组件是SCA模型的核心,可以用支持SCA的任何语言来实现。一经定义,组件可以使用属性来声明配置,这将在接下来的实现中映射到accessor和mutator。
下面的是一个XML声明的组件。
//例1:组件声明(a) <component name="AddServiceComponent"> <implementation.java class="calculator.AddServiceImpl"/> </component> (b) <component name="CalculatorServiceComponent"> <implementation.java class="calculator.CalculatorServiceImpl"/> <reference name="addService">AddServiceComponent</reference> </component>
引用使得组件可以调用其他服务。引用在部署时或运行时被解析。例1(b)显示了一个例子引用。
组合是组件的群。根据声明,一个组合可以被作为一个服务或者新的组件使用。因此,SCA模型支持递归程序集。
如果你通过将服务元素包含在组合声明里,那服务本质就是组合。和组件类似,组合和服务可以通过属性来声明配置。就像你可以从SCA程序集的元素声明里看到的一样,已有的程序可以通过将应用建模为一个组件,组合或者提供一个可调用的程序接口而添加到架构中来。
布线(Wiring)
组件连接是通过布线来完成的,也就暗示了需要定义组件之间的源/目标信息。和其他SCA元素一样,布线细节可以被声明设置。SCA布线不需要元和目标是一个相同的类型(比如Java到WSDL的接口就是可接受的),只要考虑到了诸如远端性,回调支持,容错,和异常处理等的兼容性。例3(a)是一个简单的布线实例。
//例2:引用声明<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="CalculatorComposite"> <service name="CalculatorService"> <interface.java interface="calculator.CalculatorService"/> <reference>CalculatorServiceComponent</reference> </service> <component name="CalculatorServiceComponent"> <implementation.java class="calculator.CalculatorServiceImpl"/> <reference name="addService">AddServiceComponent</reference> ... </component> <component name="AddServiceComponent"> <implementation.java class="calculator.AddServiceImpl"/> </component> ... </composite>
//例3:(a)引用中的直接布线(b)和一个web服务绑定的引用(a) <reference name="stockQuoteService" target="StockQuoteMediatorComponent"/> (b) <reference name="HelloWorldService"> <interface.java interface="helloworld.HelloWorldService" callbackInterface="helloworld.HelloWorldCallback"/> <interface.wsdl xmlns:wsdli="http://www.w3.org/2006/01/wsdl-instance" interface=
"http://helloworld#wsdl.interface(HelloWorld)" callbackInterface="http://helloworld#wsdl.interface(HelloWorldCallback)" wsdli:wsdlLocation="http://helloworld wsdl/helloworld.wsdl" /> <binding.ws endpoint= "http://helloworld#wsdl.endpoint(HelloWorldService/HelloWorldSoapPort)"
location="wsdl/helloworld.wsdl" /> </reference>
//例4:(a)Intent声明;(b)Profile声明
(a) <intent name="confidentiality" constrains="sca:binding"> <description> Communication through this binding must prevent unauthorized users from reading the messages. </description> </intent> (b) <sca:profile intents="sec.confidentiality rel.reliability"/>
//例5:使用一个intentMap和WS-PolicyAttachment的Policy Set<policySet name="SecureMessagingPolicies" provides="confidentiality" appliesTo="binding.ws" xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"> <intentMap provides="confidentiality" default="transport"> <qualifier name="transport"> <wsp:PolicyAttachment> <wsp:AppliesTo> <wsa:EndpointReference xmlns:myStore="..." > <wsa:Address>http://myStore.example.com/acct </wsa:Address> <wsa:PortType> myStore:myPortType </wsa:PortType> <wsa:ServiceName> myStore:InventoryService </wsa:ServiceName> </wsa:EndpointReference> </wsp:AppliesTo> <wsp:PolicyReference URI="http://myStore.example.com/policies.xml" /> </wsp:PolicyAttachment> <wsp:PolicyAttachment> ... </wsp:PolicyAttachment> </qualifier> <qualifier name="message"> <wsp:PolicyAttachment> <!-- policy expression and policy subject for "message" alternative" --> ... </wsp:PolicyAttachment> </qualifier> </intentMap> </policySet>
//例6:连接在服务上的Profile
<sca:service name="mySpecialService"> <sca:interface.wsdl portType="..." /> <sca:profile intents="sec.authentication rel.reliabilty"/> </sca:service>
| 第1页: 用SCA实现SOA的编程模型 |