面向服务的体系架构
面向服务的体系架构
SO vs OO
• SO 是对 OO的补充 • SO是为服务的整合而生 • SO 把互联作为首要的目标
– 提供平台无关互操作能力 – 提供更多的互联:同步,异步,one-way, two-way, request-response, queued, streamed communication
– – 服务之间的通信方式灵活,而不是固定某种方式 服务之间交互不需要了解彼此的运行环境 Services scale well in all directions. For example, a service can be scaled out by fronting it with a router service that distributes traffic among a farm of services If services make use of queue-based communication, they don't have to be online at the same time to interact. If services employ a discovery mechanism, they can locate each other without any prior notion about where they reside Restricting, relocating, or outsourcing a service requires changes only in policy, not to the service itself.
平台无关、实现无关
•
• • •
Services are scale invariant
– – – –
Services can be time independent Services can be address agnostic. Behavior is separated from constraints
• SO是松耦合而OO是紧耦合
– 基于OO的系统往往通过类库之间的依赖耦合 – 基于SO的系统通过Message互相关联
SO的四个原则
• 边界清晰
– 每次服务的交互都是需要跨越边界的 – 跨越边界需要付出较高的代价 – 服务的交互需要清晰考虑
•
服务自治
– – – – – 服务完成的功能具有较强的内聚性 服务不会因为依赖的服务不可用而失败 服务的部署,管理,升级是彼此无关的 整个基于服务的系统在拓普布局会随着时间演化,而不影响系统 整个基于服务的系统没有控制权威
Service剖析(Ext)
• 从外部看Service暴露了一个service description和 一组Endpoint • Service描述
– WSDL:描述Service可以做什么,如何访问,Service位 置 – XSD:用来描述Service中消息的结构 – WS-Policy:描述Service的约束,如需要满足的安全要 求,QOS等 – WS-MEX:客户用来获取服务描述自己的元信息 (WSDL, WS-Policy)访问协议
SO对平台的要求
• • • 统一的编程模型
– – – – – – – 能够整合多种服务实现技术和交互技术 多种传输方式(Transport),消息格式(MF),消息交互模式(MEP)可供选择 平台无关 基于SOAP的能力 遵循WebService的架构 使用已有的通信标准WS-*协议 服务采用WSDL,XSD,WS-Policy和WS-MetaExchange进行描述 Security, Transactions, Reliable messaging MTOM 可以选择不同的传输机制如TCP,HTTP,SMTP等传输机制 可以自由的扩展,提供更多的传输机制支持 提供多种扩展技术支持,对服务开发透明 Scale up: 提供更好的服务器资源,Scale down: 切换对其它服务的使用,Scale out: Farms技术和负载均很技 术, Scale in: 采用更高效的通信技术(如本地优化)
Channel
• Channel为服务之间消息通信的通道 • Channel按照MEP可换分为simplex, duplex, request/response几种类型
Channel Stack
• 多种类型的Channel组和成一个管道,从而 组合了多个Channel的能力 • Channel Stack的组合受MEP的约束,利润 duplex就不能含有reliable session channel
更丰富的通信模式 广泛的互操作能力
• • •
提供企业应用需要的能力
– – – – – –
Transport, Protocol, and Format Neutrality Scale Invariance
体系架构
Application
Contracts
Service Runtime
Messaging
•
服务之间通过schema和contract关联,而非class和type
– Services interact solely on schemas for data and contracts for behaviors – Services do not combine data and behavior – Contracts and schemas remain stable over time
• One-way (simplex) • 异步two-way (duplex或者叫 solicit/response) • 同步two-way (request/response) • Notification • WSDL1.1对Notification和solicit/response 没有很好的描述
• Data Contract:数据结构信息,相当于OO中的 数据类型(VO) • Message Contract:定义了服务操作之间互相传递 的消息格式,控制了服务之间传递的消息的格式, 如Header,Body
Service剖析:Binding
• Binding描述了服务如何与外部通信 • 它指定了transport,encoding format, reliability requirements 和 security requirements, session requirements, transaction requirements信息 • 一个Service Contract必须至少有一个 Binding • 服务运行环境根据Binding信息创建 Channel Stack
Implementding
Service Contract
Implementation
Service Description
WSDL
WS-Policy
Service剖析:Contracts
• Service Contract
– – – – 有一个名称 由一个或多个Service operations构成 一个服务可以有多个Service Contract Service Contract相当于OO中的接口,Service operation相当于OO中的接口方法
Service vs WebService
• 共同点
– 都利用SOAP,XML,XSD,WSDL等标准协议 – 都具有自治、平台实现无关等特性
• 差异
– Service是WebService在SOA领域的后继标准 – WebService只提供了基于Http的传输通道和 request/response的消息交互模式,而Service是传输 中立,协议中立和格式中立的,能够提供多种消息交 互模式 – Service比WebService更成熟,更能够满足企业需要, 能够提共企业运算的安全、事务、可靠性以及性能满 足
– Transport:Channel用来通信的方法,如HTTP, TCP, SMTP, Queue – Encodings: 包括text, MTOM等编码方式编码消息在连接上传递 – Security:包括Transport的安全,如HTTPS,TCPS和消息安全, 例如SOAP Message Security – Reliable Session: 提供了两个关键能力,reliable message和 session, reliable message提供了消息的可靠传递和消息顺序等特 性,session保持了客户一系列交互的状态,它是建立在message 级别的,并不要求底层的通道是可靠或者支持session – MEP: 采用什么样的MEP决定于Channel是如何构建的,三个重要 的MEP为simplex, duplex, request/response – Interoperability: WS-Basic, WS-*
Reliable TCP Binary Request Security Sessions Transport Message Response Channel Channel Channel Encoder Channel
Channel Stack
• 可以组合形成Channel Stack的一些关键特征
Service剖析: Endpoint
• Endpoint描述了Service在何处的问题 • Endpoint用一个Address来关联Service Contract和Binding (ABC) • 服务的Endpoint通过Address告诉外界, Address的格式受多种因素影响,其中就包 括采用的transport
• Endpoint:Service的Access point
Service剖析(Int)
Address Endpoint
Service
Binding Binding Binding Service Contract