首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

servicemix使用小记

2012-10-19 
servicemix应用小记?前一段时间,研究了一下Apache的ServiceMix(3.3.2)的应用,作为一个ESB(基于SOA和EDA)应

servicemix应用小记

?

前一段时间,研究了一下Apache的ServiceMix(3.3.2)的应用,作为一个ESB(基于SOA和EDA)应用,牵涉的内容和知识很多,在整个建立的过程中,感觉有几个概念比较重要:

一、JBI(Java Business Integration)是什么意思。

二、ServiceMix中的BC和SE概念。

三、Provider和Consumer的理解。

2010.07.28

这两天一直在研究利用cxf-bc进行服务代理的实验,今天终于做通了,具体的步骤如下:

1、在ServiceMix外部发布一个webservice,这里我利用cxf,发布了一个HelloWorld的服务,在HelloWorld.wsdl文件中的targetNamespace=”http://spring.demo/“、service name “HelloWorldImplService”、port type “HelloWorld”、port binding name “HelloWorldImplPort”在后面的配置中,将会用到。

?<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="HelloWorldImplService" targetNamespace="http://spring.demo/" xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://spring.demo/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
? <wsdl:types>
<xs:schema elementFormDefault="unqualified" targetNamespace="http://spring.demo/" version="1.0" xmlns:tns="http://spring.demo/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sayHi" type="tns:sayHi"/>
<xs:element name="sayHiResponse" type="tns:sayHiResponse"/>
<xs:complexType name="sayHi">
??? <xs:sequence>
????? <xs:element minOccurs="0" name="arg0" type="xs:string"/>
??? </xs:sequence>
? </xs:complexType>
<xs:complexType name="sayHiResponse">
??? <xs:sequence>
????? <xs:element minOccurs="0" name="return" type="xs:string"/>
??? </xs:sequence>
? </xs:complexType>
</xs:schema>
? </wsdl:types>
? <wsdl:message name="sayHiResponse">
??? <wsdl:part element="tns:sayHiResponse" name="parameters">
??? </wsdl:part>
? </wsdl:message>
? <wsdl:message name="sayHi">
??? <wsdl:part element="tns:sayHi" name="parameters">
??? </wsdl:part>
? </wsdl:message>
? <wsdl:portType name="HelloWorld">
??? <wsdl:operation name="sayHi">
????? <wsdl:input message="tns:sayHi" name="sayHi">
??? </wsdl:input>
????? <wsdl:output message="tns:sayHiResponse" name="sayHiResponse">
??? </wsdl:output>
??? </wsdl:operation>
? </wsdl:portType>
? <wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:HelloWorld">
??? <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
??? <wsdl:operation name="sayHi">
????? <soap:operation soapAction="" style="document"/>
????? <wsdl:input name="sayHi">
??????? <soap:body use="literal"/>
????? </wsdl:input>
????? <wsdl:output name="sayHiResponse">
??????? <soap:body use="literal"/>
????? </wsdl:output>
??? </wsdl:operation>
? </wsdl:binding>
? <wsdl:service name="HelloWorldImplService">
??? <wsdl:port binding="tns:HelloWorldImplServiceSoapBinding" name="HelloWorldImplPort">
????? <soap:address location="http://localhost:8080/cxf_spring_web/HelloWorld"/>
??? </wsdl:port>
? </wsdl:service>
</wsdl:definitions>

2、cxf_bc中的配置

??? 在cxf_bc中需要配置两个endpoint,一个为provider,利用它来连接外部的service:

???? <cxfbc:provider wsdl="classpath:HelloWorld.wsdl"
????? ?????locationURI="http://localhost:8080/cxf_spring_web/HelloWorld"
?????????????????????? service="hello:HelloWorldImplService"
????????????????????? endpoint="HelloWorldImplPortProxy"
????????????????????? interfaceName="hello:HelloWorld"
????????????????????/ >

??? 需要注意的是service的名字为hello:HelloWorldImplService要和wsdl中定义的一致,hello为文件头中定义的namespace=“http://spring.demo/"。

利用一个consumer的endpoint连接这个provider,从而形成一个webService发布的桥:

????? <cxfbc:consumer wsdl="classpath:HelloWorld.wsdl"
????????????????????? locationURI="http://localhost:19000/CalculatorService/SoapPort"
????????????????????? service="hello:HelloWorldImplService"
????????????????????? endpoint="HelloWorldImplPort"
????????????????????? targetEndpoint="HelloWorldImplPortProxy"
????????????????????? targetService="hello:HelloWorldImplService"
????????????????????? targetInterface="hello:HelloWorld"/>

这里需要注意的一是locationURI要和原始的service发布路径不一致,否则就会产生混淆;二是service和provider中定义的一致;三是endpoint名字是wsdl中定义的port binding name。

经过测试,以上配置就实现了在ServiceMix中发布WebService的功能。

热点排行