Oracle 服务总线介绍-36大数据
我们正设计一套针对电信供应商的新系统,并且锁定Oracle服务总线(OSB)作为企业服务总线。对我来说这款工具的最好的加分项就是强大的工具支持。Oracle已经将其所有企业集成软件栈集成为一个整体,将其捆绑为Oracle SOA套件。本文将把重点放在Oracle SOA套件11g的一部分,Oracle OSB 11g上。Oracle SOA Suite 12c有很大的变化。然而ORacle 12C套件中我喜欢的新功能是开发人员可以在一个IDE(集成开发环境)里,用JDeveloper开发BPEL(业务流程执行语言)以及开发OSB代码。
关于 OSB 需要注意的几点如下:
- 代理服务: 正如其名字所表明的,代理服务是为外部客户提供的服务,扮演了内部服务外观的角色。通过代理服务,你可以更好地控制内部服务中的变化,因为如果你的内部服务发生变化,代理服务可以执行需要的转换。
- 业务服务: 在 OSB中, 业务服务表示内部应用服务。它可以是 WebService, JMS 队列/主题, REST 服务, FTP 服务以及其他服务. 业务服务将会包含调用实际服务的功能。
所以本文中关注的场景如下:
- 我们有一个内部的服务,回报用户信息,如果用户通过在MSISDN或SIM卡号码,根据输入,数据将被取回来。
- 通过使用代理服务,这项服务必须以更有意义的方式开放给外部方。
演示项目可以在 这里 下载。
首先创建企业服务,作为内部服务的表面。 在OSB项目中,创建四个文件夹:
- 代理
- 业务
- 转换
- WSDL
然后需要复制本例中的 内部服务WSDL和代理服务 WSDL文件到 “WSDL” 文件夹。
配置企业服务
右击 “business” 文件夹,并选择 New->Business服务。当企业服务创建好,“General” 选项卡弹出。在此,我们需要做如下操作:
- 选择 “WSDL Web Service” ,然后点击浏览器。 然后选择“Browse,” 选择 the WSDL file,然后有两个选项。选择the one ending with “(port)
- 然后到“Transport” 选项卡,并且将 URI改为:: http://localhost:8088/mockInstalledBaseSubscriberClassificationQueryWSServiceSoapBinding. 这是因为我们将使用SOAPUI 模拟服务特征来测试, URI 代表由WSDL表示的SOAPUI的模拟服务端点。
- 本例中的SOAPUI项目可以在 此 下载。
这就是我们配置业务服务所需要做的所有操作。然后进入我们的代理服务,这是所有的动作发生的地方。
配置代理服务
- 右键点击创建的 “proxy” 目录, 选择 New->Proxy Service 并提供一个有效的名称.
- 在 “General” 标签页, 选择 “WSDL Web Service” 并点击浏览.
- 现在代理服务中,你需要选择我们创建的代理 WSDL 文件,该文件会提供给外部客户端。
- 进入 “Message Flow” 标签页. 在该标签页, 首先由右侧的 “Design Palette” 中拖拽一个 “Route” 元素.
- 然后,拖拽一个 “Routing” 元素到 “Route” 元素中.
- 点击 “Routing” 元素, 并在底部面板中, 进入 “Properties” 标签页, 在该标签页中你将提供代理服务将会访问的业务服务与操作名称.
结果如下:
- 然后拖拽一个 “Replace” 到 “Request Action” 组件.
- 在 “Properties” 标签页为 “Replace” 动作提供信息之前, 我们需要创建 XQuery 转换文件, 该文件会将代理服务映射为业务服务请求,然后将业务服务响应映射回代理服务响应.
- 右键点击 “transformation” 目录并选择 New->XQuery Transformation. 输入有效名称. 对请求与响应转换文件也需要进行同样的操作。
-
所用的请求转换文件如下:
(:: pragma bea:global-element-parameter parameter="$fetchSubscriber1" element="ns2:FetchSubscriber" location="../wsdl/SubscriberProxyService.wsdl" ::) (:: pragma bea:local-element-return type="ns1:InstalledBaseSubscriberClassificationQuery/ns0:InstalledBaseSubscriberClassificationQuery" location="../wsdl/subscriber_classfication.wsdl" ::) declare namespace ns2 = "http://www.example.org/SubscriberProxyService/"; declare namespace ns1 = "http://www.openuri.org/"; declare namespace ns0 = "http://mtnsa.co.za/si/IB/IBSubscriberClassificationQuery"; declare namespace xf = "http://tempuri.org/OSB%20training%201/transformation/subscriberrequest/"; declare function xf:subscriberrequest($fetchSubscriber1 as element(ns2:FetchSubscriber)) as element() { <ns1:InstalledBaseSubscriberClassificationQuery> <ns0:InstalledBaseSubscriberClassificationQuery> <ns0:Request> { if (data($fetchSubscriber1/EquipmentType) = "MSISDN") then <ns0:MSISDN> { (data($fetchSubscriber1/EquipmentValue))}</ns0:MSISDN> else <ns0:SIMCard> { data($fetchSubscriber1/EquipmentValue)}</ns0:SIMCard> } </ns0:Request> </ns0:InstalledBaseSubscriberClassificationQuery> </ns1:InstalledBaseSubscriberClassificationQuery> }; declare variable $fetchSubscriber1 as element(ns2:FetchSubscriber) external; xf:subscriberrequest($fetchSubscriber1)
在这里正如你所看到的,我们检测设备类型是否等 “MSISDN” ,然后在业务服务中设置相应的元素。
- 所用的响应转换文件如下:
(:: pragma bea:global-element-parameter parameter="$installedBaseSubscriberClassificationQueryResponse1" element="ns1:InstalledBaseSubscriberClassificationQueryResponse" location="../wsdl/subscriber_classfication.wsdl" ::) (:: pragma bea:global-element-return element="ns2:FetchSubscriberResponse" location="../wsdl/SubscriberProxyService.wsdl" ::) declare namespace ns2 = "http://www.example.org/SubscriberProxyService/"; declare namespace ns1 = "http://www.openuri.org/"; declare namespace ns0 = "http://mtnsa.co.za/si/IB/IBSubscriberClassificationQuery"; declare namespace xf = "http://tempuri.org/OSB%20training%201/transformation/subscriberresponse/"; declare function xf:subscriberresponse($installedBaseSubscriberClassificationQueryResponse1 as element(ns1:InstalledBaseSubscriberClassificationQueryResponse)) as element(ns2:FetchSubscriberResponse) { <ns2:FetchSubscriberResponse> <TradeCustomerCode>{ data($installedBaseSubscriberClassificationQueryResponse1/ns0:InstalledBaseSubscriberClassificationQuery/ns0:Response/ns0:Subscriber/@ServiceProviderCode) }</TradeCustomerCode> <PackageCode>{ data($installedBaseSubscriberClassificationQueryResponse1/ns0:InstalledBaseSubscriberClassificationQuery/ns0:Response/ns0:Subscriber/ns0:Package/@ProductCode) }</PackageCode> <PaymentOption>{ data($installedBaseSubscriberClassificationQueryResponse1/ns0:InstalledBaseSubscriberClassificationQuery/ns0:Response/ns0:Subscriber/@PaymentOption) }</PaymentOption> </ns2:FetchSubscriberResponse> }; declare variable $installedBaseSubscriberClassificationQueryResponse1 as element(ns1:InstalledBaseSubscriberClassificationQueryResponse) external; xf:subscriberresponse($installedBaseSubscriberClassificationQueryResponse1)
这是一个简单的转换,在其中我们将响应元素映射到所需的代理响应元素。
现在我们回到代理服务,点击 “Replace” 动作,进入 “Properties” 标签页.
- 在 “In Variable” 中插入值 “body”.
- 点击 “Expression” 链接. 进入 “XQuery Resources” 标签页, 点击 “Browse” 并选择请求转换文件.
- 在右侧的 “Variable Structures” 组件中,展开 “body” 元素,然后选择请求元素并将其拖拽到 “Binding” 文本框中,如下所示:text box as follows:
- 然后选择 “OK” 从而会将你带回 “Properties” 标签.
- 选择以 “Replace node contents” 单选按钮. 结果如下所示:
- 现在让我们拖拽一个 “Replace” 动作到 “Response Action” 组件.
- 与之前相同,选择响应转换“$body/ins:InstalledBaseSubscriberClassificationQueryResponse”.
- 你会遇到一个错误,表明 “ins” 命名空间没有被识别.
- 为解决该错误,在同一个 “Properties” 标签内, 选择标签 “Namespaces” 并点击添加. 输入 “ins” 作为前缀, “http://www.openuri.org/” 作为 URI.
就是这样,现在我们就可以测试该功能。 在你动手之前,请记住首先启动在SOAP UI上创建的模拟服务。
现在,我们登录服务总线控制台,转到代理服务并启动测试控制台。 下面是过运行示例得到的结果:
你以在“ Invocation Trace”部分中的同一个屏幕上进一步了解发生的详细过程。 OSB进行的请求和响应转换可以在下面的图片中看到:
到这里我们将结束对Oracle Service Bus的介绍。 如果你有任何疑问,请随时留言,我将尽快回复。 另外,如果有任何改善的地方,请留下你的反馈,我们将一如既往的非常感谢。
End.
转载请注明来自36大数据(36dsj.com): 36大数据 » Oracle 服务总线介绍